Download the PHP package electrolinux/silex-capsule without Composer
On this page you can find all versions of the php package electrolinux/silex-capsule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download electrolinux/silex-capsule
More information about electrolinux/silex-capsule
Files in electrolinux/silex-capsule
Package silex-capsule
Short Description A Laravel Eloquent ORM/Capsule service provider for Silex 2
License MIT
Informations about the package silex-capsule
Silex Capsule Service Provider
This is a service provider for the Silex Micro Framework that integrates Laravel's Eloquent ORM via Capsule, its standalone wrapper implementation.
Requirements
In order to use the service provider you'll need to be running PHP 5.4+
Installation
The best way to install the service provider is using Composer:
`
Alternatively, you can add it directly to your composer.json
file:
`
Basic Usage
To use it in your application just register the service provider with Silex:
``
For more information about the available options you should refer to the Capsule documentation.
Once you've registered the service provider a Capsule object will be created and Eloquent booted up before any of your route controllers are called. If you're interested in the technical aspects, Capsule is registered as before
middleware with Silex using Application::EARLY_EVENT
, so it'll only ever be made available once your application is run and before anything else happens.
If you need Capsule and Eloquent to be booted up before your application is run ($app->run()
), for example in a Symfony Console command, you just need to access its array element within the dependency injection container:
``
Capsule will be made available globally by default, allowing you to write queries directly in your controllers should you wish:
``
If you don't want Capsule to be booted then set the capsule.global
setting to false
. If you don't plan to use Eloquent to build models then you can also prevent it from being booted by setting capsule.eloquent
to false
.
Creating Eloquent models is identical to how you would create them in Laravel:
``
Then you can use it, and all of its features, in your controllers just like you would in Laravel:
``
Advanced Usage
You can setup multiple connections and even caching with the service provider; simply use the capsule.connections
option:
``
If you've enabled query logging on your connection you can retrieve it through Capsule:
``
You can toggling query logging on a per-connection basis using the logging
option in your connection credentials.
You can also use Eloquent's schema building tools to build migrations:
``
By default the service provider installs the Laravel Events package, so you can also use model observers:
``
Capsule Options Example
The following is a full example of all the available options that you can pass to the service provider:
``
Testing
There are some basic tests to ensure that the Capsule object is correctly registered with Silex. You can run them using PHPUnit, and you'll also need SQLite as the tests use a simple in-memory database.
If you make a pull request please ensure you add the accompanying tests.
All versions of silex-capsule with dependencies
silex/silex Version ~2.0
pimple/pimple Version ~3.0
illuminate/database Version ~5.0
illuminate/events Version ~5.0