mirror of
https://github.com/symfony/class-loader.git
synced 2026-03-24 17:22:11 +01:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3527a2b300 | ||
|
|
c393e86a03 | ||
|
|
475b92bd71 | ||
|
|
6329e84c2d | ||
|
|
28bf7c891b | ||
|
|
1c055115cc | ||
|
|
58e364c99c | ||
|
|
788001eb1a | ||
|
|
67f0ac3a3b | ||
|
|
a0c2e07078 |
@@ -17,7 +17,7 @@ namespace Symfony\Component\ClassLoader;
|
||||
* 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);
|
||||
* class names (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md);
|
||||
*
|
||||
* * The PEAR naming convention for classes (http://pear.php.net/).
|
||||
*
|
||||
@@ -84,6 +84,8 @@ class ApcUniversalClassLoader extends UniversalClassLoader
|
||||
* Finds a file by class name while caching lookups to APC.
|
||||
*
|
||||
* @param string $class A class name to resolve to file
|
||||
*
|
||||
* @return string|null The path, if found
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,8 @@ namespace Symfony\Component\ClassLoader;
|
||||
*/
|
||||
class ClassCollectionLoader
|
||||
{
|
||||
static private $loaded;
|
||||
private static $loaded;
|
||||
private static $useTokenizer = true;
|
||||
|
||||
/**
|
||||
* Loads a list of classes and caches them in one big file.
|
||||
@@ -32,7 +33,7 @@ class ClassCollectionLoader
|
||||
*
|
||||
* @throws \InvalidArgumentException When class can't be loaded
|
||||
*/
|
||||
static public function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
|
||||
public static 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])) {
|
||||
@@ -123,9 +124,13 @@ class ClassCollectionLoader
|
||||
*
|
||||
* @return string Namespaces with brackets
|
||||
*/
|
||||
static public function fixNamespaceDeclarations($source)
|
||||
public static function fixNamespaceDeclarations($source)
|
||||
{
|
||||
if (!function_exists('token_get_all')) {
|
||||
if (!function_exists('token_get_all') || !self::$useTokenizer) {
|
||||
if (preg_match('/namespace(.*?)\s*;/', $source)) {
|
||||
$source = preg_replace('/namespace(.*?)(\s*);/', "namespace$1$2\n{", $source)."}\n";
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
@@ -172,12 +177,12 @@ class ClassCollectionLoader
|
||||
/**
|
||||
* Writes a cache file.
|
||||
*
|
||||
* @param string $file Filename
|
||||
* @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)
|
||||
private static function writeCacheFile($file, $content)
|
||||
{
|
||||
$tmpFile = tempnam(dirname($file), basename($file));
|
||||
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
|
||||
@@ -199,7 +204,7 @@ class ClassCollectionLoader
|
||||
*
|
||||
* @return string The PHP string with the comments removed
|
||||
*/
|
||||
static private function stripComments($source)
|
||||
private static function stripComments($source)
|
||||
{
|
||||
if (!function_exists('token_get_all')) {
|
||||
return $source;
|
||||
@@ -219,4 +224,12 @@ class ClassCollectionLoader
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is only useful for testing.
|
||||
*/
|
||||
public static function enableTokenizer($bool)
|
||||
{
|
||||
self::$useTokenizer = (Boolean) $bool;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class DebugUniversalClassLoader extends UniversalClassLoader
|
||||
/**
|
||||
* Replaces all regular UniversalClassLoader instances by a DebugUniversalClassLoader ones.
|
||||
*/
|
||||
static public function enable()
|
||||
public static function enable()
|
||||
{
|
||||
if (!is_array($functions = spl_autoload_functions())) {
|
||||
return;
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2004-2011 Fabien Potencier
|
||||
Copyright (c) 2004-2013 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
|
||||
|
||||
60
README.md
Normal file
60
README.md
Normal file
@@ -0,0 +1,60 @@
|
||||
ClassLoader Component
|
||||
=====================
|
||||
|
||||
ClassLoader loads your project classes automatically if they follow some
|
||||
standard PHP conventions.
|
||||
|
||||
The Universal ClassLoader is able to autoload classes that implement the PSR-0
|
||||
standard or the PEAR naming convention.
|
||||
|
||||
First, register the autoloader:
|
||||
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
|
||||
use Symfony\Component\ClassLoader\UniversalClassLoader;
|
||||
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->register();
|
||||
|
||||
Then, register some namespaces with the `registerNamespace()` method:
|
||||
|
||||
$loader->registerNamespace('Symfony', __DIR__.'/src');
|
||||
$loader->registerNamespace('Monolog', __DIR__.'/vendor/monolog/src');
|
||||
|
||||
The `registerNamespace()` method takes a namespace prefix and a path where to
|
||||
look for the classes as arguments.
|
||||
|
||||
You can also register a sub-namespaces:
|
||||
|
||||
$loader->registerNamespace('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');
|
||||
|
||||
The order of registration is significant and the first registered namespace
|
||||
takes precedence over later registered one.
|
||||
|
||||
You can also register more than one path for a given namespace:
|
||||
|
||||
$loader->registerNamespace('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
|
||||
|
||||
Alternatively, you can use the `registerNamespaces()` method to register more
|
||||
than one namespace at once:
|
||||
|
||||
$loader->registerNamespaces(array(
|
||||
'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
|
||||
'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
|
||||
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
|
||||
'Monolog' => __DIR__.'/vendor/monolog/src',
|
||||
));
|
||||
|
||||
For better performance, you can use the APC based version of the universal
|
||||
class loader:
|
||||
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
|
||||
|
||||
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
|
||||
|
||||
$loader = new ApcUniversalClassLoader('apc.prefix.');
|
||||
|
||||
Furthermore, the component provides tools to aggregate classes into a single
|
||||
file, which is especially useful to improve performance on servers that do not
|
||||
provide byte caches.
|
||||
@@ -17,7 +17,7 @@ namespace Symfony\Component\ClassLoader;
|
||||
* 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);
|
||||
* class names (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md);
|
||||
*
|
||||
* * The PEAR naming convention for classes (http://pear.php.net/).
|
||||
*
|
||||
@@ -169,8 +169,8 @@ class UniversalClassLoader
|
||||
/**
|
||||
* 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
|
||||
* @param string $prefix The classes prefix
|
||||
* @param array|string $paths The location(s) of the classes
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
"description": "Symfony ClassLoader Component",
|
||||
"keywords": [],
|
||||
"homepage": "http://symfony.com",
|
||||
"version": "2.0.7",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user