4 Applications that use Symfony Flex
5 ----------------------------------
7 Add bundle custom repository to your project's `composer.json` file:
16 "name": "rapsys/packbundle",
17 "version": "dev-master",
20 "url": "https://git.rapsys.eu/packbundle",
25 "Rapsys\\PackBundle\\": ""
35 Then open a command console, enter your project directory and execute:
38 $ composer require rapsys/packbundle dev-master
41 Applications that don't use Symfony Flex
42 ----------------------------------------
44 ### Step 1: Download the Bundle
46 Open a command console, enter your project directory and execute the
47 following command to download the latest stable version of this bundle:
50 $ composer require rapsys/packbundle dev-master
53 This command requires you to have Composer installed globally, as explained
54 in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
55 of the Composer documentation.
57 ### Step 2: Enable the Bundle
59 Then, enable the bundle by adding it to the list of registered bundles
60 in the `app/AppKernel.php` file of your project:
67 class AppKernel extends Kernel
69 public function registerBundles()
73 new Rapsys\PackBundle\RapsysPackBundle(),
83 ### Step 3: Configure the Bundle
85 Verify that you have the configuration file `config/packages/rapsys_pack.yaml`
86 with the following content:
89 #Services configuration
91 #Register assets pack package
93 class: Rapsys\PackBundle\Asset\PathPackage
94 arguments: [ '/', '@assets.empty_version_strategy', '@assets.context' ]
95 #Register twig pack extension
96 rapsys_pack.twig.pack_extension:
97 class: Rapsys\PackBundle\Twig\PackExtension
98 arguments: [ '@file_locator', '@service_container', '@assets.pack_package' ]
99 tags: [ twig.extension ]
102 Open a command console, enter your project directory and execute the
103 following command to see default bundle configuration:
106 $ php bin/console config:dump-reference RapsysPackBundle
109 Open a command console, enter your project directory and execute the
110 following command to see current bundle configuration:
113 $ php bin/console debug:config RapsysPackBundle
116 ### Step 4: Use the twig extension in your Template
118 You can use a template like this to generate your first `rapsys_pack` enabled template:
124 <meta charset="UTF-8" />
125 <title>{% block title %}Welcome!{% endblock %}</title>
126 {% stylesheet '//fonts.googleapis.com/css?family=Irish+Grover|La+Belle+Aurore' '@NamedBundle/Resources/public/css/{reset,screen}.css' '@Short/css/example.css' %}
127 <link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
131 {% block body %}{% endblock %}
132 {% javascript '@Short/js/*.js' %}
133 <script type="text/javascript" src="{{ asset_url }}"></script>
139 ### Step 5: Make sure you have local binary installed
141 You need to have cpack and jpack scripts from https://git.rapsys.eu/packer/ repository
142 set as executable and installed in /usr/local/bin.
144 To install cpack and jpack required packages open a root console and execute the
148 # urpmi perl-base perl-CSS-Packer perl-JavaScript-Packer
151 or stone age distributions:
154 # apt-get install libcss-packer-perl libjavascript-packer-perl
157 or other distributions through cpan:
160 # cpan App::cpanminus
162 # cpanm JavaScript::Packer
165 ### Step 6: Create your own filter
167 You can create you own mypackfilter class which call a mypack binary:
172 namespace Rapsys\PackBundle\Twig\Filter;
174 use Rapsys\PackBundle\Twig\Filter\FilterInterface;
175 use Twig\Error\Error;
177 //This class will be defined in the parameter rapsys_pack.filters.(css|img|js).[x].class string
178 class MyPackFilter implements FilterInterface {
179 //The constructor arguments ... will be replaced defined in the parameter rapsys_pack.filters.(css|img|js).[x].args array
180 public function __construct($fileName, $line, $bin = 'mypack', ...) {
182 $this->fileName = $fileName;
190 //Check argument presence
191 if (!empty($this->...)) {
193 if ($this->... == '...') {
194 $this->bin .= ' ...';
196 //Throw an error on ...
197 throw new Error(sprintf('Got ... for %s: %s', $this->bin, $this->...), $this->line, $this->fileName);
202 //Pass merge of all inputs in content
203 public function process($content) {
205 $descriptorSpec = array(
206 0 => array('pipe', 'r'),
207 1 => array('pipe', 'w'),
208 2 => array('pipe', 'w')
212 if (is_resource($proc = proc_open($this->bin, $descriptorSpec, $pipes))) {
213 //Set stderr as non blocking
214 stream_set_blocking($pipes[2], 0);
216 //Send content to stdin
217 fwrite($pipes[0], $content);
222 //Read content from stdout
223 if ($stdout = stream_get_contents($pipes[1])) {
230 //Read content from stderr
231 if (($stderr = stream_get_contents($pipes[2]))) {
232 throw new Error(sprintf('Got unexpected strerr for %s: %s', $this->bin, $stderr), $this->line, $this->fileName);
239 if (($ret = proc_close($proc))) {
240 throw new Error(sprintf('Got unexpected non zero return code %s: %d', $this->bin, $ret), $this->line, $this->fileName);
250 The class is required to get it's arguments through constructor and have a process method.