PSR-2. When to capitalize directories?

As I understood according to the PSR-2 standard, we have to use the names of the directories containing the classes. But how do you do this if the directory also contains some other files, such as styles and scripts?

Let's say I have a plugin directory, each plugin can contain templates and other things:

plugins
  PluginName // lowercase?
    PluginName.php // Contains base class "PluginName"
    templates
      home.tpl
    css
      css.css
    js
      js.js
  PluginName2
    ....

      

Is this structure correct?

+3


source to share


2 answers


You can name your directories whatever you want.

However, if you intend to automatically load your PHP classes using PSR-0 or PSR-4, the directory names affected by the corresponding part of the class name must match exactly.

PSR-2 does not make any assumptions or give rules as to when a class name or namespace should exist.

PSR-1 states in Chapter 3 : "Class names must be declared in StudlyCaps". However, this only affects the filename of the file containing such a class. If you're using PSR-4 autoloading, you can still avoid using any part of the namespace altogether in the path if you define the entire map Name\Space -> directory/for/that/namespace

for each directory containing code.



PSR-1 has no rules regarding the formatting of the namespace, so you can also avoid using uppercase letters there, and because of this, avoid using uppercase letters in the directory path.

Note that both PSR-0 and PSR-4 autoload are case sensitive when it comes to mapping a namespace / class to a file path and file. So in the end you will end up with a case-sensitive filesystem layout.

Also note that most namespaces also use StudlyCaps, and I find the use of lowercase letters to be unusual.

+4


source


There is no clearly defined way of how a structure should be in PHP.

I don't even think that directory names should be capitalized.



However, can the plugin or any dependencies be handled by any package manager ( Composer )?

From what I can tell, your structure looks great.

+1


source







All Articles