Skip to content

Instantly share code, notes, and snippets.

@pmjones
Last active December 26, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmjones/7129733 to your computer and use it in GitHub Desktop.
Save pmjones/7129733 to your computer and use it in GitHub Desktop.
Simplified rewrite of PSR-4, with a nod to Beau Simensen.

Autoloading Standard

The following describes the mandatory requirements that must be adhered to for autoloader interoperability.

Mandatory

  • The term "class" refers to classes, interfaces, traits, and other similar structures.

  • A fully qualified class name MUST have the following form:

      \<NamespaceName>(\<SubNamespaceName>)*\<ClassName>
    
    • The fully qualified class name MUST have a top-level namespace name.

    • The fully qualified class name MAY have one or more sub-namespace names.

    • The fully qualified class name MUST have a terminating class name.

  • When loading a file that defines a fully qualified class name from the file system ...

    • a contiguous series of one or more leading namespace names without the leading namespace separator (a "qualified name") in the fully qualified class name corresponds to a base directory;

    • the contiguous sub-namespace names after the "qualified name" correspond to a subdirectory within the base directory, where the namespace separators correspond to directory separators; and,

    • the terminating class name corresponds to a file name ending in .php.

  • Alphabetic characters in in the fully qualified class name may be of any combination of lower case and upper case. Underscores have no special meaning in any portion of the fully qualified class name.

Examples

Fully Qualified Class Name      Qualified Name      Base Directory              File Path
----------------------------    ----------------    ---------------------       ----------------------------------------
\Acme\Log\Writer\File_Writer    Acme                ./acme/lib/                 ./acme/lib/Log/Writer/File_Writer.php
\Aura\Web\Response\Status       Aura\Web            /path/to/aura-web/src/      /path/to/aura-web/src/Response/Status.php
\Symfony\Core\Request           Symfony\Core        ./vendor/Symfony/Core/      ./vendor/Symfony/Core/Request.php`
\Zend\Acl                       Zend                /usr/includes/Zend/         /usr/includes/Zend/Acl.php
@AmyStephen
Copy link

Better still. I appreciate how you have adapted to the "will of the people" - what a long journey.

Like the format of the examples at the end - BTW, I'm not against examples, just know life is easier when things can be changed. Whatever works is great.

Looking forward to using it (officially). =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment