您的位置:首页 > 编程语言 > PHP开发

PHP PSR-0 语言规范翻译

2014-06-12 11:53 696 查看
摘自:https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md

A fully-qualified namespace and class must have the followingstructure
\<Vendor Name>\(<Namespace>\)*<Class Name>

Each namespace must have a top-level namespace ("Vendor Name").
Each namespace can have as many sub-namespaces as it wishes.
Each namespace separator is converted to a
DIRECTORY_SEPARATOR
whenloading from the file system.
Each
_
character in the CLASS NAME is converted to a
DIRECTORY_SEPARATOR
. The
_
character has no special meaning in thenamespace.
The fully-qualified namespace and class is suffixed with
.php
whenloading from the file system.
Alphabetic characters in vendor names, namespaces, and class names maybe of any combination of lower case and upper case.

大致翻译:

命名空间与类的结构为:\供应商\命名空间\类名。
每个命名空间必须有顶级(供应商)
每个命名空间可以有多个子命名空间。
每个命名空间分割可被转化“/”(目录分割符),当从文件系统中加载的时候。
类名中的_下划线可被转化成“/”(目录分割符),这个符号没有特殊的意思。
类与命名空间后缀以“.php”结尾,当从文件系统中加载的时候。
\供应商\命名空间\类名的字符随便是小写或大写。

Examples

\Doctrine\Common\IsolatedClassLoader
=>
/path/to/project/lib/vendor/Doctrine/Common/IsolatedClassLoader.php

\Symfony\Core\Request
=>
/path/to/project/lib/vendor/Symfony/Core/Request.php

\Zend\Acl
=>
/path/to/project/lib/vendor/Zend/Acl.php

\Zend\Mail\Message
=>
/path/to/project/lib/vendor/Zend/Mail/Message.php


Underscores in Namespaces and Class
Names

\namespace\package\Class_Name
=>
/path/to/project/lib/vendor/namespace/package/Class/Name.php

\namespace\package_name\Class_Name
=>
/path/to/project/lib/vendor/namespace/package_name/Class/Name.php
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: