silex-pack
Add bundle like system to Silex 2.x, (*1)
There is a demo project !, (*2)
What ?
Silex Pack add some code structuring in your Silex project. It mimics the Symfony Bundle feature., (*3)
mountable pack
Packs can provides controllers and prefix where to mount., (*4)
Implement Quazardous\Silex\Api\MountablePackInterface
, (*5)
twiggable pack
Packs can define private Twig templates folder with override capability from the application templates folder., (*6)
Implement Quazardous\Silex\Api\TwiggablePackInterface
, (*7)
For a pack class AcmeDemoPack
Silex pack will register a @AcmeDemo
namespace with Twig. @AcmeDemo
is created from PackInterface::getName()
., (*8)
Now you can use something like that in your controllers:, (*9)
...
return $app->renderView('@AcmeDemo/default/hello.html.twig', $vars);
...
Within .twig
templates, you can also use @AcmeDemo
, ie for extends
clause:, (*10)
{% extends '@AcmeDemo/base.html.twig' %}
...
If you register twig.path
, Silex Pack will look for overriden templates in these folders., (*11)
...
$app->register(new TwigServiceProvider(), ['twig.path' => '/path/to/app/views']);
...
For @AcmeDemo/default/hello.html.twig
we will look for in /path/to/app/views/AcmeDemo/default/hello.html.twig
. Cute no ?, (*12)
entitable pack
Packs can expose entites to Doctrine ORM., (*13)
Implement Quazardous\Silex\Api\EntitablePackInterface
, (*14)
consolable pack
Packs can add commands to the console., (*15)
Implement Quazardous\Silex\Api\ConsolablePackInterface
, (*16)
configurable pack
Packs can have config files. All the config files will be injected into the application container., (*17)
Implement Quazardous\Silex\Api\ConfigurablePackInterface
, (*18)
assetable pack
Packs can have assets., (*19)
Implement Quazardous\Silex\Api\AssetablePackInterface
, (*20)
...
{% stylesheets '@AcmeDemo/css/*.css' output="css/acme_demo.css" %}
<link href="{{ asset(asset_url) }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
...
You have to register the provided Assetic service provider because we have to inject a "namespace aware" assetic factory., (*21)
The provided assetic.factory
knows how to handle paths with @AcmeDemo
prefix., (*22)
@AcmeDemo
is derived from PackInterface::getName()
., (*23)
See Quazardous\Silex\Provider\AsseticServiceProvider
, (*24)
The assets dump is done in the standard $app['assetic.path_to_web']
., (*25)
See Silex Assetic from more info on this provider., (*26)
translatable pack
Packs can have translations., (*27)
Implement Quazardous\Silex\Api\TranslatablePackInterface
, (*28)
You can provide yaml files, xliff files or php files (returning a key => translation array)., (*29)
linkable pack
You can create symlinks between project and pack (ie. for public files)., (*30)
Implement Quazardous\Silex\Api\LinkablePackInterface
, (*31)
You'll have to execute the provided command pack:symlinks
., (*32)
optionnable pack
You can inject common options into your pack., (*33)
Implement Quazardous\Silex\Api\OptionnablePackInterface
, (*34)
...
$app->register(new AcmeDemoPack(), [
'acme_demo.mount_prefix' => '/acme/demo',
'acme_demo.entity_subnamespace' => 'Model',
]);
...
See below., (*35)
Usage
Install
composer require quazardous/silex-pack
Use Quazardous\Silex\PackableApplication
instead of Silex\Application
., (*36)
Implements the interfaces you need and register your pack as a classic service provider., (*37)
...
$app = new Quazardous\Silex\PackableApplication;
...
use Acme\DemoPack\AcmeDemoPack;
$app->register(new AcmeDemoPack());
...
Enjoy (or not) !, (*38)
Jet pack
Silex Pack provides a basic dropin trait implementation for the trivial functions:, (*39)
Use Quazardous\Silex\Pack\JetPackTrait
, (*40)
And a all in one interface:, (*41)
Implement Quazardous\Silex\Pack\JetPackInterface
, (*42)
So with JetPackInterface
+ JetPackTrait
you should just have to provide some options:, (*43)
...
$app->register(new AcmeDemoPack(), [
'acme_demo.mount_prefix' => '/acme/demo',
'entity_subnamespace' => 'Model',
]);
...
The user pack namespace acme_demo.
is derived from PackInterface::getName()
wich result is decamelize., (*44)
See JetPackTrait::$packOptions
for a list of all options., (*45)
NB: you will need to manualy add all the suggested dependencies (see the demo project for a typical composer.json)., (*46)
Commands
Silex pack uses Sillex Console., (*47)
Silex pack provides assetic commands:, (*48)
-
assetic:dump
: dumps the assets
-
assetic:watch
: watches the assets and dumps if modifications
Register Quazardous\Silex\Provider\AsseticCommandsProvider
, (*49)
Silex pack provides pack commands:, (*50)
-
pack:symlinks
: create pack symlinks
Register Quazardous\Silex\Provider\PackCommandsProvider
, (*51)
Pack folders
A pack has no strict structure but it could/should be very similar to bundle:, (*52)
+-- Acme/ :
| +-- AlphaPack/
| | +-- AcmeAlphaPack.php
| | +-- Command/
| | +-- Controller/
| | +-- Entity/
| | +-- assets/
| | +-- configs/
| | +-- fixtures/
| | +-- locales/
| | +-- public/
| | +-- views/
| |
| +-- BetaPack/
|
Demo
See a full working demo., (*53)
You can use it as a quick bootstrap for your project., (*54)
Features Silex User Pack (see below)., (*55)
Some pack projects