Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial creation of PHP FIG repo

- Added directory for proposed standards
- Added PSR-0 standard (accepted)
  • Loading branch information...
commit ab3b658ec9fae0ec6b1b93913c1c8789360b3755 0 parents
Matthew Weier O'Phinney weierophinney authored
1  README.md
Source Rendered
... ... @@ -0,0 +1 @@
  1 +Repository for maintaining Framework Interop Group specification proposals.
63 accepted/PSR-0.md
Source Rendered
... ... @@ -0,0 +1,63 @@
  1 +The following describes the mandatory requirements that must be adhered
  2 +to for autoloader interoperability.
  3 +
  4 +## Mandatory:
  5 +* A fully-qualified namespace and class must have the following
  6 + structure \<Vendor Name>\(<Namespace>\)*<Class Name>
  7 +* Each namespace must have a top-level namespace ("Vendor Name").
  8 +* Each namespace can have as many sub-namespaces as it wishes.
  9 +* Each namespace separator is converted to a DIRECTORY_SEPARATOR when
  10 + loading from the file system.
  11 +* Each "_" character in the CLASS NAME is converted to a
  12 +* DIRECTORY_SEPARATOR. The "_" character has no special meaning in the
  13 + namespace.
  14 +* The fully-qualified namespace and class is suffixed with ".php" when
  15 + loading from the file system.
  16 +* Alphabetic characters in vendor names, namespaces, and class names may
  17 + be of any combination of lower case and upper case.
  18 +
  19 +## Examples:
  20 +* \Doctrine\Common\IsolatedClassLoader => /path/to/project/lib/vendor/Doctrine/Common/IsolatedClassLoader.php
  21 +* \Symfony\Core\Request => /path/to/project/lib/vendor/Symfony/Core/Request.php
  22 +* \Zend\Acl => /path/to/project/lib/vendor/Zend/Acl.php
  23 +* \Zend\Mail\Message => /path/to/project/lib/vendor/Zend/Mail/Message.php
  24 +
  25 +## Underscores in namespaces and class names:
  26 +* \namespace\package\Class_Name => /path/to/project/lib/vendor/namespace/package/Class/Name.php
  27 +* \namespace\package_name\Class_Name => /path/to/project/lib/vendor/namespace/package_name/Class/Name.php
  28 +
  29 +The standards we set here should be the lowest common denominator for
  30 +painless autoloader interoperability. You can test that you are
  31 +following these standards by utilizing this sample SplClassLoader
  32 +implementation which is able to load PHP 5.3 classes.
  33 +
  34 +## Example Implementation
  35 +
  36 +Below is an example function to simply demonstrate how the above
  37 +proposed standards are autoloaded.
  38 +
  39 + <?php
  40 +
  41 + function autoload($className)
  42 + {
  43 + $className = ltrim($className, '\\');
  44 + $fileName = '';
  45 + $namespace = '';
  46 + if ($lastNsPos = strripos($className, '\\')) {
  47 + $namespace = substr($className, 0, $lastNsPos);
  48 + $className = substr($className, $lastNsPos + 1);
  49 + $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
  50 + }
  51 + $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
  52 +
  53 + require $fileName;
  54 + }
  55 +
  56 +## SplClassLoader Implementation
  57 +
  58 +The following gist is a sample SplClassLoader implementation that can
  59 +load your classes if you follow the autoloader interoperability
  60 +standards proposed above. It is the current recommended way to load PHP
  61 +5.3 classes that follow these standards.
  62 +
  63 +* http://gist.github.com/221634
0  proposed/.placeholder
No changes.

0 comments on commit ab3b658

Please sign in to comment.
Something went wrong with that request. Please try again.