Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
1a23e6c9
Commit
1a23e6c9
authored
May 20, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed the autoloader service (use composer instead, closes #205, closes #176)
parent
6dcb2587
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
24 additions
and
157 deletions
+24
-157
doc/changelog.rst
doc/changelog.rst
+4
-0
doc/cookbook/translating_validation_messages.rst
doc/cookbook/translating_validation_messages.rst
+0
-1
doc/providers.rst
doc/providers.rst
+0
-54
doc/providers/doctrine.rst
doc/providers/doctrine.rst
+0
-10
doc/providers/monolog.rst
doc/providers/monolog.rst
+1
-5
doc/providers/swiftmailer.rst
doc/providers/swiftmailer.rst
+1
-6
doc/providers/symfony_bridges.rst
doc/providers/symfony_bridges.rst
+2
-5
doc/providers/translation.rst
doc/providers/translation.rst
+13
-13
doc/providers/twig.rst
doc/providers/twig.rst
+1
-5
doc/providers/validator.rst
doc/providers/validator.rst
+2
-5
doc/services.rst
doc/services.rst
+0
-13
src/Silex/Application.php
src/Silex/Application.php
+0
-8
src/Silex/Provider/DoctrineServiceProvider.php
src/Silex/Provider/DoctrineServiceProvider.php
+0
-8
src/Silex/Provider/FormServiceProvider.php
src/Silex/Provider/FormServiceProvider.php
+0
-4
src/Silex/Provider/MonologServiceProvider.php
src/Silex/Provider/MonologServiceProvider.php
+0
-4
src/Silex/Provider/SymfonyBridgesServiceProvider.php
src/Silex/Provider/SymfonyBridgesServiceProvider.php
+0
-4
src/Silex/Provider/TranslationServiceProvider.php
src/Silex/Provider/TranslationServiceProvider.php
+0
-4
src/Silex/Provider/TwigServiceProvider.php
src/Silex/Provider/TwigServiceProvider.php
+0
-4
src/Silex/Provider/ValidatorServiceProvider.php
src/Silex/Provider/ValidatorServiceProvider.php
+0
-4
No files found.
doc/changelog.rst
View file @
1a23e6c9
...
...
@@ -3,6 +3,10 @@ Changelog
This changelog references all backward incompatibilities as we introduce them:
* **2012-05-24**: Removed the ``autoloader`` service (use composer instead).
The ``*.class_path`` settings on all the built-in providers have also been
removed in favor of Composer.
* **2012-05-21**: Changed error() to allow handling specific exceptions.
* **2012-05-20**: Added a way to define settings on a controller collection.
...
...
doc/cookbook/translating_validation_messages.rst
View file @
1a23e6c9
...
...
@@ -9,7 +9,6 @@ In order to do that, you will need to register translator and point to translate
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
'locale' => 'sr_Latn',
'translation.class_path' => __DIR__ . '/vendor/symfony/src',
'translator.messages' => array()
));
$app->before(function () use ($app) {
...
...
doc/providers.rst
View file @
1a23e6c9
...
...
@@ -34,15 +34,6 @@ Conventions
You need to watch out in what order you do certain things when
interacting with providers. Just keep to these rules:
* Class paths (for the autoloader) must be defined **before**
the provider is registered. Passing it as a second argument
to ``Application::register`` qualifies too, because it sets
the passed parameters first.
*Reason: The provider will set up the autoloader at
provider register time. If the class path is not set
at that point, no autoloader can be registered.*
* Overriding existing services must occur **after** the
provider is registered.
...
...
@@ -138,51 +129,6 @@ You can now use this provider as follows::
In this example we are getting the ``name`` parameter from the
query string, so the request path would have to be ``/hello?name=Fabien``.
Class loading
~~~~~~~~~~~~~
Providers are great for tying in external libraries as you
can see by looking at the ``MonologServiceProvider`` and
``TwigServiceProvider``. If the library is decent and follows the
`PSR-0 Naming Standard <http://groups.google.com/group/php-standards/web/psr-0-final-proposal>`_
or the PEAR Naming Convention, it is possible to autoload
classes using the ``UniversalClassLoader``.
As described in the *Services* chapter, there is an
*autoloader* service which can be used for this.
Here is an example of how to use it (based on `Buzz <https://github.com/kriswallsmith/Buzz>`_)::
namespace Acme;
use Silex\Application;
use Silex\ServiceProviderInterface;
class BuzzServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$app['buzz'] = $app->share(function () { ... });
if (isset($app['buzz.class_path'])) {
$app['autoloader']->registerNamespace('Buzz', $app['buzz.class_path']);
}
}
}
This allows you to simply provide the class path as an
option when registering the provider::
$app->register(new BuzzServiceProvider(), array(
'buzz.class_path' => __DIR__.'/vendor/buzz/lib',
));
.. note::
For libraries that do not use PHP 5.3 namespaces you can use ``registerPrefix``
instead of ``registerNamespace``, which will use an underscore as directory
delimiter.
Controllers providers
---------------------
...
...
doc/providers/doctrine.rst
View file @
1a23e6c9
...
...
@@ -35,12 +35,6 @@ Parameters
These and additional options are described in detail in the `Doctrine DBAL
configuration documentation <http://www.doctrine-project.org/docs/dbal/2.0/en/reference/configuration.html>`_.
* **db.dbal.class_path** (optional): Path to where the
Doctrine DBAL is located.
* **db.common.class_path** (optional): Path to where
Doctrine Common is located.
Services
--------
...
...
@@ -63,8 +57,6 @@ and *Doctrine Common* in ``vendor/doctrine-common``::
'driver' => 'pdo_sqlite',
'path' => __DIR__.'/app.db',
),
'db.dbal.class_path' => __DIR__.'/vendor/doctrine-dbal/lib',
'db.common.class_path' => __DIR__.'/vendor/doctrine-common/lib',
));
Usage
...
...
@@ -106,8 +98,6 @@ and values are options::
'password' => 'my_password',
),
),
'db.dbal.class_path' => __DIR__.'/vendor/doctrine-dbal/lib',
'db.common.class_path' => __DIR__.'/vendor/doctrine-common/lib',
));
The first registered connection is the default and can simply be accessed as
...
...
doc/providers/monolog.rst
View file @
1a23e6c9
...
...
@@ -15,9 +15,6 @@ Parameters
* **monolog.logfile**: File where logs are written to.
* **monolog.class_path** (optional): Path to where the
Monolog library is located.
* **monolog.level** (optional): Level of logging defaults
to ``DEBUG``. Must be one of ``Logger::DEBUG``, ``Logger::INFO``,
``Logger::WARNING``, ``Logger::ERROR``. ``DEBUG`` will log
...
...
@@ -47,8 +44,7 @@ Make sure you place a copy of *Monolog* in the ``vendor/monolog``
directory::
$app->register(new Silex\Provider\MonologServiceProvider(), array(
'monolog.logfile' => __DIR__.'/development.log',
'monolog.class_path' => __DIR__.'/vendor/monolog/src',
'monolog.logfile' => __DIR__.'/development.log',
));
.. note::
...
...
doc/providers/swiftmailer.rst
View file @
1a23e6c9
...
...
@@ -23,9 +23,6 @@ Parameters
* **encryption**: SMTP encryption, defaults to null.
* **auth_mode**: SMTP authentication mode, defaults to null.
* **swiftmailer.class_path** (optional): Path to where the
Swift Mailer library is located.
Services
--------
...
...
@@ -60,9 +57,7 @@ directory. Make sure you point the class path to ``/lib/classes``.
::
$app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
'swiftmailer.class_path' => __DIR__.'/vendor/swiftmailer/lib/classes',
));
$app->register(new Silex\Provider\SwiftmailerServiceProvider());
.. note::
...
...
doc/providers/symfony_bridges.rst
View file @
1a23e6c9
...
...
@@ -7,8 +7,7 @@ Symfony2 components and libraries.
Parameters
----------
* **symfony_bridges.class_path** (optional): Path to where
the Symfony2 Bridges are located.
none
Twig
----
...
...
@@ -41,6 +40,4 @@ Make sure you place a copy of the Symfony2 Bridges in either
Then, register the provider via::
$app->register(new Silex\Provider\SymfonyBridgesServiceProvider(), array(
'symfony_bridges.class_path' => __DIR__.'/vendor/symfony/src',
));
$app->register(new Silex\Provider\SymfonyBridgesServiceProvider());
doc/providers/translation.rst
View file @
1a23e6c9
...
...
@@ -16,9 +16,6 @@ Parameters
* **locale_fallback** (optional): Fallback locale for the translator. It will
be used when the current locale has no messages set.
* **translation.class_path** (optional): Path to where
the Symfony2 Translation component is located.
Services
--------
...
...
@@ -41,8 +38,7 @@ Make sure you place a copy of the Symfony2 Translation component in
``vendor/symfony/src``. You can simply clone the whole Symfony2 into vendor::
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
'locale_fallback' => 'en',
'translation.class_path' => __DIR__.'/vendor/symfony/src',
'locale_fallback' => 'en',
));
Usage
...
...
@@ -95,11 +91,15 @@ YAML-based language files
Having your translations in PHP files can be inconvenient. This recipe will
show you how to load translations from external YAML files.
First you will need the ``Config`` and ``Yaml`` components from Symfony2. Also
make sure you register them with the autoloader. You can just clone the entire
Symfony2 repository into ``vendor/symfony``::
First, add the Symfony2 ``Config`` and ``Yaml`` components in your composer
file:
.. code-block:: json
$app['autoloader']->registerNamespace('Symfony', __DIR__.'/vendor/symfony/src');
"require": {
"symfony/config": "2.1.*",
"symfony/yaml": "2.1.*",
}
Next, you have to create the language mappings in YAML files. A naming you can
use is ``locales/en.yml``. Just do the mapping in this file as follows:
...
...
@@ -132,11 +132,11 @@ That's all you need to load translations from YAML files.
XLIFF-based language files
~~~~~~~~~~~~~~~~~~~~~~~~~~
Just as you would do with YAML translation files, you first need to make
sure you have the ``Config`` component from Symfony2, and that it is
registered with the autoloader. See above for details.
Just as you would do with YAML translation files, you first need to add the
Symfony2 ``Config`` component as a dependency (see above for details).
Then, similarly, create XLIFF files in your locales directory and setup the ``translator.messages`` to map to them.
Then, similarly, create XLIFF files in your locales directory and setup the
``translator.messages`` to map to them.
Finally override the ``translator.loader`` to use a ``XliffFileLoader``::
...
...
doc/providers/twig.rst
View file @
1a23e6c9
...
...
@@ -16,9 +16,6 @@ Parameters
* **twig.options** (optional): An associative array of twig
options. Check out the twig documentation for more information.
* **twig.class_path** (optional): Path to where the Twig
library is located.
* **twig.form.templates** (optional): An array of templates used to render
forms (only available when the ``FormServiceProvider`` is enabled).
...
...
@@ -43,8 +40,7 @@ Make sure you place a copy of *Twig* in the ``vendor/twig``
directory::
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/views',
'twig.class_path' => __DIR__.'/vendor/twig/lib',
'twig.path' => __DIR__.'/views',
));
.. note::
...
...
doc/providers/validator.rst
View file @
1a23e6c9
...
...
@@ -8,8 +8,7 @@ standalone.
Parameters
----------
* **validator.class_path** (optional): Path to where
the Symfony2 Validator component is located.
none
Services
--------
...
...
@@ -35,9 +34,7 @@ Registering
Make sure you place a copy of the Symfony2 Validator component in
``vendor/symfony/src``. You can simply clone the whole Symfony2 into vendor::
$app->register(new Silex\Provider\ValidatorServiceProvider(), array(
'validator.class_path' => __DIR__.'/vendor/symfony/src',
));
$app->register(new Silex\Provider\ValidatorServiceProvider());
Usage
-----
...
...
doc/services.rst
View file @
1a23e6c9
...
...
@@ -195,19 +195,6 @@ of them.
This is only available when a request is being served, you can only access it
from within a controller, before filter, after filter or error handler.
* **autoloader**: This service provides you with a
`UniversalClassLoader
<http://api.symfony.com/master/Symfony/Component/ClassLoader/UniversalClassLoader.html>`_
that is already registered. You can register prefixes
and namespaces on it.
Example usage, autoloads Twig classes::
$app['autoloader']->registerPrefix('Twig_', $app['twig.class_path']);
For more information, check out the `Symfony2 autoloader documentation
<http://symfony.com/doc/current/components/class_loader.html>`_.
* **routes**: The `RouteCollection
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
that is used internally. You can add, modify, read
...
...
src/Silex/Application.php
View file @
1a23e6c9
...
...
@@ -36,7 +36,6 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
use
Symfony\Component\Routing\RouteCollection
;
use
Symfony\Component\Routing\RequestContext
;
use
Symfony\Component\ClassLoader\UniversalClassLoader
;
use
Silex\RedirectableUrlMatcher
;
use
Silex\ControllerResolver
;
...
...
@@ -56,13 +55,6 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
{
$app
=
$this
;
$this
[
'autoloader'
]
=
$this
->
share
(
function
()
{
$loader
=
new
UniversalClassLoader
();
$loader
->
register
();
return
$loader
;
});
$this
[
'routes'
]
=
$this
->
share
(
function
()
{
return
new
RouteCollection
();
});
...
...
src/Silex/Provider/DoctrineServiceProvider.php
View file @
1a23e6c9
...
...
@@ -118,13 +118,5 @@ class DoctrineServiceProvider implements ServiceProviderInterface
return
$dbs
[
$app
[
'dbs.default'
]];
});
if
(
isset
(
$app
[
'db.dbal.class_path'
]))
{
$app
[
'autoloader'
]
->
registerNamespace
(
'Doctrine\\DBAL'
,
$app
[
'db.dbal.class_path'
]);
}
if
(
isset
(
$app
[
'db.common.class_path'
]))
{
$app
[
'autoloader'
]
->
registerNamespace
(
'Doctrine\\Common'
,
$app
[
'db.common.class_path'
]);
}
}
}
src/Silex/Provider/FormServiceProvider.php
View file @
1a23e6c9
...
...
@@ -51,9 +51,5 @@ class FormServiceProvider implements ServiceProviderInterface
return
new
DefaultCsrfProvider
(
$app
[
'form.secret'
]);
});
if
(
isset
(
$app
[
'form.class_path'
]))
{
$app
[
'autoloader'
]
->
registerNamespace
(
'Symfony\\Component\\Form'
,
$app
[
'form.class_path'
]);
}
}
}
src/Silex/Provider/MonologServiceProvider.php
View file @
1a23e6c9
...
...
@@ -51,10 +51,6 @@ class MonologServiceProvider implements ServiceProviderInterface
};
}
if
(
isset
(
$app
[
'monolog.class_path'
]))
{
$app
[
'autoloader'
]
->
registerNamespace
(
'Monolog'
,
$app
[
'monolog.class_path'
]);
}
$app
->
before
(
function
(
Request
$request
)
use
(
$app
)
{
$app
[
'monolog'
]
->
addInfo
(
'> '
.
$request
->
getMethod
()
.
' '
.
$request
->
getRequestUri
());
});
...
...
src/Silex/Provider/SymfonyBridgesServiceProvider.php
View file @
1a23e6c9
...
...
@@ -24,9 +24,5 @@ class SymfonyBridgesServiceProvider implements ServiceProviderInterface
public
function
register
(
Application
$app
)
{
$app
[
'symfony_bridges'
]
=
true
;
if
(
isset
(
$app
[
'symfony_bridges.class_path'
]))
{
$app
[
'autoloader'
]
->
registerNamespace
(
'Symfony\\Bridge'
,
$app
[
'symfony_bridges.class_path'
]);
}
}
}
src/Silex/Provider/TranslationServiceProvider.php
View file @
1a23e6c9
...
...
@@ -49,9 +49,5 @@ class TranslationServiceProvider implements ServiceProviderInterface
$app
[
'translator.message_selector'
]
=
$app
->
share
(
function
()
{
return
new
MessageSelector
();
});
if
(
isset
(
$app
[
'translation.class_path'
]))
{
$app
[
'autoloader'
]
->
registerNamespace
(
'Symfony\\Component\\Translation'
,
$app
[
'translation.class_path'
]);
}
}
}
src/Silex/Provider/TwigServiceProvider.php
View file @
1a23e6c9
...
...
@@ -85,9 +85,5 @@ class TwigServiceProvider implements ServiceProviderInterface
$app
[
'twig.loader.array'
],
));
});
if
(
isset
(
$app
[
'twig.class_path'
]))
{
$app
[
'autoloader'
]
->
registerPrefix
(
'Twig_'
,
$app
[
'twig.class_path'
]);
}
}
}
src/Silex/Provider/ValidatorServiceProvider.php
View file @
1a23e6c9
...
...
@@ -42,9 +42,5 @@ class ValidatorServiceProvider implements ServiceProviderInterface
$app
[
'validator.validator_factory'
]
=
$app
->
share
(
function
()
{
return
new
ConstraintValidatorFactory
();
});
if
(
isset
(
$app
[
'validator.class_path'
]))
{
$app
[
'autoloader'
]
->
registerNamespace
(
'Symfony\\Component\\Validator'
,
$app
[
'validator.class_path'
]);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment