.. include:: /Includes.rst.txt .. index:: ! Namespaces .. _namespaces: ========== Namespaces ========== TYPO3 uses PHP namespaces for all classes in the Core. The general structure of namespaces is the following: .. code-block:: none :caption: General namespace schema \{VendorName}\{PackageName}\({CategoryName}\)*{ClassName} For the Core, the *vendor name* is :php:`TYPO3\CMS` and the *package name* corresponds to a system extension. All classes must be located inside the :file:`Classes` folder at the root of the (system) extension. The *category name* may contain several segments that correspond to the path inside the :file:`Classes` folder. Finally the *class name* is the same as the corresponding file name, without the :file:`.php` extension. "UpperCamelCase" is used for all segments. .. index:: pair: Namespaces; Core .. _namespaces-example: Core example ------------ The good old :php:`t3lib_div` class has been renamed to: :php:`\TYPO3\CMS\Core\Utility\GeneralUtility` This means that the class is now found in the `core` system extension, in folder :file:`Classes/Utility`, in a file named :file:`GeneralUtility.php`. .. index:: pair: Namespaces; Extensions .. _namespaces-extensions: Usage in extensions ------------------- Extension developers are free to use their own vendor name. *Important:* It may consist of *one* segment only. Vendor names must start with an uppercase character and are usually written in UpperCamelCase style. In order to avoid problems with different filesystems, only the characters a-z, A-Z, 0-9 and the dash sign "-" are allowed for package names – don't use special characters: .. code-block:: php :caption: Examples for vendor names // correct vendor name for 'web company': \WebCompany // wrong vendor name for 'web company': \Web\Company .. attention:: The vendor name `TYPO3\CMS` is reserved and may not be used by extensions! The package name corresponds to the extension key. Underscores in the extension key are removed in the namespace and replaced by upper camel-case. So extension key: .. code-block:: none :caption: Do not do this weird-name_examples would become: .. code-block:: none :caption: Do not do this Weird-nameExamples .. TODO: Something is very wrong with this example... in the namespace. As mentioned above, all classes **must** be located in the :file:`Classes` folder inside your extension. All sub-folders translate to a segment of the category name and the class name is the file name without the :file:`.php` extension. Looking at the "examples" extension, file :file:`examples/Classes/Controller/DefaultController.php` corresponds to the class with :php:`\Documentation\Examples\Controller\DefaultController` as fully qualified name. Inside the class, the namespace is declared as: .. code-block:: php :caption: EXT:examples/Classes/Controller/DefaultController.php `_ and in particular the `Namespaces FAQ `_.