Hi all,

Now that the developer is free to use any namespace for his bundles, it's time to talk about the naming conventions (the best practices) once again.

This RFC is about the bundle namespace name, not the bundle class name.

First things first, the namespace must adhere to the PSR-0 standard; and we should also keep the Bundle suffix for the last namespace segment.

One of the PSR-0 rules says that the first segment must be the vendor name. This rule was not possible some days ago as all bundles were stored under Bundle\ or Application\. It is now possible because we have removed this constraint and also because we have added a fallback mechanism to the Symfony2 autoloader. So, if the autoloader does not find a class, it can look for it under a fallback directory:

    $loader = new UniversalClassLoader();
    $loader->registerNamespaces(array(
        'Symfony' => __DIR__.'/src',
    ));
    $loader->registerNamespaceFallback(__DIR__.'/src');
    $loader->register();

With the above configuration, if you try to use the 'Sensio\Foo' class, the autoloader will look for a __DIR__.'/src/Sensio/Foo.php' class. This acts as a catch-all but if the class is not found, the autoloader gives up and let other autolaoders do their work.

So, we have several vendor types:

 * Symfony (a very special one);

* Companies working with Symfony and publishing bundles (Sensio, Liip, ...);

 * Open-Source software (Doctrine, Twig, ...).

And here are some existing examples:

 * Symfony vendor: Symfony\Bundle\FrameworkBundle

 * Sensio vendor: Sensio\Bundle\CasBundle

 * Liip vendor: Liip\ViewBundle\LiipViewBundle

Bascially, the first segment is always the vendor name, no surprise here. But after that, we have different possibilities for the categories:

 * no category at all (Liip case);
 * a Bundle category.

The 'Bundle' category better separates things and is probably a good idea if you have many things to store under your namespace.

And for big namespaces, it can be interesting to also add a Symfony
category in-between. Let's take another example. I think that the DoctrineBundle should be under the Doctrine vendor namespace (note that it is a matter of how we see things: Does Symfony provides support for Doctrine or is it the other way around.).

Anyway, here are all the sensible possibilities I can think of:

 * Doctrine\DoctrineBundle
 * Doctrine\Bundle\DoctrineBundle
 * Doctrine\Symfony\DoctrineBundle
 * Doctrine\Symfony\Bundle\DoctrineBundle

Which one makes more sense? As the bundles are suffixed by Bundle, I think that 'Doctrine\Symfony\DoctrineBundle' is the best one. But I also like the explicit Bundle category.

What do you think?

Fabien

--
Fabien Potencier
Sensio CEO - symfony lead developer
sensiolabs.com | symfony-project.org | fabien.potencier.org
Tél: +33 1 40 99 80 80

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to