You get a bonus - 1 coin for daily activity. Now you have 1 coin

psr-4 autoloader

Lecture



Autoloader

The keywords “MUST” (“MUST”), “MUST NOT” (“MUST NOT”), “REQUIRED”, “NEED” (“SHALL”), “NOT ALLOW” (“SHALL NOT”), "SHOULD" ("SHOULD"), "DO NOT SUBJECT" ("SHOULD NOT"), "RECOMMENDED" ("RECOMMENDED"), "CAN" ("MAY") and "OPTIONAL" ("OPTIONAL") in this document should regarded as described in RFC 2119.

1. Overview

This PSR describes the specification for autoloading classes based on file paths. It is completely interchangeable and can be used in addition to any other autoloader specification, including PSR-0. This PSR also describes where to place the files that will be loaded in accordance with the specification.

2. Specification

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

  2. The absolute class name has the following form:

    \<ИмяПространстваИмён>(\<ИменаПодпространствИмён>)*\<ИмяКласса> 
    1. An absolute class name MUST include the top level of the namespace, also known as the “manufacturer name”.
    2. An absolute class name MAY include one or more namespaces.
    3. An absolute class name MUST end with a class name.
    4. Underscores do not have any special meaning in any part of the absolute name of the class.
    5. For alphabetic characters in an absolute namespace, ANY combination of upper and lower case MAY be used.
    6. All class names MUST be case sensitive.
  3. When loading a file corresponding to an absolute class name:

    1. In an absolute class name, a sequence of one or more leading namespaces and namespaces ("namespace prefix"), excluding the leading separator, corresponds to at least one "base directory".
    2. The sequence of namespaces following the "namespace prefix" corresponds to a subdirectory in the "base directory". Namespace delimiters correspond to directory delimiters. The subdirectory name MUST have the same character case as the name of the subspace.
    3. The terminating class name corresponds to a file name ending in .php . The file name MUST be the same case as the terminating class name.
  4. In autoloader implementations, it is NOT ALLOWABLE to throw exceptions, NOT to cause errors at any level, and DO NOT return a value.

3. Examples

The table below shows the correspondence between the file path, the absolute class name, the namespace prefix, and the base directory.

Absolute class name Namespace prefix Base directory The path to the file
\ Acme \ Log \ Writer \ File_Writer Acme \ Log \ Writer ./acme-log-writer/lib/ ./acme-log-writer/lib/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

Examples of the implementation of autoloaders that meet the specifications are given in the examples file. DO NOT consider them as part of the specification. Examples MAY change at any time.

Additional Info:
  • PSR-4 - Autoloader
  • PSR-4 metadocument
  • PSR-4 Implementation Examples

    Autoloader

    The keywords “MUST” (“MUST”), “MUST NOT” (“MUST NOT”), “REQUIRED”, “NEED” (“SHALL”), “NOT ALLOW” (“SHALL NOT”), "SHOULD" ("SHOULD"), "DO NOT SUBJECT" ("SHOULD NOT"), "RECOMMENDED" ("RECOMMENDED"), "CAN" ("MAY") and "OPTIONAL" ("OPTIONAL") in this document should regarded as described in RFC 2119.

    1. Overview

    This PSR describes the specification for autoloading classes based on file paths. It is completely interchangeable and can be used in addition to any other autoloader specification, including PSR-0. This PSR also describes where to place the files that will be loaded in accordance with the specification.

    2. Specification

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

    2. The absolute class name has the following form:

       \<ИмяПространстваИмён>(\<ИменаПодпространствИмён>)*\<ИмяКласса> 
      1. An absolute class name MUST include the top level of the namespace, also known as the “manufacturer name”.
      2. An absolute class name MAY include one or more namespaces.
      3. An absolute class name MUST end with a class name.
      4. Underscores do not have any special meaning in any part of the absolute name of the class.
      5. For alphabetic characters in an absolute namespace, ANY combination of upper and lower case MAY be used.
      6. All class names MUST be case sensitive.
    3. When loading a file corresponding to an absolute class name:

      1. In an absolute class name, a sequence of one or more leading namespaces and namespaces ("namespace prefix"), excluding the leading separator, corresponds to at least one "base directory".
      2. The sequence of namespaces following the "namespace prefix" corresponds to a subdirectory in the "base directory". Namespace delimiters correspond to directory delimiters. The subdirectory name MUST have the same character case as the name of the subspace.
      3. The terminating class name corresponds to a file name ending in .php . The file name MUST be the same case as the terminating class name.
    4. In autoloader implementations, it is NOT ALLOWABLE to throw exceptions, NOT to cause errors at any level, and DO NOT return a value.

    3. Examples

    The table below shows the correspondence between the file path, the absolute class name, the namespace prefix, and the base directory.

    Absolute class name Namespace prefix Base directory The path to the file
    \ Acme \ Log \ Writer \ File_Writer Acme \ Log \ Writer ./acme-log-writer/lib/ ./acme-log-writer/lib/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

    Examples of the implementation of autoloaders that meet the specifications are given in the examples file. DO NOT consider them as part of the specification. Examples MAY change at any time.

    Additional Info:
    • PSR-4 - Autoloader
    • PSR-4 metadocument
    • PSR-4 Implementation Examples

Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Software and information systems development

Terms: Software and information systems development