Skip to content

Commit

Permalink
Remove "class_path" option and update README.
Browse files Browse the repository at this point in the history
Changes reflect the need of Composer to download and make this provider
available to applications after the removal of the autoloader service
in recent changes of Silex.
  • Loading branch information
nrk committed Jul 8, 2012
1 parent 2d0a8ad commit a8090eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
40 changes: 15 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
# PredisServiceProvider #

This service provider for the __[Silex](http://silex-project.org)__ microframework enables developers to easily use
__[Predis](http://github.com/nrk/predis)__ in their applications to connect to __[Redis](http://redis.io)__.

__NOTE__: starting from [commit 5a20c1c](http://github.com/fabpot/Silex/commit/5a20c1cc13081f6062bd865c1646b48732e00dba),
the developers behind Silex decided to switch from the concept of _extensions_ to the one of _service providers_
and renamed all the interfaces and classes involved by this change. __PredisExtension__ has been renamed to
__PredisServiceProvider__ with the release of __v0.2.0__ to accomodate this change, so if you need to use it
with older versions of Silex you can download the previous __v0.1.0__.
This service provider for the __[Silex](http://silex-project.org)__ microframework enables developers to easily
use __[Predis](http://github.com/nrk/predis)__ in their applications to connect to __[Redis](http://redis.io)__.


## Getting started ##

Starting to use this service provider is quite easy. Supposing that you already have the scheleton of your Silex
application ready, you just need to register the `Predis\Silex` namespace to point to the path of where the source
code of the provider has been placed and then add an instance to the application object:
Using this service provider in your application is easy and requires the use of [Composer](http://packagist.org/about-composer)
to download and set up all the needed dependencies by adding `"predis/service-provider": "0.2.*@stable"` to the
list of `require`d libraries in your `composer.json` file.

After installing, and supposing that you already have the scheleton of your Silex application ready, you just need
to register the service provider with the parameters needed to access the Redis server instance and configure the
underlying Predis client:

``` php
<?php
/* ... */
$app['autoloader']->registerNamespaces(array(
'Predis\Silex' => __DIR__.'/../vendor/PredisServiceProvider/lib',
));

$app->register(new Predis\Silex\PredisServiceProvider(), array(
'predis.class_path' => __DIR__.'/../vendor/Predis/lib',
'predis.parameters' => 'tcp://127.0.0.1:6379/',
'predis.options' => array('profile' => '2.2'),
));
/* ... */
```

The `predis.class_path` option lets you specify where to look for Predis. Both `predis.parameters` and
`predis.options` are optional and they accept the same values of the constructor method of `Predis\Client`.

It is also possible to define multiple clients identified by aliases with their own parameters and options
using `predis.clients`. Each client instance will be initialized lazily upon first access:
Both `predis.parameters` and `predis.options` are actually optional and accept the same values of the constructor
method of `Predis\Client`. It is also possible to define multiple clients identified by aliases with their own
parameters and options using `predis.clients`. Each client instance will be initialized lazily upon first access:

``` php
<?php
/* ... */
$app->register(new Predis\Silex\PredisServiceProvider(), array(
'predis.class_path' => __DIR__.'/../vendor/Predis/lib',
'predis.clients' => array(
'first' => 'tcp://127.0.0.1:6379',
'second' => array(
Expand All @@ -61,13 +51,13 @@ $app->register(new Predis\Silex\PredisServiceProvider(), array(
```

If you are looking for simple but complete examples of how to use this extension you can have a look at the
_examples_ directory that is included in the repository, or the test suite in the _tests_ directory.
_examples_ directory included in the repository or the test suite in the _tests_ directory.


## Testing ##

In order to be able to run the test suite of the provider you must download [Composer](http://packagist.org/about-composer)
in the root of the repository and then install the needed dependencies.
In order to be able to run the test suite of the provider you must run `php composer.phar install` in the root
of the repository to install the needed dependencies.

```bash
$ wget http://getcomposer.org/composer.phar
Expand Down
6 changes: 1 addition & 5 deletions lib/Predis/Silex/PredisServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PredisServiceProvider implements ServiceProviderInterface
{
protected static $reserved = array(
'parameters', 'options', 'default_parameters', 'default_options',
'class_path', 'clients', 'client_initializer',
'clients', 'client_initializer',
);

protected $prefix;
Expand All @@ -49,10 +49,6 @@ public function boot(Application $app)
{
$prefix = $this->prefix;

if (isset($app["$prefix.class_path"])) {
$app['autoloader']->registerNamespace('Predis', $app["$prefix.class_path"]);
}

if (!isset($app["$prefix.default_parameters"])) {
$app["$prefix.default_parameters"] = array();
}
Expand Down
1 change: 0 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
*/

require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../lib/Predis/Silex/PredisServiceProvider.php';

0 comments on commit a8090eb

Please sign in to comment.