You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by bh...@apache.org on 2011/10/28 01:30:21 UTC
svn commit: r1190090 - in
/shindig/branches/php_namespace_refactoring/php/external: OAuth/ Symfony/
Symfony/Component/ Symfony/Component/ClassLoader/
Author: bhofmann
Date: Thu Oct 27 23:30:20 2011
New Revision: 1190090
URL: http://svn.apache.org/viewvc?rev=1190090&view=rev
Log:
namespace refactoring
Added:
shindig/branches/php_namespace_refactoring/php/external/Symfony/
shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/
shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/
shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php (with props)
shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ClassCollectionLoader.php (with props)
shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php (with props)
shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/LICENSE
shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/MapClassLoader.php (with props)
shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/UniversalClassLoader.php (with props)
Modified:
shindig/branches/php_namespace_refactoring/php/external/OAuth/OAuth.php
Modified: shindig/branches/php_namespace_refactoring/php/external/OAuth/OAuth.php
URL: http://svn.apache.org/viewvc/shindig/branches/php_namespace_refactoring/php/external/OAuth/OAuth.php?rev=1190090&r1=1190089&r2=1190090&view=diff
==============================================================================
--- shindig/branches/php_namespace_refactoring/php/external/OAuth/OAuth.php (original)
+++ shindig/branches/php_namespace_refactoring/php/external/OAuth/OAuth.php Thu Oct 27 23:30:20 2011
@@ -90,9 +90,9 @@ abstract class OAuthSignatureMethod {
}
/**
- * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
- * where the Signature Base String is the text and the key is the concatenated values (each first
- * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
+ * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
+ * where the Signature Base String is the text and the key is the concatenated values (each first
+ * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
* character (ASCII code 38) even if empty.
* - Chapter 9.2 ("HMAC-SHA1")
*/
@@ -118,7 +118,7 @@ class OAuthSignatureMethod_HMAC_SHA1 ext
}
/**
- * The PLAINTEXT method does not provide any security protection and SHOULD only be used
+ * The PLAINTEXT method does not provide any security protection and SHOULD only be used
* over a secure channel such as HTTPS. It does not use the Signature Base String.
* - Chapter 9.4 ("PLAINTEXT")
*/
@@ -128,8 +128,8 @@ class OAuthSignatureMethod_PLAINTEXT ext
}
/**
- * oauth_signature is set to the concatenated encoded values of the Consumer Secret and
- * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
+ * oauth_signature is set to the concatenated encoded values of the Consumer Secret and
+ * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
* empty. The result MUST be encoded again.
* - Chapter 9.4.1 ("Generating Signatures")
*
@@ -151,10 +151,10 @@ class OAuthSignatureMethod_PLAINTEXT ext
}
/**
- * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in
- * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for
- * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a
- * verified way to the Service Provider, in a manner which is beyond the scope of this
+ * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in
+ * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for
+ * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a
+ * verified way to the Service Provider, in a manner which is beyond the scope of this
* specification.
* - Chapter 9.3 ("RSA-SHA1")
*/
@@ -555,7 +555,7 @@ class OAuthServer {
private function get_version(&$request) {
$version = $request->get_parameter("oauth_version");
if (!$version) {
- // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
+ // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
// Chapter 7.0 ("Accessing Protected Ressources")
$version = '1.0';
}
@@ -569,7 +569,7 @@ class OAuthServer {
* figure out the signature with some defaults
*/
private function get_signature_method($request) {
- $signature_method = $request instanceof OAuthRequest
+ $signature_method = $request instanceof OAuthRequest
? $request->get_parameter("oauth_signature_method")
: NULL;
@@ -594,7 +594,7 @@ class OAuthServer {
* try to find the consumer for the provided request's consumer key
*/
private function get_consumer($request) {
- $consumer_key = $request instanceof OAuthRequest
+ $consumer_key = $request instanceof OAuthRequest
? $request->get_parameter("oauth_consumer_key")
: NULL;
@@ -666,7 +666,7 @@ class OAuthServer {
throw new OAuthException(
'Missing timestamp parameter. The parameter is required'
);
-
+
// verify that timestamp is recentish
$now = time();
if (abs($now - $timestamp) > $this->timestamp_threshold) {
@@ -876,4 +876,4 @@ class OAuthUtil {
}
}
-?>
+?>
\ No newline at end of file
Added: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php
URL: http://svn.apache.org/viewvc/shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php?rev=1190090&view=auto
==============================================================================
--- shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php (added)
+++ shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php Thu Oct 27 23:30:20 2011
@@ -0,0 +1,96 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fa...@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\ClassLoader;
+
+/**
+ * ApcUniversalClassLoader implements a "universal" autoloader cached in APC for PHP 5.3.
+ *
+ * It is able to load classes that use either:
+ *
+ * * The technical interoperability standards for PHP 5.3 namespaces and
+ * class names (http://groups.google.com/group/php-standards/web/psr-0-final-proposal);
+ *
+ * * The PEAR naming convention for classes (http://pear.php.net/).
+ *
+ * Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be
+ * looked for in a list of locations to ease the vendoring of a sub-set of
+ * classes for large projects.
+ *
+ * Example usage:
+ *
+ * require 'vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
+ * require 'vendor/symfony/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
+ *
+ * use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
+ *
+ * $loader = new ApcUniversalClassLoader('apc.prefix.');
+ *
+ * // register classes with namespaces
+ * $loader->registerNamespaces(array(
+ * 'Symfony\Component' => __DIR__.'/component',
+ * 'Symfony' => __DIR__.'/framework',
+ * 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
+ * ));
+ *
+ * // register a library using the PEAR naming convention
+ * $loader->registerPrefixes(array(
+ * 'Swift_' => __DIR__.'/Swift',
+ * ));
+ *
+ * // activate the autoloader
+ * $loader->register();
+ *
+ * In this example, if you try to use a class in the Symfony\Component
+ * namespace or one of its children (Symfony\Component\Console for instance),
+ * the autoloader will first look for the class under the component/
+ * directory, and it will then fallback to the framework/ directory if not
+ * found before giving up.
+ *
+ * @author Fabien Potencier <fa...@symfony.com>
+ * @author Kris Wallsmith <kr...@symfony.com>
+ *
+ * @api
+ */
+class ApcUniversalClassLoader extends UniversalClassLoader
+{
+ private $prefix;
+
+ /**
+ * Constructor.
+ *
+ * @param string $prefix A prefix to create a namespace in APC
+ *
+ * @api
+ */
+ public function __construct($prefix)
+ {
+ if (!extension_loaded('apc')) {
+ throw new \RuntimeException('Unable to use ApcUniversalClassLoader as APC is not enabled.');
+ }
+
+ $this->prefix = $prefix;
+ }
+
+ /**
+ * Finds a file by class name while caching lookups to APC.
+ *
+ * @param string $class A class name to resolve to file
+ */
+ public function findFile($class)
+ {
+ if (false === $file = apc_fetch($this->prefix.$class)) {
+ apc_store($this->prefix.$class, $file = parent::findFile($class));
+ }
+
+ return $file;
+ }
+}
Propchange: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php
------------------------------------------------------------------------------
svn:keywords = Id
Added: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ClassCollectionLoader.php
URL: http://svn.apache.org/viewvc/shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ClassCollectionLoader.php?rev=1190090&view=auto
==============================================================================
--- shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ClassCollectionLoader.php (added)
+++ shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ClassCollectionLoader.php Thu Oct 27 23:30:20 2011
@@ -0,0 +1,222 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fa...@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\ClassLoader;
+
+/**
+ * ClassCollectionLoader.
+ *
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class ClassCollectionLoader
+{
+ static private $loaded;
+
+ /**
+ * Loads a list of classes and caches them in one big file.
+ *
+ * @param array $classes An array of classes to load
+ * @param string $cacheDir A cache directory
+ * @param string $name The cache name prefix
+ * @param Boolean $autoReload Whether to flush the cache when the cache is stale or not
+ * @param Boolean $adaptive Whether to remove already declared classes or not
+ * @param string $extension File extension of the resulting file
+ *
+ * @throws \InvalidArgumentException When class can't be loaded
+ */
+ static public function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
+ {
+ // each $name can only be loaded once per PHP process
+ if (isset(self::$loaded[$name])) {
+ return;
+ }
+
+ self::$loaded[$name] = true;
+
+ if ($adaptive) {
+ // don't include already declared classes
+ $classes = array_diff($classes, get_declared_classes(), get_declared_interfaces());
+
+ // the cache is different depending on which classes are already declared
+ $name = $name.'-'.substr(md5(implode('|', $classes)), 0, 5);
+ }
+
+ $cache = $cacheDir.'/'.$name.$extension;
+
+ // auto-reload
+ $reload = false;
+ if ($autoReload) {
+ $metadata = $cacheDir.'/'.$name.$extension.'.meta';
+ if (!is_file($metadata) || !is_file($cache)) {
+ $reload = true;
+ } else {
+ $time = filemtime($cache);
+ $meta = unserialize(file_get_contents($metadata));
+
+ if ($meta[1] != $classes) {
+ $reload = true;
+ } else {
+ foreach ($meta[0] as $resource) {
+ if (!is_file($resource) || filemtime($resource) > $time) {
+ $reload = true;
+
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (!$reload && is_file($cache)) {
+ require_once $cache;
+
+ return;
+ }
+
+ $files = array();
+ $content = '';
+ foreach ($classes as $class) {
+ if (!class_exists($class) && !interface_exists($class)) {
+ throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
+ }
+
+ $r = new \ReflectionClass($class);
+ $files[] = $r->getFileName();
+
+ $c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($r->getFileName()));
+
+ // add namespace declaration for global code
+ if (!$r->inNamespace()) {
+ $c = "\nnamespace\n{\n".self::stripComments($c)."\n}\n";
+ } else {
+ $c = self::fixNamespaceDeclarations('<?php '.$c);
+ $c = preg_replace('/^\s*<\?php/', '', $c);
+ }
+
+ $content .= $c;
+ }
+
+ // cache the core classes
+ if (!is_dir(dirname($cache))) {
+ mkdir(dirname($cache), 0777, true);
+ }
+ self::writeCacheFile($cache, '<?php '.$content);
+
+ if ($autoReload) {
+ // save the resources
+ self::writeCacheFile($metadata, serialize(array($files, $classes)));
+ }
+ }
+
+ /**
+ * Adds brackets around each namespace if it's not already the case.
+ *
+ * @param string $source Namespace string
+ *
+ * @return string Namespaces with brackets
+ */
+ static public function fixNamespaceDeclarations($source)
+ {
+ if (!function_exists('token_get_all')) {
+ return $source;
+ }
+
+ $output = '';
+ $inNamespace = false;
+ $tokens = token_get_all($source);
+
+ for ($i = 0, $max = count($tokens); $i < $max; $i++) {
+ $token = $tokens[$i];
+ if (is_string($token)) {
+ $output .= $token;
+ } elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
+ // strip comments
+ continue;
+ } elseif (T_NAMESPACE === $token[0]) {
+ if ($inNamespace) {
+ $output .= "}\n";
+ }
+ $output .= $token[1];
+
+ // namespace name and whitespaces
+ while (($t = $tokens[++$i]) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
+ $output .= $t[1];
+ }
+ if (is_string($t) && '{' === $t) {
+ $inNamespace = false;
+ --$i;
+ } else {
+ $output .= "\n{";
+ $inNamespace = true;
+ }
+ } else {
+ $output .= $token[1];
+ }
+ }
+
+ if ($inNamespace) {
+ $output .= "}\n";
+ }
+
+ return $output;
+ }
+
+ /**
+ * Writes a cache file.
+ *
+ * @param string $file Filename
+ * @param string $content Temporary file content
+ *
+ * @throws \RuntimeException when a cache file cannot be written
+ */
+ static private function writeCacheFile($file, $content)
+ {
+ $tmpFile = tempnam(dirname($file), basename($file));
+ if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
+ chmod($file, 0644);
+
+ return;
+ }
+
+ throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
+ }
+
+ /**
+ * Removes comments from a PHP source string.
+ *
+ * We don't use the PHP php_strip_whitespace() function
+ * as we want the content to be readable and well-formatted.
+ *
+ * @param string $source A PHP string
+ *
+ * @return string The PHP string with the comments removed
+ */
+ static private function stripComments($source)
+ {
+ if (!function_exists('token_get_all')) {
+ return $source;
+ }
+
+ $output = '';
+ foreach (token_get_all($source) as $token) {
+ if (is_string($token)) {
+ $output .= $token;
+ } elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
+ $output .= $token[1];
+ }
+ }
+
+ // replace multiple new lines with a single newline
+ $output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
+
+ return $output;
+ }
+}
Propchange: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/ClassCollectionLoader.php
------------------------------------------------------------------------------
svn:keywords = Id
Added: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php
URL: http://svn.apache.org/viewvc/shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php?rev=1190090&view=auto
==============================================================================
--- shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php (added)
+++ shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php Thu Oct 27 23:30:20 2011
@@ -0,0 +1,63 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fa...@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\ClassLoader;
+
+/**
+ * Checks that the class is actually declared in the included file.
+ *
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class DebugUniversalClassLoader extends UniversalClassLoader
+{
+ /**
+ * Replaces all regular UniversalClassLoader instances by a DebugUniversalClassLoader ones.
+ */
+ static public function enable()
+ {
+ if (!is_array($functions = spl_autoload_functions())) {
+ return;
+ }
+
+ foreach ($functions as $function) {
+ spl_autoload_unregister($function);
+ }
+
+ foreach ($functions as $function) {
+ if (is_array($function) && $function[0] instanceof UniversalClassLoader) {
+ $loader = new static();
+ $loader->registerNamespaceFallbacks($function[0]->getNamespaceFallbacks());
+ $loader->registerPrefixFallbacks($function[0]->getPrefixFallbacks());
+ $loader->registerNamespaces($function[0]->getNamespaces());
+ $loader->registerPrefixes($function[0]->getPrefixes());
+ $loader->useIncludePath($function[0]->getUseIncludePath());
+
+ $function[0] = $loader;
+ }
+
+ spl_autoload_register($function);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function loadClass($class)
+ {
+ if ($file = $this->findFile($class)) {
+ require $file;
+
+ if (!class_exists($class, false) && !interface_exists($class, false)) {
+ throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
+ }
+ }
+ }
+}
Propchange: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php
------------------------------------------------------------------------------
svn:keywords = Id
Added: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/LICENSE
URL: http://svn.apache.org/viewvc/shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/LICENSE?rev=1190090&view=auto
==============================================================================
--- shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/LICENSE (added)
+++ shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/LICENSE Thu Oct 27 23:30:20 2011
@@ -0,0 +1,19 @@
+Copyright (c) 2004-2011 Fabien Potencier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
Added: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/MapClassLoader.php
URL: http://svn.apache.org/viewvc/shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/MapClassLoader.php?rev=1190090&view=auto
==============================================================================
--- shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/MapClassLoader.php (added)
+++ shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/MapClassLoader.php Thu Oct 27 23:30:20 2011
@@ -0,0 +1,76 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fa...@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\ClassLoader;
+
+/**
+ * A class loader that uses a mapping file to look up paths.
+ *
+ * @author Fabien Potencier <fa...@symfony.com>
+ */
+class MapClassLoader
+{
+ private $map = array();
+
+ /**
+ * Constructor.
+ *
+ * @param array $map A map where keys are classes and values the absolute file path
+ */
+ public function __construct(array $map)
+ {
+ $this->map = $map;
+ }
+
+ /**
+ * Registers this instance as an autoloader.
+ *
+ * @param Boolean $prepend Whether to prepend the autoloader or not
+ */
+ public function register($prepend = false)
+ {
+ spl_autoload_register(array($this, 'loadClass'), true, $prepend);
+ }
+
+ /**
+ * Loads the given class or interface.
+ *
+ * @param string $class The name of the class
+ */
+ public function loadClass($class)
+ {
+ if ('\\' === $class[0]) {
+ $class = substr($class, 1);
+ }
+
+ if (isset($this->map[$class])) {
+ require $this->map[$class];
+ }
+ }
+
+ /**
+ * Finds the path to the file where the class is defined.
+ *
+ * @param string $class The name of the class
+ *
+ * @return string|null The path, if found
+ */
+ public function findFile($class)
+ {
+ if ('\\' === $class[0]) {
+ $class = substr($class, 1);
+ }
+
+ if (isset($this->map[$class])) {
+ return $this->map[$class];
+ }
+ }
+}
Propchange: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/MapClassLoader.php
------------------------------------------------------------------------------
svn:keywords = Id
Added: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/UniversalClassLoader.php
URL: http://svn.apache.org/viewvc/shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/UniversalClassLoader.php?rev=1190090&view=auto
==============================================================================
--- shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/UniversalClassLoader.php (added)
+++ shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/UniversalClassLoader.php Thu Oct 27 23:30:20 2011
@@ -0,0 +1,299 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fa...@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\ClassLoader;
+
+/**
+ * UniversalClassLoader implements a "universal" autoloader for PHP 5.3.
+ *
+ * It is able to load classes that use either:
+ *
+ * * The technical interoperability standards for PHP 5.3 namespaces and
+ * class names (http://groups.google.com/group/php-standards/web/psr-0-final-proposal);
+ *
+ * * The PEAR naming convention for classes (http://pear.php.net/).
+ *
+ * Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be
+ * looked for in a list of locations to ease the vendoring of a sub-set of
+ * classes for large projects.
+ *
+ * Example usage:
+ *
+ * $loader = new UniversalClassLoader();
+ *
+ * // register classes with namespaces
+ * $loader->registerNamespaces(array(
+ * 'Symfony\Component' => __DIR__.'/component',
+ * 'Symfony' => __DIR__.'/framework',
+ * 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
+ * ));
+ *
+ * // register a library using the PEAR naming convention
+ * $loader->registerPrefixes(array(
+ * 'Swift_' => __DIR__.'/Swift',
+ * ));
+ *
+ *
+ * // to enable searching the include path (eg. for PEAR packages)
+ * $loader->useIncludePath(true);
+ *
+ * // activate the autoloader
+ * $loader->register();
+ *
+ * In this example, if you try to use a class in the Symfony\Component
+ * namespace or one of its children (Symfony\Component\Console for instance),
+ * the autoloader will first look for the class under the component/
+ * directory, and it will then fallback to the framework/ directory if not
+ * found before giving up.
+ *
+ * @author Fabien Potencier <fa...@symfony.com>
+ *
+ * @api
+ */
+class UniversalClassLoader
+{
+ private $namespaces = array();
+ private $prefixes = array();
+ private $namespaceFallbacks = array();
+ private $prefixFallbacks = array();
+ private $useIncludePath = false;
+
+ /**
+ * Turns on searching the include for class files. Allows easy loading
+ * of installed PEAR packages
+ *
+ * @param Boolean $useIncludePath
+ */
+ public function useIncludePath($useIncludePath)
+ {
+ $this->useIncludePath = $useIncludePath;
+ }
+
+ /**
+ * Can be used to check if the autoloader uses the include path to check
+ * for classes.
+ *
+ * @return Boolean
+ */
+ public function getUseIncludePath()
+ {
+ return $this->useIncludePath;
+ }
+
+ /**
+ * Gets the configured namespaces.
+ *
+ * @return array A hash with namespaces as keys and directories as values
+ */
+ public function getNamespaces()
+ {
+ return $this->namespaces;
+ }
+
+ /**
+ * Gets the configured class prefixes.
+ *
+ * @return array A hash with class prefixes as keys and directories as values
+ */
+ public function getPrefixes()
+ {
+ return $this->prefixes;
+ }
+
+ /**
+ * Gets the directory(ies) to use as a fallback for namespaces.
+ *
+ * @return array An array of directories
+ */
+ public function getNamespaceFallbacks()
+ {
+ return $this->namespaceFallbacks;
+ }
+
+ /**
+ * Gets the directory(ies) to use as a fallback for class prefixes.
+ *
+ * @return array An array of directories
+ */
+ public function getPrefixFallbacks()
+ {
+ return $this->prefixFallbacks;
+ }
+
+ /**
+ * Registers the directory to use as a fallback for namespaces.
+ *
+ * @param array $dirs An array of directories
+ *
+ * @api
+ */
+ public function registerNamespaceFallbacks(array $dirs)
+ {
+ $this->namespaceFallbacks = $dirs;
+ }
+
+ /**
+ * Registers the directory to use as a fallback for class prefixes.
+ *
+ * @param array $dirs An array of directories
+ *
+ * @api
+ */
+ public function registerPrefixFallbacks(array $dirs)
+ {
+ $this->prefixFallbacks = $dirs;
+ }
+
+ /**
+ * Registers an array of namespaces
+ *
+ * @param array $namespaces An array of namespaces (namespaces as keys and locations as values)
+ *
+ * @api
+ */
+ public function registerNamespaces(array $namespaces)
+ {
+ foreach ($namespaces as $namespace => $locations) {
+ $this->namespaces[$namespace] = (array) $locations;
+ }
+ }
+
+ /**
+ * Registers a namespace.
+ *
+ * @param string $namespace The namespace
+ * @param array|string $paths The location(s) of the namespace
+ *
+ * @api
+ */
+ public function registerNamespace($namespace, $paths)
+ {
+ $this->namespaces[$namespace] = (array) $paths;
+ }
+
+ /**
+ * Registers an array of classes using the PEAR naming convention.
+ *
+ * @param array $classes An array of classes (prefixes as keys and locations as values)
+ *
+ * @api
+ */
+ public function registerPrefixes(array $classes)
+ {
+ foreach ($classes as $prefix => $locations) {
+ $this->prefixes[$prefix] = (array) $locations;
+ }
+ }
+
+ /**
+ * Registers a set of classes using the PEAR naming convention.
+ *
+ * @param string $prefix The classes prefix
+ * @param array|string $paths The location(s) of the classes
+ *
+ * @api
+ */
+ public function registerPrefix($prefix, $paths)
+ {
+ $this->prefixes[$prefix] = (array) $paths;
+ }
+
+ /**
+ * Registers this instance as an autoloader.
+ *
+ * @param Boolean $prepend Whether to prepend the autoloader or not
+ *
+ * @api
+ */
+ public function register($prepend = false)
+ {
+ spl_autoload_register(array($this, 'loadClass'), true, $prepend);
+ }
+
+ /**
+ * Loads the given class or interface.
+ *
+ * @param string $class The name of the class
+ */
+ public function loadClass($class)
+ {
+ if ($file = $this->findFile($class)) {
+ require $file;
+ }
+ }
+
+ /**
+ * Finds the path to the file where the class is defined.
+ *
+ * @param string $class The name of the class
+ *
+ * @return string|null The path, if found
+ */
+ public function findFile($class)
+ {
+ if ('\\' == $class[0]) {
+ $class = substr($class, 1);
+ }
+
+ if (false !== $pos = strrpos($class, '\\')) {
+ // namespaced class name
+ $namespace = substr($class, 0, $pos);
+ $className = substr($class, $pos + 1);
+ $normalizedClass = str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
+ foreach ($this->namespaces as $ns => $dirs) {
+ if (0 !== strpos($namespace, $ns)) {
+ continue;
+ }
+
+ foreach ($dirs as $dir) {
+ $file = $dir.DIRECTORY_SEPARATOR.$normalizedClass;
+ if (is_file($file)) {
+ return $file;
+ }
+ }
+ }
+
+ foreach ($this->namespaceFallbacks as $dir) {
+ $file = $dir.DIRECTORY_SEPARATOR.$normalizedClass;
+ if (is_file($file)) {
+ return $file;
+ }
+ }
+
+ } else {
+ // PEAR-like class name
+ $normalizedClass = str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
+ foreach ($this->prefixes as $prefix => $dirs) {
+ if (0 !== strpos($class, $prefix)) {
+ continue;
+ }
+
+ foreach ($dirs as $dir) {
+ $file = $dir.DIRECTORY_SEPARATOR.$normalizedClass;
+ if (is_file($file)) {
+ return $file;
+ }
+ }
+ }
+
+ foreach ($this->prefixFallbacks as $dir) {
+ $file = $dir.DIRECTORY_SEPARATOR.$normalizedClass;
+ if (is_file($file)) {
+ return $file;
+ }
+ }
+ }
+
+ if ($this->useIncludePath && $file = stream_resolve_include_path($normalizedClass)) {
+ return $file;
+ }
+ }
+}
Propchange: shindig/branches/php_namespace_refactoring/php/external/Symfony/Component/ClassLoader/UniversalClassLoader.php
------------------------------------------------------------------------------
svn:keywords = Id