Commit Graph

1895 Commits

Author SHA1 Message Date
Ryan Weaver
17f9162b89 [Standards] Changing many instances of "boolean" to "Boolean". 2011-01-21 09:53:24 +01:00
Fabien Potencier
e6f1248151 [HttpKernel] added back Bundle::getName() as it is quite useful 2011-01-21 09:45:37 +01:00
Fabien Potencier
6d1e91a1fa refactored bundle management
Before I explain the changes, let's talk about the current state.

Before this patch, the registerBundleDirs() method returned an ordered (for
resource overloading) list of namespace prefixes and the path to their
location. Here are some problems with this approach:

 * The paths set by this method and the paths configured for the autoloader
   can be disconnected (leading to unexpected behaviors);

 * A bundle outside these paths worked, but unexpected behavior can occur;

 * Choosing a bundle namespace was limited to the registered namespace
   prefixes, and their number should stay low enough (for performance reasons)
   -- moreover the current Bundle\ and Application\ top namespaces does not
   respect the standard rules for namespaces (first segment should be the
   vendor name);

 * Developers must understand the concept of "namespace prefixes" to
   understand the overloading mechanism, which is one more thing to learn,
   which is Symfony specific;

 * Each time you want to get a resource that can be overloaded (a template for
   instance), Symfony would have tried all namespace prefixes one after the
   other until if finds a matching file. But that can be computed in advance
   to reduce the overhead.

Another topic which was not really well addressed is how you can reference a
file/resource from a bundle (and take into account the possibility of
overloading). For instance, in the routing, you can import a file from a
bundle like this:

  <import resource="FrameworkBundle/Resources/config/internal.xml" />

Again, this works only because we have a limited number of possible namespace
prefixes.

This patch addresses these problems and some more.

First, the registerBundleDirs() method has been removed. It means that you are
now free to use any namespace for your bundles. No need to have specific
prefixes anymore. You are also free to store them anywhere, in as many
directories as you want. You just need to be sure that they are autoloaded
correctly.

The bundle "name" is now always the short name of the bundle class (like
FrameworkBundle or SensioCasBundle). As the best practice is to prefix the
bundle name with the vendor name, it's up to the vendor to ensure that each
bundle name is unique. I insist that a bundle name must be unique. This was
the opposite before as two bundles with the same name was how Symfony2 found
inheritance.

A new getParent() method has been added to BundleInterface. It returns the
bundle name that the bundle overrides (this is optional of course). That way,
there is no ordering problem anymore as the inheritance tree is explicitely
defined by the bundle themselves.

So, with this system, we can easily have an inheritance tree like the
following:

FooBundle < MyFooBundle < MyCustomFooBundle

MyCustomFooBundle returns MyFooBundle for the getParent() method, and
MyFooBundle returns FooBundle.

If two bundles override the same bundle, an exception is thrown.

Based on the bundle name, you can now reference any resource with this
notation:

    @FooBundle/Resources/config/routing.xml
    @FooBundle/Controller/FooController.php

This notation is the input of the Kernel::locateResource() method, which
returns the location of the file (and of course it takes into account
overloading).

So, in the routing, you can now use the following:

    <import resource="@FrameworkBundle/Resources/config/internal.xml" />

The template loading mechanism also use this method under the hood.

As a bonus, all the code that converts from internal notations to file names
(controller names: ControllerNameParser, template names: TemplateNameParser,
resource paths, ...) is now contained in several well-defined classes. The
same goes for the code that look for templates (TemplateLocator), routing
files (FileLocator), ...

As a side note, it is really easy to also support multiple-inheritance for a
bundle (for instance if a bundle returns an array of bundle names it extends).
However, this is not implemented in this patch as I'm not sure we want to
support that.

