4
4
Autoloader
5
5
==========
6
6
7
- Whenever you use an undefined class, PHP uses the autoloading mechanism to
8
- delegate the loading of a file defining the class. Symfony2 provides a
9
- "universal" autoloader, which is able to load classes from files that
10
- implement one of the following conventions :
7
+ Sempre que você usa uma classe indefinida, o PHP usa o mecanismo de autoloading para
8
+ delegar o carregamento de um arquivo que defina a classe. O Symfony2 fornece um
9
+ autoloader "universal", que é capaz de carregar as classes de arquivos que implementem
10
+ uma das seguintes convenções :
11
11
12
- * The technical interoperability ` standards `_ for PHP 5.3 namespaces and class
12
+ * As ` normas `_ técnicas de interoperabilidade para os namespaces e classes do PHP 5.3
13
13
names;
14
14
15
- * The `PEAR `_ naming convention for classes.
15
+ * A nomeação conforme a convenção do `PEAR `_ para classes.
16
16
17
- If your classes and the third-party libraries you use for your project follow
18
- these standards, the Symfony2 autoloader is the only autoloader you will ever
19
- need.
17
+ Se suas classes e as bibliotecas de terceiros que você usa no seu projeto seguem
18
+ essas normas, o autoloader do Symfony2 será o único autoloader que você irá
19
+ precisar
20
20
21
- Usage
22
- -----
21
+ Uso
22
+ ---
23
23
24
- Registering the autoloader is straightforward ::
24
+ Registrar o autoloader é simples ::
25
25
26
26
require_once '/path/to/src/Symfony/Foundation/UniversalClassLoader.php';
27
27
@@ -30,14 +30,15 @@ Registering the autoloader is straightforward::
30
30
$loader = new UniversalClassLoader();
31
31
$loader->register();
32
32
33
- The autoloader is useful only if you add some libraries to autoload.
33
+ O autoloader é útil apenas se você que adicionar algumas bibliotecas para carregarem
34
+ automaticamente.
34
35
35
36
.. note ::
36
- The autoloader is automatically registered in a Symfony2 application (see
37
+ O autoloader é automaticamente registrado em uma aplicação do Symfony2 (veja
37
38
``src/autoload.php ``).
38
39
39
- If the classes to autoload use namespaces, use the `` registerNamespace() `` or
40
- ``registerNamespaces() `` methods ::
40
+ Se as classes a serem carregadas automaticamente usam namespaces, use o método
41
+ ``registerNamespace() `` ou `` registerNamespaces() `` ::
41
42
42
43
$loader->registerNamespace('Symfony', __DIR__.'/vendor/symfony/src');
43
44
@@ -46,8 +47,8 @@ If the classes to autoload use namespaces, use the ``registerNamespace()`` or
46
47
'Zend' => __DIR__.'/vendor/zend/library',
47
48
));
48
49
49
- For classes that follow the PEAR naming convention , use the ``registerPrefix ``
50
- or ``registerPrefixes `` methods ::
50
+ Para classes que seguem a nomeclatura padrão do PEAR , use o método ``registerPrefix ``
51
+ ou ``registerPrefixes `` ::
51
52
52
53
$loader->registerPrefix('Twig_', __DIR__.'/vendor/twig/lib');
53
54
@@ -57,12 +58,12 @@ or ``registerPrefixes`` methods::
57
58
));
58
59
59
60
.. note ::
60
- Some libraries also need that their root path be registered in the PHP include
61
- path (``set_include_path() ``).
61
+ Algumas bibliotecas também precisam que o caminho da raiz seja registrado no include path do
62
+ PHP (``set_include_path() ``).
62
63
63
- Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be looked
64
- for in a list of locations to ease the vendoring of a sub-set of classes for
65
- large projects ::
64
+ Classes de um sub-namespace ou de uma sub-hierarquia de classes PEAR poden ser procuradas
65
+ em uma lista de locais para facilitar o agrupamento de um sub-conjunto de classes para
66
+ grandes projetos ::
66
67
67
68
$loader->registerNamespaces(array(
68
69
'Doctrine\Common' => __DIR__.'/vendor/doctrine/lib/vendor/doctrine-common/lib',
@@ -71,11 +72,11 @@ large projects::
71
72
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
72
73
));
73
74
74
- In this example, if you try to use a class in the ``Doctrine\Common `` namespace
75
- or one of its children, the autoloader will first look for the class under the
76
- ``doctrine-common `` directory, and it will then fallback to the default
77
- ``Doctrine `` directory (the last one configured) if not found, before giving up .
78
- The order of the registrations is significant in this case.
75
+ Neste exemplo, se você tentar usar a classe no namespace ``Doctrine\Common ``
76
+ ou em um dos seus filhos, o autoloader vai procurar primeiro pela classe no
77
+ diretório ``doctrine-common ``, e vai procurar no diretório padrão
78
+ ``Doctrine `` (o último configurado) se não encontrar, antes de desistir .
79
+ A ordem dos registros é importante neste caso.
79
80
80
- .. _ standards : http://groups.google.com/group/php-standards/web/psr-0-final-proposal
81
+ .. _ normas : http://groups.google.com/group/php-standards/web/psr-0-final-proposal
81
82
.. _PEAR : http://pear.php.net/manual/en/standards.php
0 commit comments