PHP PSR-4 Autoloader Automatic loading Chinese version nt6 OEM loader loader activation Tool SKSE Loader

Source: Internet
Author: User
Tags autoloader
Autoloader

Keywords "must" ("must"), "must not/must not be" ("must not"), "Need" ("REQUIRED"),
"Will" ("Shall"), "no" ("Shall not"), "should" ("should"), "shouldn't" ("should not"),
A detailed description of "recommended" ("RECOMMENDED"), "Can" ("may") and "optional" ("OPTIONAL") can be found in [RFC 2119][].

1. Overview

This PSR is about the specification of automatic loading of corresponding classes by file paths,
This specification is interoperable and can be used as a supplement to any automatic loading specification, including PSR-0, in addition,
This PSR also includes the file storage path specification for automatically loaded classes.

2. Detailed description

  1. The "class" Here refers to all class classes, interfaces, traits reusable blocks of code, and other similar structures.

  2. A complete class name needs to have the following structure:

    \<命名空间>(\<子命名空间>)*\<类名>
    1. The complete class name must have a top-level namespace, known as "Vendor namespace";

    2. The full class name can have one or more sub-namespaces;

    3. The complete class name must have a final class name;

    4. The glide line in any part of the complete class name has no special meaning;

    5. The complete class name can consist of any uppercase and lowercase letters;

    6. All class names must be case-sensitive.

  3. When loading the corresponding file according to the full class name ...

    1. In the complete class name, remove the first namespace delimiter, one or more contiguous namespaces and sub-namespaces as "namespace prefixes", which must correspond to at least one "file base directory";

    2. The child namespace immediately following the namespace prefix must match the corresponding file base directory, where the namespace delimiter is used as the directory delimiter.

    3. The class name at the end must have the same name as the corresponding file with the .php suffix.

    4. The implementation of the Autoloader (autoloader) must not throw an exception, must not trigger any level of error information, and should not have a return value.

3. Example

The following table shows the file paths that correspond to the canonical full class name, namespace prefix, and file base directory.

Full class name namespace Prefixes File base directory file path
\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

For the implementation of this specification, refer to the relevant examples
Note: Instances are not part of the specification and are subject to change at any time.

The above describes the PHP PSR-4 Autoloader automatic loading Chinese version, including loader aspects of the content, I hope that the PHP tutorial interested in a friend to help.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.