How to upgrade:

 * Each bundle must now implement two new mandatory methods: getPath() and
   getNamespace(), and optionally the getParent() method if the bundle extends
   another one. Here is a common implementation for these methods:

    /**
     * {@inheritdoc}
     */
    public function getParent()
    {
        return 'MyFrameworkBundle';
    }

    /**
     * {@inheritdoc}
     */
    public function getNamespace()
    {
        return __NAMESPACE__;
    }

    /**
     * {@inheritdoc}
     */
    public function getPath()
    {
        return strtr(__DIR__, '\\', '/');
    }

 * The registerBundleDirs() can be removed from your Kernel class;

 * If your code relies on getBundleDirs() or the kernel.bundle_dirs parameter,
   it should be upgraded to use the new interface (see Doctrine commands for
   many example of such a change);

 * When referencing a bundle, you must now always use its name (no more \ or /
   in bundle names) -- this transition was already done for most things
   before, and now applies to the routing as well;

 * Imports in routing files must be changed:
    Before: <import resource="Sensio/CasBundle/Resources/config/internal.xml" />
    After:  <import resource="@SensioCasBundle/Resources/config/internal.xml" />
2011-01-20 18:42:47 +01:00
Jordi Boggiano
252918beb2 [TwigBundle] Fixed RenderTokenParser when with isn't used and options are provided 2011-01-20 16:47:54 +01:00
Ryan Weaver
ea2cb49696 [TwigBundle] Improving the PHPDoc on the FormExtension inside the TwigBundle. 2011-01-20 16:37:36 +01:00
Ryan Weaver
cf1512dce8 [Form] Fixing the object versus normalized data PHPDoc on Field, which I believe was backwards. 2011-01-20 16:37:33 +01:00
Ryan Weaver
d41b4ec109 [Form] adding PHPDoc and some small PHPDoc changes. 2011-01-20 16:37:31 +01:00
Ryan Weaver
82283db789 [Form] Making the constructor inherit docs. 2011-01-20 16:37:27 +01:00
Fabien Potencier
67f13fee9e [HttpKernel] made a small tweak 2011-01-20 11:38:17 +01:00
Fabien Potencier
24ff22af07 [HttpFoundation] added a directory fallback for when the class is not found in registered namespaces and class prefixes 2011-01-20 10:20:14 +01:00
Jeremy Mikola
e414e06327 [HttpKernel] Fix AccessDecisionManagerInterface::decide() invocation in SwitchUserListener 2011-01-20 07:14:46 +01:00
Bulat Shakirzyanov
04fd4194b5 [DoctrineMongoDBBundle] fixed typo, updated extension test to reflection validation addon 2011-01-20 07:13:37 +01:00
Victor Berchet
b75840c6fc DI Extension: use the base class from the HttpKernel Component 2011-01-19 22:08:41 +01:00
Bulat Shakirzyanov
6d52645861 [DoctrineMongoDBBundle] registered new validation namespace for annotations 2011-01-19 21:50:51 +01:00
Bulat Shakirzyanov
1cbd0caa89 [DoctrineMongoDBBundle] added unique constraint, validator and test, registered validator in DIC 2011-01-19 21:50:47 +01:00
Johannes M. Schmitt
84fa4b50db adds setArgument to Definition 2011-01-19 21:48:56 +01:00
Bernhard Schussek
bdd2c91abd [Form] Fixed failing test 2011-01-19 17:51:07 +01:00
Bernhard Schussek
d143eaad72 [Validator] Fixed XML schema 2011-01-19 16:50:45 +01:00
Jordi Boggiano
8800452b1c [Form] Fixed some documentation 2011-01-19 16:37:02 +01:00
Jordi Boggiano
d928632583 [Form] Made RepeatedField sub-field names configurable 2011-01-19 16:36:57 +01:00
Bernhard Schussek
d327a90ff2 [Validator] Added namespace prefix support for XML and YAML loaders 2011-01-19 16:25:50 +01:00
Bernhard Schussek
2d7c47e488 [Validator] Each object is now only validated once for a given group 2011-01-19 16:25:50 +01:00
Bernhard Schussek
d52ae8e103 [Validator] Removed unused class GroupChain 2011-01-19 16:25:50 +01:00
Bernhard Schussek
eed3c9a48c [Validator] Added abstract method Constraint::targets() to define whether constraints can be put onto properties, classes or both 2011-01-19 16:25:50 +01:00
Bernhard Schussek
6ad22fd702 [Validator] Added ValidatorFactory for programmatically creating validators 2011-01-19 16:25:50 +01:00
Bernhard Schussek
8f8f53d631 [Form][FrameworkBundle] Implemented FormFactory and added it to the DI container 2011-01-19 16:25:50 +01:00
Bernhard Schussek
fea37a3e95 [Validator] Added tests for AssertTypeValidator 2011-01-19 16:25:50 +01:00
Jordi Boggiano
a305f9b25a [Form] Fixed indenting 2011-01-19 16:25:50 +01:00
Jordi Boggiano
de3f240ea4 [Form] Added required attribute on input field templates 2011-01-19 16:25:49 +01:00
Jordi Boggiano
59957727e3 [Form] Allow setting the date_format option via DateTimeField 2011-01-19 16:25:49 +01:00
Jordi Boggiano
ae40a5da53 [Form] Use HTML5 number and url input types for number and url fields 2011-01-19 16:25:49 +01:00
Christophe Coevoet
f5f7021669 Fixed the conenction alias used by acl 2011-01-19 11:41:14 +01:00
Fabien Potencier
12f3497281 simplified Doctrine unit tests 2011-01-19 08:22:13 +01:00
Fabien Potencier
23a7d3657a fixed Doctrine commands help message 2011-01-19 08:20:04 +01:00
Victor Berchet
3e8f8ea6af [ProfilerStorage] Make write() returns a status (Boolean) 2011-01-19 07:38:46 +01:00
Victor Berchet
5030255021 [SQLiteProfilerStorage] Add a unit test 2011-01-19 07:36:27 +01:00
Victor Berchet
db42ab21f0 [SQLiteProfilerStorage] Escape '\' in find() 2011-01-19 07:35:20 +01:00
Victor Berchet
2740e105e1 [Profiler] Fix a typo 2011-01-19 07:33:36 +01:00
Lukas Kahwe Smith
d030882c20 ignore firewalls that are set to false (f.e. http-basic: false), removed two unused variables 2011-01-19 07:33:04 +01:00
Bulat Shakirzyanov
267a7e6956 [HttpKernel] fixed Cache, to respect the variable and trigger error handling 2011-01-19 07:31:27 +01:00
Kris Wallsmith
8d6da86016 [DependencyInjection] moved loading stack from static to object scope 2011-01-19 07:28:42 +01:00
Jordi Boggiano
afbf6bfdc7 Added missing HTTP status code 418 2011-01-19 07:21:06 +01:00
Lukas Kahwe Smith
3d77302609 if( -> if ( 2011-01-19 07:20:27 +01:00
Lukas Kahwe Smith
ddea635a51 fixes else -> } else 2011-01-19 07:20:23 +01:00
Fabien Potencier
40a70cd6f4 simplified TemplateNameParser::parse() return value 2011-01-18 19:13:37 +01:00
Fabien Potencier
9f4863e4dc [DoctrineBundle] cleaned up doctrine:generate:entity 2011-01-18 18:57:00 +01:00
Fabien Potencier
b4acae5b73 removed defaults to TemplateNameParserInterface::parse() method as it was not used anywhere (everything is explicit now) 2011-01-18 18:51:29 +01:00
Dominique Bongiraud
64fb94c725 normalized license messages in PHP files 2011-01-18 08:07:46 +01:00
Sergey Linnik
22aba900d4 [TwigBundle] Normalize names of templates and enable cache found templates file names 2011-01-18 07:45:52 +01:00
Fabien Potencier
5b3e5e454b reverted a previous commit where translators were made optional 2011-01-17 22:58:55 +01:00