The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

本文档中的关键词“必须”、“不可”、“必须”、“必须”、“应该”、“不应该”、“推荐”、“可能”和“可选”将按照 RFC2119中的描述进行解释。

  1. Overview
  2. 概述
    This PSR describes a specification for autoloading classes from file paths. It is fully interoperable, and can be used in addition to any other autoloading specification, including PSR-0. This PSR also describes where to place files that will be autoloaded according to the specification.

这个 PSR 描述了从文件路径自动加载类的规范。它是完全互操作的,可以用于除了任何其他自动加载规范,包括 PSR-0。这个 PSR 还描述了将根据规范自动加载的文件放置在何处。

  1. Specification
  2. 规格
    The term "class" refers to classes, interfaces, traits, and other similar structures.

术语“类”指的是类、接口、特性和其他类似的结构。

A fully qualified class name has the following form:

完全限定类名的形式如下:

\<NamespaceName>(\<SubNamespaceNames>)*\<ClassName>
The fully qualified class name MUST have a top-level namespace name, also known as a "vendor namespace".

完全限定类名必须具有顶级名称空间名称,也称为“供应商名称空间”。

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

完全限定类名称可能有一个或多个子命名空间名称。

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

完全限定类名必须具有终止类名。

Underscores have no special meaning in any portion of the fully qualified class name.

下划线在完全限定类名的任何部分中都没有特殊意义。

Alphabetic characters in the fully qualified class name MAY be any combination of lower case and upper case.

完全限定类名称中的字母字符可以是小写字母和大写字母的任意组合。

All class names MUST be referenced in a case-sensitive fashion.

必须以区分大小写的方式引用所有类名。

When loading a file that corresponds to a fully qualified class name ...

加载对应于完全限定类名的文件时..。

A contiguous series of one or more leading namespace and sub-namespace names, not including the leading namespace separator, in the fully qualified class name (a "namespace prefix") corresponds to at least one "base directory".

在完全限定类名(“名称空间前缀”)中,由一个或多个前导名称空间和子名称空间名称(不包括前导名称空间分隔符)组成的连续系列对应于至少一个“基本目录”。

The contiguous sub-namespace names after the "namespace prefix" correspond to a subdirectory within a "base directory", in which the namespace separators represent directory separators. The subdirectory name MUST match the case of the sub-namespace names.

“名称空间前缀”之后的连续子名称空间名称对应于“基本目录”中的一个子目录,其中名称空间分隔符表示目录分隔符。子目录名称必须与子名称空间名称的大小写匹配。

The terminating class name corresponds to a file name ending in .php. The file name MUST match the case of the terminating class name.

终止类名对应于以。我不知道。文件名必须与终止类名的大小写匹配。

Autoloader implementations MUST NOT throw exceptions, MUST NOT raise errors of any level, and SHOULD NOT return a value.

自动加载程序的实现不能抛出异常,不能引发任何级别的错误,并且不应该返回值。

  1. Examples
  2. 例子
    The table below shows the corresponding file path for a given fully qualified class name, namespace prefix, and base directory.

下表显示了给定的完全限定类名、命名空间前缀和基目录的相应文件路径。

FULLY QUALIFIED CLASS NAME
完全限定类名
NAMESPACE PREFIX
名称空间前缀
BASE DIRECTORY
基本目录
RESULTING FILE PATH
结果文件路径
\Acme\Log\Writer\File_Writer
Acme Log Writer File _ Writer
Acme\Log\Writer
Acme Log Writer
./acme-log-writer/lib/
./acme-log-writer/lib/File_Writer.php
./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 核心请求
Symfony\Core
Symfony Core
./vendor/Symfony/Core/
./供应商/Symfony/核心/
./vendor/Symfony/Core/Request.php
。/厂商/Symfony/核心/Request.php
\Zend\Acl
Zend Acl
Zend
赞德
/usr/includes/Zend/
/usr/包括/Zend/
/usr/includes/Zend/Acl.php
/usr/include/Zend/Acl.php
For example implementations of autoloaders conforming to the specification, please see the examples file. Example implementations MUST NOT be regarded as part of the specification and MAY change at any time.

最后修改:2024 年 04 月 07 日
如果觉得我的文章对你有用,请随意赞赏