pimple/pimple
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
psr/container | 2.0.2 | 3.55 kB | MIT | prod |
Pimple is a light weight and simple Dependency Injection Container for PHP. Its main focus is to manage services and parameters for your PHP applications. Services are represented as global objects that have specific roles within a larger system, such as a database connection, templating engine, or a mailer, and are defined by anonymous functions returning an instance of the object. Parameters, on the other hand, help to customize the configuration of the container in relation to the portfolio and to store global values.
To use Pimple in your PHP project, the first step is to add it to your composer.json
file. This can be done using the following command:
$ ./composer.phar require pimple/pimple "^3.0"
This will install Pimple, providing you access to the Container
class. You create a new Pimple container like so:
use Pimple\Container;
$container = new Container();
You can define a service as follows:
$container['session_storage'] = fn($c) => new SessionStorage('SESSION_ID');
$container['session'] = fn($c) => new Session($c['session_storage']);
To use a service, you can simply fetch it from the container:
$session = $container['session'];
Parameters are defined like so:
$container['cookie_name'] = 'SESSION_ID';
$container['session_storage_class'] = 'SessionStorage';
Pimple also provides the functionality to extend, modify or protect parameters and services as per your specific business requirements.
Pimple’s documentation content can be found on the project’s Github page at https://github.com/silexphp/Pimple.git within the README file. This includes detailed examples and explanations of the core concepts involved in using Pimple, all aimed at helping to get you up and running with Pimple as quickly as possible.