psr 4_ autoloader php fig
TRANSCRIPT
-
7/25/2019 Psr 4_Autoloader Php Fig
1/4
PHP-FIGHomeRecommendations (PSRs)MembersBylawsFAQsGet InvolvedPSR-4: AutoloaderPSR-4: Autoloader
The key words"MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and"OPTIONAL" in
thisdocument are to be interpretedasdescribedin RFC 2119.
1. Overview
ThisPSR describesa specification forautoloadingclassesfrom file paths. It is
fully interoperable, andcan be usedin addition to any otherautoloading
specification, including PSR-0. ThisPSR also describeswhere to place files
that will be autoloadedaccording to the specification.
2. Speci cation
The term "class" refersto classes, interfaces, traits, andothersimilar
structures.
1.
A fully qualifiedclassname hasthe following form:
\(\)*\
The fully qualifiedclassname MUST have a top-level namespace
name, also known asa "vendornamespace".
1.
The fully qualifiedclassname MAY have one ormore sub-namespace
names.
2.
2.
4: Autoloader - PHP-FIG http://www.php-fig.org/p
4 19/06/2016 0
-
7/25/2019 Psr 4_Autoloader Php Fig
2/4
The fully qualifiedclassname MUST have a terminating classname.3.
Underscoreshave no special meaning in any portion of the fully
qualifiedclassname.
4.
Alphabetic charactersin the fully qualifiedclassname MAY be any
combination of lowercase anduppercase.
5.
All classnamesMUST be referencedin a case-sensitive fashion.6.
When loading a file that correspondsto a fully qualifiedclassname ...
A contiguousseriesof one ormore leading namespace and
sub-namespace names, not including the leading namespace
separator, in the fully qualifiedclassname (a "namespace prefix")
correspondsto at least one "base directory".
1.
The contiguoussub-namespace namesafterthe "namespace prefix"
correspondto a subdirectory within a "base directory", in which the
namespace separatorsrepresent directory separators. The
subdirectory name MUST match the case of the sub-namespace
names.
2.
The terminating classname correspondsto a file name ending in.php . The file name MUST match the case of the terminating class
name.
3.
3.
AutoloaderimplementationsMUST NOT throwexceptions, MUST NOT
raise errorsof any level, andSHOULD NOT return a value.
4.
3. Examples
The table belowshowsthe corresponding file path fora given fully qualified
classname, namespace prefix, andbase directory.
FULLY QUALIFIEDCLASS NAME
NAMESPACEPREFIX
BASEDIRECTORY
RESULTING FILEPATH
4: Autoloader - PHP-FIG http://www.php-fig.org/p
4 19/06/2016 0
-
7/25/2019 Psr 4_Autoloader Php Fig
3/4
FULLY QUALIFIEDCLASS NAME
NAMESPACEPREFIX
BASEDIRECTORY
RESULTING FILEPATH
\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
Forexample implementationsof autoloadersconforming to the specification,
please see the examplesfile. Example implementationsMUST NOT be
regardedaspart of the specification andMAY change at any time.
Additional Info:
Available translations:
PSR-4: Autoloader
PSR-4 Meta Document
Example Implementationsof PSR-4
English (official)
4: Autoloader - PHP-FIG http://www.php-fig.org/p
4 19/06/2016 0
-
7/25/2019 Psr 4_Autoloader Php Fig
4/4
Followuson Twitter Chat on IRC Channel Contribute via Github Join ourmailing list
2016PHP Framework Interop Group. Site design by Jonathan Reinink.
4: Autoloader - PHP-FIG http://www.php-fig.org/p
4 19/06/2016 0