Since an increasing number of PHP projects are going to use namespaces, it gets more important to agree on a scheme which avoids naming conflicts. The current best practice is to use the "vendor name" as the top level namespace โ but who says that your vendor name is unique?
The approach of FLOW3 was โ until now โ to force all its packages to use a schema like "F3\PackageKey\Foo\Bar\..." for the naming of their classes. In order to keep the package key unique, we force suggest that developers register a package at forge.typo3.org. This essentially allows us to guarantee that each fully qualified class name is unique world wide.
This approach would work fine within the TYPO3 / FLOW3 universe, but what we really want is to foster code reuse and collaboration among other PHP projects. The PSR0 standard initiative was certainly a good step into this direction and the suggestion by Fabien (ie. essentially to put not any real restrictions on the namespace as long as the top level part is the vendor name) is the way to go. Following the current best practice I'd like FLOW3 to support class names like \[Vendor]\Foo\Bar\Baz. In case of Fluid that would be a namespace like \FLOW3\Package\Fluid (because Fluid is a project of the FLOW3 team). The actual Doctrine2 code would reside somewhere in the \Doctrine\... namespace (Doctrine project is the vendor) whilst a possible Doctrine2 wrapper for FLOW3 would be put into a namespace like \FLOW3\Package\Doctrine2.
The big question now is: how can we achieve that the vendor name is almost certainly unique? For its bundles, Symfony2 currently establishes the best practice to use the Github user name as its vendor name. But in the TYPO3 / FLOW3 project we don't use Github as we have our own servers at git.typo3.org. If I would start using "RL" as a vendor name, it is not unlikely that someone will do the same. Even with "RobertLemke" I wouldn't be on the safe side.
Do we need a schema or registry for vendor names?
Bertrand Dunogier | 24.02.2011
I know for sure eZ Systems will most likely use eZ, and that the brand is strong enough not to overlap with others. But since there is no centralized management whatsoever over PHP namespaces, conflicts will happen sooner or later...
Kevin | 24.02.2011
The \Org\Typo3\FLOW3 format is similar to what I do already, though I follow the Java naming convention and do the namespaces with lower case. For example
org\eschrade\test\SomeClass
Adrian Foeder | 24.02.2011
...OK, I read the comments in the wrong order ;-)
Karsten had a nice Idea; just extended with the rule that CamelCase *must only* be used instead of the dots, so
foeder.de will result in DeFoeder, but robertlemke.de will result in DeRobertlemke.
more:
usa.acme.org and eu.acme.org would be OrgAcmeUsa and OrgAcmeEu.
....but what about dashes? Are they allowed in the namespaces?
Adrian Foeder | 24.02.2011
I think the Internet DNS system with its hierarchy could be a good inspiration; maybe, like Bastian wrote, with a kind of reversed ("from big entity to small") statements. Because each company/developer/vendor would have an own domain name, it could be done pretty simple... And the "registration" is "automatically" done by a very large authority, the IATA (?)...
Robert | 24.02.2011
Maybe it's good enough if you own one of the domains [vendor].com, [vendor].org, [vendor].net? Then I'd go for \RobertLemke\Package\Nothing with confidence.
Bastian Waidelich | 24.02.2011
It's quite common to use domains for namespaces like org.typo3.[project]
For FLOW3 this would mean
\Org\Typo3\FLOW3\Package
..not so sure about that one ;)
JohnChristopher | 27.02.2017
Just curious, has anything happened on this front ?