PHP Standardization Fig Namespaces

0

I have a PHP application with my mvc framework and it follows the following template:

Namespace         Diretorio                              Desc
Nautilus\         root/Nautilus/src/Nautilus_Web/        Aplicação principal
Nautilus\Service  root/Nautilus/src/Nautilus_Service/    Serviços
Nautilus\Domain   root/Nautilus/src/Nautilus_Domain/     Modelos e repositórios

I am standardizing my project according to PHP-Fig and according to the documentation the namespace must correspond to the physical directory.

I wonder if standardization is being done the wrong way since Nautilus \ Service and Nautilus \ Domain should include the classes from the Nautilus namespace directory that would be:

root / Nautilus / src / Nautilus_Web /....

If my namespace calls Nautilus the physical directory should be:

root/Nautilus/src/Nautilus_Web/Nautilus does not? or rename the namespace to Nautilus\Web from the directory ... / src / Nautilus_Web would match, correct?

Thank you!

    
asked by anonymous 27.08.2014 / 02:19

1 answer

2

I think I'm seeing three questions so I'll answer them in the order that makes the most sense: Structure of directories, namespaces, and content.

As every framework or component / library, whether proprietary or 3rd-Party, is custom, regardless of PSR, from the root directory if you have a subdirectory usually called vendor and within it a directory for each resource:

|-\
| |-\Application
|   |-\Application\Portal
|      |-\Application\Portal\Models
|      |-\Application\Portal\Views
|      |-\Application\Portal\Controllers
|   |-\Application\Portal
|      |-\Application\Admin\Models
|      |-\Application\Admin\Views
|      |-\Application\Admin\Controllers
| |-\vendor
|   |-\vendor\Symfony
|   |-\vendor\Doctrine
|   |-\vendor\Nautilus

Framework namespaces or libraries / components are a little off the rule of getting started from the root directory mainly because of autoloaders which almost always take into account the include_path that should be modified at run time to include this vendor directory as you need it:

set_include_path(
    '.' . PATH_SEPARATOR . realpath( './vendor' )
);

Finally, the location of the content. Once you resolve both of the above problems, you resolve the latter as well because all autoloader should work from the root directory and vendor is already part of > include_path whenever you instantiate a new class or import a resource (with use ) as long as it has not yet been declared in the invocator scope (otherwise there is no autoloader intervention) you will always be "positioned" in the Application's path.

That is, imagine that Nautilus\Web\Domain needs some feature of Nautilus\Web\Service . Even though abos will be in completely separate directories, both will be under the wings of the same parent namespace, Nautilus

Ah! And by the way, with the exception of the include_path modification, forget the concept of relative paths. ;)

    
27.08.2014 / 02:41