@@ -4,34 +4,34 @@ ClassLoader Component
4
4
ClassLoader loads your project classes automatically if they follow some
5
5
standard PHP conventions.
6
6
7
- The Universal ClassLoader is able to autoload classes that implement the PSR-0
7
+ The ClassLoader object is able to autoload classes that implement the PSR-0
8
8
standard or the PEAR naming convention.
9
9
10
10
First, register the autoloader:
11
11
12
12
``` php
13
- require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader .php';
13
+ require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader .php';
14
14
15
- use Symfony\Component\ClassLoader\UniversalClassLoader ;
15
+ use Symfony\Component\ClassLoader\ClassLoader ;
16
16
17
- $loader = new UniversalClassLoader ();
17
+ $loader = new ClassLoader ();
18
18
$loader->register();
19
19
```
20
20
21
- Then, register some namespaces with the ` registerNamespace ()` method:
21
+ Then, register some namespaces with the ` addPrefix ()` method:
22
22
23
23
``` php
24
- $loader->registerNamespace ('Symfony', __DIR__.'/src');
25
- $loader->registerNamespace ('Monolog', __DIR__.'/vendor/monolog/src');
24
+ $loader->addPrefix ('Symfony', __DIR__.'/src');
25
+ $loader->addPrefix ('Monolog', __DIR__.'/vendor/monolog/src');
26
26
```
27
27
28
- The ` registerNamespace ()` method takes a namespace prefix and a path where to
28
+ The ` addPrefix ()` method takes a namespace prefix and a path where to
29
29
look for the classes as arguments.
30
30
31
31
You can also register a sub-namespaces:
32
32
33
33
``` php
34
- $loader->registerNamespace ('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');
34
+ $loader->addPrefix ('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');
35
35
```
36
36
37
37
The order of registration is significant and the first registered namespace
@@ -40,31 +40,35 @@ takes precedence over later registered one.
40
40
You can also register more than one path for a given namespace:
41
41
42
42
``` php
43
- $loader->registerNamespace ('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
43
+ $loader->addPrefix ('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
44
44
```
45
45
46
- Alternatively, you can use the ` registerNamespaces ()` method to register more
46
+ Alternatively, you can use the ` addPrefixes ()` method to register more
47
47
than one namespace at once:
48
48
49
49
``` php
50
- $loader->registerNamespaces (array(
50
+ $loader->addPrefixes (array(
51
51
'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
52
52
'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
53
53
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
54
54
'Monolog' => __DIR__.'/vendor/monolog/src',
55
55
));
56
56
```
57
57
58
- For better performance, you can use the APC based version of the universal
59
- class loader:
58
+ For better performance, you can use the APC class loader:
60
59
61
60
``` php
62
- require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader .php';
63
- require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader .php';
61
+ require_once __DIR__.'/src/Symfony/Component/ClassLoader/ClassLoader .php';
62
+ require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcClassLoader .php';
64
63
65
- use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
64
+ use Symfony\Component\ClassLoader\ClassLoader;
65
+ use Symfony\Component\ClassLoader\ApcClassLoader;
66
66
67
- $loader = new ApcUniversalClassLoader('apc.prefix.');
67
+ $loader = new ClassLoader();
68
+ $loader->addPrefix('Symfony', __DIR__.'/src');
69
+
70
+ $loader = new ApcClassLoader('apc.prefix.', $loader);
71
+ $loader->register();
68
72
```
69
73
70
74
Furthermore, the component provides tools to aggregate classes into a single
0 commit comments