<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Silex | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/category/php/silex/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Fri, 12 Feb 2016 08:06:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Superleansilexplate Update v3</title>
		<link>https://nerdpress.org/2016/02/11/superleansilexplate-update-v3/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Thu, 11 Feb 2016 17:15:52 +0000</pubDate>
				<category><![CDATA[Silex]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[silex]]></category>
		<category><![CDATA[superleansilexplate]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2667</guid>

					<description><![CDATA[<p>Some news from the Superleansilexplate: v3 now uses symfony3 components Silex 1.3 supports symfony3 so lets use it :) Note: as symfony3 doesnt support php5.4 anymore, we dont either! new ConsoleServiceProvider the one from knplabs that was used before seems to be unmaintained and wasnt matching the dependencies anymore. So i decided to take it &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2016/02/11/superleansilexplate-update-v3/" class="more-link">Continue reading<span class="screen-reader-text"> "Superleansilexplate Update v3"</span></a></p>
The post <a href="https://nerdpress.org/2016/02/11/superleansilexplate-update-v3/">Superleansilexplate Update v3</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Some news from the <a href="https://github.com/ivoba/superleansilexplate" target="_blank">Superleansilexplate</a>:</p>
<ul>
<li>v3 now uses symfony3 components<br />
  Silex 1.3 supports symfony3 so lets use it :)<br />
  Note: as symfony3 doesnt support php5.4 anymore, we dont either!</li>
<li>new <a href="https://github.com/ivoba/console-service-provider" target="_blank">ConsoleServiceProvider</a><br />
  the one from <a href="https://github.com/KnpLabs/ConsoleServiceProvider" target="_blank">knplabs</a> that was used before seems to be unmaintained and wasnt matching the dependencies anymore.<br />
  So i decided to take it over and renew it a bit. Check it out!</li>
<li>Docker support<br />
  I started to use Docker as dev enviroment for my projects, so i added dev &#038; prod Docker support.<br />
  For the sake of simplicity it uses a single container with Apache and PHP7.<br />
  If you have Docker and docker-compose on your machine just spin it up with <code>docker-compose up</code> and check on localhost:8088.</li>
</ul>
<p><span id="more-2667"></span></p>
<p>As a quick outview:<br />
we are all waiting for Silex2, but development seems to stagnate there.<br />
Hopefully it will pace up again.<br />
But with the rise of other MicroFrameworks like <a href="https://lumen.laravel.com/" target="_blank">Lumen</a> or the <a href="http://symfony.com/blog/new-in-symfony-2-8-symfony-as-a-microframework" target="_blank">symfony MicroKernel</a>, things went all a bit quiet around Silex.<br />
As i use symfony quite a lot i personally tend to symfony MicroKernel these days.<br />
Check out this <a href="https://www.symfony.fi/entry/symfony-benchmarks-microkernel-silex-lumen-and-slim" target="_blank">blogpost</a> for a benchmark of the microframeworks. </p>The post <a href="https://nerdpress.org/2016/02/11/superleansilexplate-update-v3/">Superleansilexplate Update v3</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Enable Twig-Extensions in Silex revisited</title>
		<link>https://nerdpress.org/2014/05/05/enable-twig-extensions-silex-revisited/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 05 May 2014 16:20:51 +0000</pubDate>
				<category><![CDATA[Silex]]></category>
		<category><![CDATA[Twig]]></category>
		<category><![CDATA[silex]]></category>
		<category><![CDATA[Twig Extension]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2545</guid>

					<description><![CDATA[<p>As of 2014 things have changed improved a lot in the Symfony / Silex world, compared to 2011, when i first blogged about twig extensions in Silex. Things got more easy, yay! As Composer appeared, installation and autoloading is a breeze nowadays. I presume here, that you have installed your Silex project via composer. If &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2014/05/05/enable-twig-extensions-silex-revisited/" class="more-link">Continue reading<span class="screen-reader-text"> "Enable Twig-Extensions in Silex revisited"</span></a></p>
The post <a href="https://nerdpress.org/2014/05/05/enable-twig-extensions-silex-revisited/">Enable Twig-Extensions in Silex revisited</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>As of 2014 things have <del datetime="2014-05-05T16:12:03+00:00">changed</del> improved a lot in the Symfony / Silex world, compared to 2011, when <a href="https://nerdpress.org/2011/11/21/enable-twig-extensions-in-silex/">i first blogged about twig extensions in Silex</a>.<br />
Things got more easy, yay!</p>
<p>As Composer appeared, installation and autoloading is a breeze nowadays.<br />
I presume here, that you have installed your Silex project via composer.<br />
If so, you can install the twig extensions like this:<br />
<span id="more-2545"></span><br />
Just go to your project folder and run:</p>
<pre class="brush: plain; title: ; notranslate">composer require twig/extensions:~1.0</pre>
<p>and your done with installation and autoloading.</p>
<p>Now to integration and service registration, this also got more easy.</p>
<p>Place this after you have registered the twig service:</p>
<pre class="brush: php; title: ; notranslate">$app&#x5B;'twig'] = $app-&gt;share($app-&gt;extend('twig', function($twig, $app) {
    $twig-&gt;addExtension(new Twig_Extensions_Extension_Text($app));
    return $twig;
}));</pre>
<p>Thats it, now you can use the text filters in your twig templates:</p>
<pre class="brush: plain; title: ; notranslate">
{{ post.content|truncate(200)|raw }}</pre>
<p>Easy&#8230;</p>The post <a href="https://nerdpress.org/2014/05/05/enable-twig-extensions-silex-revisited/">Enable Twig-Extensions in Silex revisited</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[Symfony 2][Assetic] Sass, CompassFilter + Foundation Responsive Front-end Framework</title>
		<link>https://nerdpress.org/2012/10/26/symfony-2assetic-sass-compassfilter-foundation-responsive-front-end-framework/</link>
					<comments>https://nerdpress.org/2012/10/26/symfony-2assetic-sass-compassfilter-foundation-responsive-front-end-framework/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 26 Oct 2012 15:32:56 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Silex]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Tools]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2323</guid>

					<description><![CDATA[<p>Did you ever wonder how to enable 3rd party plugins (or so called &#8220;frameworks&#8220;) within the great compass toolset managed by assetic in your edgy symfony 2.1 project? (If there is more extensive documentation available concerning assetic + CompassFilter, please stop reading on and let me know!) If you take a look at the filter &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/10/26/symfony-2assetic-sass-compassfilter-foundation-responsive-front-end-framework/" class="more-link">Continue reading<span class="screen-reader-text"> "[Symfony 2][Assetic] Sass, CompassFilter + Foundation Responsive Front-end Framework"</span></a></p>
The post <a href="https://nerdpress.org/2012/10/26/symfony-2assetic-sass-compassfilter-foundation-responsive-front-end-framework/">[Symfony 2][Assetic] Sass, CompassFilter + Foundation Responsive Front-end Framework</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Did you ever wonder how to enable 3rd <a href="http://compass-style.org/frameworks/">party</a> plugins (or so called &#8220;<a href="http://compass-style.org/frameworks/">frameworks</a>&#8220;) within the great <a href="http://compass-style.org/">compass toolset</a> managed by <a href="https://github.com/kriswallsmith/assetic">assetic</a> in your edgy <a href="http://symfony.com/">symfony 2.1</a> project?</p>
<p>(If there is more extensive documentation available concerning assetic + CompassFilter, please stop reading on and let me know!)</p>
<p>If you take a look at the filter class itself (it is CompassFilter in the generic Assetic\Filter namespace), you should recognise several option values that you can use in your application wide config.yml file.</p>
<p>But first you have to install the framework plugin following these <a href="http://foundation.zurb.com/docs/gem-install.php">instructions</a>.</p>
<p><span id="more-2323"></span></p>
<p>After adding the framework plugin by ruby&#8217;s own package manager &#8220;gem&#8221; (hopefully replaced by composer in the near future ;-)) by typing something like</p>
<pre class="brush: bash; title: ; notranslate">$ gem install zurb-foundation</pre>
<p>the only thing remaining to do is to load the framework plugin by assetic. To do so, put the folloging lines to your config.yml assetic section (as you would do it when using the compass command line interface, refer to the output of</p>
<pre class="brush: bash; title: ; notranslate">$ compass help compile</pre>
<p>.)</p>
<p>The yaml file should look like this:</p>
<pre class="brush: python; title: ; notranslate">
assetic:
    read_from: %kernel.root_dir%/web
    debug: %kernel.debug%
    use_controller: %kernel.debug%
    filters:
        compass:
            plugins: &#x5B;'zurb-foundation'] 
            # load foundation                                     
            # framework as you would do by typing
            # $ compass compile --require 
            # zurb-foundation &#x5B;...]
            # &#x5B; ... ]
</pre>
<p>Now you should be able to import the foundation library files by using the @import statement in your *.sass/*.scss files:</p>
<pre class="brush: css; title: ; notranslate">
@import &quot;foundation&quot;;
</pre>
<p>Have fun!</p>The post <a href="https://nerdpress.org/2012/10/26/symfony-2assetic-sass-compassfilter-foundation-responsive-front-end-framework/">[Symfony 2][Assetic] Sass, CompassFilter + Foundation Responsive Front-end Framework</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2012/10/26/symfony-2assetic-sass-compassfilter-foundation-responsive-front-end-framework/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>[Symfony 2] composer.json for a assumed-stable symfony 2 distribution</title>
		<link>https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/</link>
					<comments>https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 01 Apr 2012 12:18:54 +0000</pubDate>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Project Setup]]></category>
		<category><![CDATA[Silex]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Twig]]></category>
		<category><![CDATA[composer.phar]]></category>
		<category><![CDATA[dependency management]]></category>
		<category><![CDATA[packagist]]></category>
		<category><![CDATA[symfony 2]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2118</guid>

					<description><![CDATA[<p>This small composer.json file is used in a project i am working on atm, feel free to use it at own risk. I will provide non-periodical updates and hopefully soon a full upgrade to symfony 2.1.x including doctrine orm 2.2.x. I still did not get the point regarding dependency resolution, so i simply &#8220;composed&#8221; the &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/" class="more-link">Continue reading<span class="screen-reader-text"> "[Symfony 2] composer.json for a assumed-stable symfony 2 distribution"</span></a></p>
The post <a href="https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/">[Symfony 2] composer.json for a assumed-stable symfony 2 distribution</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>This small composer.json file is used in a project i am working on atm, feel free to use it at own risk. I will provide non-periodical updates and hopefully soon a full upgrade to symfony 2.1.x including doctrine orm 2.2.x.</p>
<p>I still did not get the point regarding dependency resolution, so i simply &#8220;composed&#8221; the composer file by writing down my own requirements (&#8220;i want only the hottest, newest stuff!!&#8221;, then tracked down the error messages, removing them by explicetly writing down the missing dependencies by using the latest &#8220;dev-*&#8221; versions. After that i tried to run the project, which actually did not work, but selective downgrade of some of the bundles (framework, security-extra blahblah) finally did the job.<span id="more-2118"></span></p>
<p>Feel free to use it in your own projects:</p>
<pre class="brush: jscript; title: ; notranslate">
{
	&quot;require&quot; : {
              &quot;symfony/symfony&quot; : &quot;v2.0.12&quot;,
              &quot;doctrine/common&quot; : &quot;2.1.4&quot;,
              &quot;doctrine/orm&quot; : &quot;2.1.6&quot;,
              &quot;symfony/finder&quot; : &quot;v2.0.12&quot;,

              &quot;symfony/assetic-bundle&quot; : &quot;2.0-dev&quot;,
              &quot;twig/extensions&quot; : &quot;dev-master&quot;,
              &quot;jms/security-extra-bundle&quot; : &quot;1.1.0&quot;,
              &quot;sensio/framework-extra-bundle&quot; : &quot;2.0-dev&quot;,
              &quot;sensio/distribution-bundle&quot; : &quot;2.0-dev&quot;,
              &quot;sensio/generator-bundle&quot; : &quot;2.0-dev&quot;

 	},
        &quot;autoload&quot; : {
            &quot;psr-0&quot; : {
                &quot;Acme&quot; : &quot;src/&quot;,
            }
        }
}

</pre>
<p>Create a file named &#8220;composer.json&#8221; in your project&#8217;s root directory, then paste the above code into it and save it.</p>
<p>Now run</p>
<pre class="brush: bash; title: ; notranslate">
$ curl -s http://getcomposer.org/installer | php
</pre>
<p>After that, download all dependencies by typing</p>
<pre class="brush: bash; title: ; notranslate">
$ php composer.phar install
</pre>
<p>The easiest way to create a full project including AcmeDemoBundle, AppKernel and the whole stuff is to download the symfony 2 standard distribution without vendors and calling the script from there. The only thing to do is to modify the path to autoload.php, which should point to vendor/.composer/autoload.php.</p>
<p>Now you are able to upgrade your project&#8217;s dependencies to the newest versions by simply modifying the composer.json file. Have fun!.</p>The post <a href="https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/">[Symfony 2] composer.json for a assumed-stable symfony 2 distribution</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Silex and MongoDB simply</title>
		<link>https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/</link>
					<comments>https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 30 Jan 2012 14:27:34 +0000</pubDate>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Silex]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[silex]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2033</guid>

					<description><![CDATA[<p>Using MongoDB in your Silex Project is quite easy. I will show this with my Superleansilexplate and will integrate it there as an example. Since i dont want to integrate MongoDB in Superleansilexplate it will just become an additional gist. Given you have some smaller amount of data like a counter that needs to be &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/" class="more-link">Continue reading<span class="screen-reader-text"> "Silex and MongoDB simply"</span></a></p>
The post <a href="https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/">Silex and MongoDB simply</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Using MongoDB in your Silex Project is quite easy.</p>
<p>I will show this with my <a href="https://github.com/ivoba/superleansilexplate">Superleansilexplate</a> and will integrate it there as an example.<br />
Since i dont want to integrate MongoDB in Superleansilexplate it will just become an additional <a href="https://gist.github.com/1704512">gist</a>.</p>
<p>Given you have some smaller amount of data like a counter that needs to be stored or other loose coupled datasets, we simply speak to MongoDB &#8220;directly&#8221; and store the data via <a href="https://github.com/doctrine/mongodb">Doctrine MongoDB Abstraction Layer</a>.<br />
Since i presume the Data / Document Structure isnt that complex we dont use <a href="https://github.com/doctrine/mongodb-odm">Doctrine MongoDB ODM</a> (the Object Document Mapper).<br />
If you want to use it instead, try this <a href="https://github.com/docteurklein/SilexExtensions">Silex Extensions</a>.</p>
<p><span id="more-2033"></span></p>
<p>So we use this <a href="https://github.com/fate/Silex-Extensions">SilexExtensions</a> collection and install it via git:</p>
<pre class="brush: bash; title: ; notranslate">
 cd mysilexproject
 git clone git@github.com:fate/Silex-Extensions.git vendor/silex-extension
</pre>
<p>Then we install the doctrine mongodb libary manually:</p>
<pre class="brush: bash; title: ; notranslate">
 git clone --recursive https://github.com/doctrine/mongodb vendor/mongodb
</pre>
<p>The extension collection has some more poviders but you can just ignore them and just focus on the MongoDbExtension.</p>
<p>&#8211;<em> i actually dont like extensions collections. i would prefer to clone each extensions individually. thou its not much code overhead, but when it comes to the vendor dependencies it can become quite messy IMHO</em> &#8211;</p>
<p>Alright now the code.<br />
Edit src/app.php and register the namespace for the extension:</p>
<pre class="brush: php; title: ; notranslate">
 $app&#x5B;'autoloader']-&gt;registerNamespace('SilexExtension', __DIR__ . '/../vendor/silex-extension/src');
</pre>
<p>Then register the MongoDbExtension;</p>
<pre class="brush: php; title: ; notranslate">
 $app-&gt;register(new SilexExtension\MongoDbExtension(), array(
 'mongodb.class_path' =&gt; __DIR__ . '/../vendor/mongodb/lib',
 'mongodb.connection' =&gt; array(
 'server' =&gt; 'mongodb://mysecretuser:mysecretpassw@localhost',
 'options' =&gt; array(),
 'eventmanager' =&gt; function($eventmanager) {
 }
 )
 ));
</pre>
<p>and finally query your MongoDB collection of choice and display the resultset as json:</p>
<pre class="brush: php; title: ; notranslate">
$app-&gt;get('/data-from-mongodb', function() use($app) {

$coll = $app&#x5B;'mongodb']-&gt;selectDatabase('mydb')-&gt;selectCollection('mycoll');
 $query = array(
 'query' =&gt; 'value'
 );
 $sort = array(
 'count' =&gt; -1,
 );
 $r = $coll-&gt;find($query)-&gt;sort($sort)-&gt;toArray();
 $response = new Response();
 $response-&gt;headers-&gt;set('Content-type', 'application/json');
 $response-&gt;setContent(json_encode($r));
 return $response;
 });
</pre>
<p>Easy</p>The post <a href="https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/">Silex and MongoDB simply</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2012/01/30/silex-and-mongodb-simply/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Silex and the HTTP_CACHE</title>
		<link>https://nerdpress.org/2011/11/29/silex-and-the-http-cache/</link>
					<comments>https://nerdpress.org/2011/11/29/silex-and-the-http-cache/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 29 Nov 2011 09:52:11 +0000</pubDate>
				<category><![CDATA[Silex]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1990</guid>

					<description><![CDATA[<p>The HTTP_CACHE resp. the reverse proxy of Symfony is a pretty cool thing. And as it is build-in Silex it can speed up the already fast micro framework massivly, wich is good for me, as i am mainly workin with Silex right now. To enable it you have to register it first like its shown &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2011/11/29/silex-and-the-http-cache/" class="more-link">Continue reading<span class="screen-reader-text"> "Silex and the HTTP_CACHE"</span></a></p>
The post <a href="https://nerdpress.org/2011/11/29/silex-and-the-http-cache/">Silex and the HTTP_CACHE</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>The HTTP_CACHE resp. the reverse proxy of Symfony is a pretty cool thing.<br />
And as it is build-in <a href="http://silex.sensiolabs.org/">Silex</a> it can speed up the already fast micro framework massivly,<br />
wich is good for me, as i am mainly workin with Silex right now.</p>
<p>To enable it you have to register it first like its shown in the <a href="http://silex.sensiolabs.org/doc/providers/http_cache.html">docs</a>:</p>
<pre class="brush: php; title: ; notranslate">
 $app-&gt;register(new Silex\Provider\HttpCacheServiceProvider(), array(
 'http_cache.cache_dir' =&gt; __DIR__.'/cache/',
 ));
</pre>
<p>Also provide the writable cache dir.<br />
<span id="more-1990"></span></p>
<p>Then you have to return the Response Object with HTTP cache headers.</p>
<pre class="brush: php; title: ; notranslate">
$app-&gt;get('/about', function () use ($app) {
 $body = $app&#x5B;'twig']-&gt;render('about.twig');
 return new Response($body, 200, array('Cache-Control' =&gt; 's-maxage=3600, public'));
 });
</pre>
<p>And its good practice to finally call it with a dev switch.</p>
<pre class="brush: php; title: ; notranslate">
if ($app&#x5B;'debug']) {
 $app-&gt;run();
 }
 else{
 $app&#x5B;'http_cache']-&gt;run();
 }
</pre>
<p>Now in production environment the page will be cached and if it gets requested it will be served from the cache, if the cached version is not older then the time-to-live limit given in seconds by s-maxage.<br />
So here you avoid expensive calculation time.<br />
You could also provide a max-age directive to tell the client to cache it on clientside, to avoid the HTTP Request.<br />
But as always with caches its quite a rodeo to balance performance and up-to-dateness.<br />
Expiration and Validation Headers can of course be used aswell to controll the cache even more.</p>
<p>To illustrate the performance increase i loaded a simple about-page, which actually does nothing more then render a template.<br />
So while warming the cache it needed 606ms and from the cache it reduced to 190ms.<br />
warm cache:<br />
<a href="https://nerdpress.org/wp-content/uploads/2011/11/about_cache_warmer.png"> <img decoding="async" class="alignnone size-medium wp-image-1992" title="about_cache_warmer" src="https://nerdpress.org/wp-content/uploads/2011/11/about_cache_warmer-300x16.png" alt="" width="300" height="16" srcset="https://nerdpress.org/wp-content/uploads/2011/11/about_cache_warmer-300x16.png 300w, https://nerdpress.org/wp-content/uploads/2011/11/about_cache_warmer-1024x55.png 1024w, https://nerdpress.org/wp-content/uploads/2011/11/about_cache_warmer.png 1260w" sizes="(max-width: 300px) 100vw, 300px" /></a><br />
from cache:<a href="https://nerdpress.org/wp-content/uploads/2011/11/about_from_cache.png"><br />
<img decoding="async" class="alignnone size-medium wp-image-1993" title="about_from_cache" src="https://nerdpress.org/wp-content/uploads/2011/11/about_from_cache-300x16.png" alt="" width="300" height="16" srcset="https://nerdpress.org/wp-content/uploads/2011/11/about_from_cache-300x16.png 300w, https://nerdpress.org/wp-content/uploads/2011/11/about_from_cache-1024x54.png 1024w, https://nerdpress.org/wp-content/uploads/2011/11/about_from_cache.png 1267w" sizes="(max-width: 300px) 100vw, 300px" /></a><br />
I cant tell how representative this is, but it aswell feels much faster, especially if you got more logic behind the page, like webservice calls etc.</p>
<p>BTW my <a href="https://github.com/ivoba/superleansilexplate">superleansilexplate</a> got also updated to support the Cache.</p>The post <a href="https://nerdpress.org/2011/11/29/silex-and-the-http-cache/">Silex and the HTTP_CACHE</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2011/11/29/silex-and-the-http-cache/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>Enable Twig-Extensions in Silex</title>
		<link>https://nerdpress.org/2011/11/21/enable-twig-extensions-in-silex/</link>
					<comments>https://nerdpress.org/2011/11/21/enable-twig-extensions-in-silex/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 21 Nov 2011 08:55:49 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Silex]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1979</guid>

					<description><![CDATA[<p>UPDATE Please have look here for a updated version. Note: its about Twig-extensions not about the former &#8220;Silex Twig Extension&#8221;, this now called TwigServiceProvider. First fetch the Twig-extensions code and put them in your vendor dir: git submodule add git://github.com/fabpot/Twig-extensions.git vendor/Twig-extensions/fabpot git submodule init git submodule update Then register the autoloader by using registerPrefixes: $app&#x5B;'autoloader']-&#62;registerPrefixes(array( &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2011/11/21/enable-twig-extensions-in-silex/" class="more-link">Continue reading<span class="screen-reader-text"> "Enable Twig-Extensions in Silex"</span></a></p>
The post <a href="https://nerdpress.org/2011/11/21/enable-twig-extensions-in-silex/">Enable Twig-Extensions in Silex</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p><strong>UPDATE</strong><br />
Please have look <a href="https://nerdpress.org/2014/05/05/enable-twig-extensions-silex-revisited/">here for a updated version</a>.</p>
<hr/>
<p>Note: its about <a href="https://github.com/fabpot/Twig-extensions">Twig-extensions</a> not about the former &#8220;Silex Twig Extension&#8221;, this now called TwigServiceProvider.</p>
<p>First fetch the Twig-extensions code and put them in your vendor dir:</p>
<pre class="brush: bash; title: ; notranslate">
git submodule add git://github.com/fabpot/Twig-extensions.git vendor/Twig-extensions/fabpot
git submodule init
git submodule update
</pre>
<p>Then register the autoloader by using registerPrefixes:</p>
<pre class="brush: php; title: ; notranslate">
$app&#x5B;'autoloader']-&gt;registerPrefixes(array(
    'Twig_Extensions_'  =&gt; array(__DIR__.'/../vendor/Twig-extensions/fabpot/lib')));
</pre>
<p><span id="more-1979"></span></p>
<p>You will need to register the TwigServiceProvider itself:</p>
<pre class="brush: php; title: ; notranslate">
$app-&gt;register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' =&gt; __DIR__ . '/../views',
    'twig.class_path' =&gt; __DIR__ . '/../vendor/twig/lib',
));
</pre>
<p>And eventually enable the Extension you like to use, in my case the Text Extension to use the truncate filter:</p>
<pre class="brush: php; title: ; notranslate">
$oldTwigConfiguration = isset($app&#x5B;'twig.configure']) ? $app&#x5B;'twig.configure']: function(){};
$app&#x5B;'twig.configure'] = $app-&gt;protect(function($twig) use ($oldTwigConfiguration) {
    $oldTwigConfiguration($twig);
    $twig-&gt;addExtension(new Twig_Extensions_Extension_Text());
});
</pre>
<p>That might look a bit strange but it has its reasons, read <a href="https://github.com/fabpot/Silex/issues/160">here</a>.</p>
<p>Thats it! Now i can use something like this in my twig templates:</p>
<pre class="brush: plain; title: ; notranslate">
{{ post.content|truncate(200)|raw }}
</pre>The post <a href="https://nerdpress.org/2011/11/21/enable-twig-extensions-in-silex/">Enable Twig-Extensions in Silex</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2011/11/21/enable-twig-extensions-in-silex/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Silex Starter Stubs</title>
		<link>https://nerdpress.org/2011/11/04/silex-starter-stubs/</link>
					<comments>https://nerdpress.org/2011/11/04/silex-starter-stubs/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 04 Nov 2011 14:01:46 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Silex]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[h5bp]]></category>
		<category><![CDATA[silex]]></category>
		<category><![CDATA[skeleton]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1924</guid>

					<description><![CDATA[<p>There are several preconfigured Silex Apps on github. They let you start your Silex project in no time, which is good. This makes Silex an even more simple rabbithole into the symfony2 world. I started one myself and had a close look on the others, so i thought i share this. They all differ a &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2011/11/04/silex-starter-stubs/" class="more-link">Continue reading<span class="screen-reader-text"> "Silex Starter Stubs"</span></a></p>
The post <a href="https://nerdpress.org/2011/11/04/silex-starter-stubs/">Silex Starter Stubs</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>There are several preconfigured <a href="http://silex.sensiolabs.org/">Silex</a> Apps on github. They let you start your Silex project in no time, which is good.<br />
This makes Silex an even more simple rabbithole into the symfony2 world.</p>
<p>I started one myself and had a close look on the others, so i thought i share this.<br />
They all differ a bit so you must choose what fits your needs the best.</p>
<p>They all follow some kind of &#8220;best practise&#8221; structure, some more, some less.</p>
<p><span id="more-1924"></span></p>
<p>So there is: <a href="https://github.com/gcalore/Silex-Stub">https://github.com/gcalore/Silex-Stub</a><br />
This has several common Providers already enabled:</p>
<ul>
<li>Twig</li>
<li>UrlGenerator</li>
<li>Monolog</li>
<li>Doctrine DBAL</li>
<li>Validator</li>
<li>Forms</li>
</ul>
<p>but it has no Frontend Frameworks integrated.<br />
Another minus point is that the index is not in a web directory but in root, so that all lib files etc. are potentially accessible from the web, thou a .htaccess avoids that here.<br />
It also doesnt provide tests.<br />
So i wouldnt recommend that one.</p>
<p>The next one is: <a href="https://github.com/brtriver/silex-sample-application">https://github.com/brtriver/silex-sample-application</a><br />
This is a sample rudimentary blog application that you could use as starter.<br />
It has Doctrine and Twig build-in, it has tests but also doesnt include some frontend magic.</p>
<p>The most complete is: <a href="https://github.com/lyrixx/Silex-Kitchen-Edition">https://github.com/lyrixx/Silex-Kitchen-Edition</a><br />
This starterkit has several extension enabled:</p>
<ul>
<li>Doctrine</li>
<li>Form</li>
<li>Session</li>
<li>SymfonyBrige</li>
<li>Translation</li>
<li>Twig (with debug extension)</li>
<li>UrlGenerator</li>
</ul>
<p>and it also has the HTML5Boilerplate and Twitter`s Bootstrap integrated.<br />
Further <em>Assetic</em> and the <em>YAMLLoader</em> are already shipped and active and tests are provided aswell.<br />
Here Silex is included as submodule, which means unpacked &#8211; hence not as phar-, which might be interesting for some.<br />
In my Opinion this is some kind of a reference app, this is even more likely since the creator is sensio employee.<br />
I stole a lot from it ;).</p>
<p>Last but not least mine ;) : <a href="https://github.com/ivoba/superleansilexplate">https://github.com/ivoba/superleansilexplate</a><br />
Its supposed to be very lean.<br />
It comes just with <em>Twig</em> and <em>Translation</em> enabled.<br />
It aims mainly at simple applications that need routing and just some additional logic. F.e. its a good container for javascript driven apps that get their data through API calls. If you need database support and more, simply register the provider yourself or use the <a href="https://github.com/lyrixx/Silex-Kitchen-Edition">kitchen</a>.</p>
<p>Tests are included and for the frontend there is the a mix of skeleton(bootstrap seemed too verbose and too twitter branded for mi gusto) and HTML5boilerplate.<br />
Also there is an optimized Boilerplate Build included to avoid Assetic.</p>
<p><a href="https://nerdpress.org/wp-content/uploads/2011/11/superleansilexplate.png"><img decoding="async" class="alignnone size-medium wp-image-1939" title="superleansilexplate" src="https://nerdpress.org/wp-content/uploads/2011/11/superleansilexplate-300x148.png" alt="" width="300" height="148" srcset="https://nerdpress.org/wp-content/uploads/2011/11/superleansilexplate-300x148.png 300w, https://nerdpress.org/wp-content/uploads/2011/11/superleansilexplate.png 972w" sizes="(max-width: 300px) 100vw, 300px" /></a><br />
Its not really finished yet, but sufficient to start with.<br />
(feel free to provide some improvements)</p>The post <a href="https://nerdpress.org/2011/11/04/silex-starter-stubs/">Silex Starter Stubs</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2011/11/04/silex-starter-stubs/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Silex, Twig und HTML5 BoilerPlate</title>
		<link>https://nerdpress.org/2011/10/12/silex-twig-und-html5-boilerplate/</link>
					<comments>https://nerdpress.org/2011/10/12/silex-twig-und-html5-boilerplate/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Wed, 12 Oct 2011 05:31:45 +0000</pubDate>
				<category><![CDATA[Silex]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1863</guid>

					<description><![CDATA[<p>Alright, there is a bundle for H5BP for symfony2 and there is Assetic, you can probably use both with Silex and thats just fine. But in case you want to keep your Silex project lean (since its micro) you can use Twig and H5BP only and build / deploy your app from the outside. With &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2011/10/12/silex-twig-und-html5-boilerplate/" class="more-link">Continue reading<span class="screen-reader-text"> "Silex, Twig und HTML5 BoilerPlate"</span></a></p>
The post <a href="https://nerdpress.org/2011/10/12/silex-twig-und-html5-boilerplate/">Silex, Twig und HTML5 BoilerPlate</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Alright, there is a bundle for <a href="http://symfony2bundles.org/FlintLabs/H5BP-Symfony2-Bundle">H5BP for symfony2</a> and there is <a href="https://github.com/kriswallsmith/assetic">Assetic</a>, you can probably use both with Silex and thats just fine.<br />
But in case you want to keep your Silex project lean (since its micro) you can use Twig and H5BP only and build / deploy your app from the outside.<br />
<a href="https://nerdpress.org/wp-content/uploads/2011/10/boilerplate.png"><img decoding="async" src="https://nerdpress.org/wp-content/uploads/2011/10/boilerplate-300x158.png" alt="" title="boilerplate" width="300" height="158" class="alignnone size-medium wp-image-1884" srcset="https://nerdpress.org/wp-content/uploads/2011/10/boilerplate-300x158.png 300w, https://nerdpress.org/wp-content/uploads/2011/10/boilerplate.png 963w" sizes="(max-width: 300px) 100vw, 300px" /></a><br />
With a little tuning of the H5BP build, of course / unfortunatly. (Ok thats the caveat) </p>
<p>So i have a structure like so:<br />
web/<br />
(this is the webroot, here is js/css/images, all that asset stuff and the index, here we use the recommended H5BP stuff&#8217;n&#8217;structure)<br />
views/<br />
(this is outside of webroot and here are all of the *.twig)<br />
<span id="more-1863"></span><br />
Then we need the boilerplate build stuff:</p>
<pre class="brush: bash; title: ; notranslate">
cd &lt;silex&gt;
cp -R &lt;boilerplate&gt;/build &lt;silex&gt;/build
mkdir intermediate
chmod 777 intermediate
mkdir publish
chmod 777 publish
</pre>
<p>Now we configure the build in the build/config/project.properties</p>
<p>#add your neccessary twig files that contain css and layout includes:<br />
file.pages        = views/layout.twig,views/search.twig</p>
<p>#exclude some already optimized libs<br />
file.js.bypass = libs/jquery.isotope.min.js, libs/jquery.hoverIntent.minified.js</p>
<p>#change the source dir to web<br />
dir.source          = ./web</p>
<p>Since the build isnt able to handle multiple source dirs we have to copy the views manually to the intermediate and publish file.<br />
So we need a new target:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!--
    *************************************************
    * CUSTOM TARGETS                                  *
    *************************************************
    --&gt;
    &lt;target name=&quot;copyViews&quot;&gt;
	    &lt;echo message=&quot;copy Views for build&quot;/&gt;
	    &lt;mkdir dir=&quot;${dir.intermediate}/${dir.views}&quot;/&gt;
            &lt;copy todir=&quot;${dir.intermediate}/${dir.views}&quot; includeEmptyDirs=&quot;true&quot;&gt;
                &lt;fileset dir=&quot;${dir.views}/&quot; excludes=&quot;${file.default.exclude}, ${file.exclude}&quot;&gt;
                &lt;/fileset&gt;
            &lt;/copy&gt;
	    &lt;mkdir dir=&quot;${dir.publish}/${dir.views}&quot;/&gt;
            &lt;copy todir=&quot;${dir.publish}/${dir.views}&quot; includeEmptyDirs=&quot;true&quot;&gt;
                &lt;fileset dir=&quot;${dir.views}/&quot; excludes=&quot;${file.default.exclude}, ${file.exclude}&quot;&gt;
                &lt;/fileset&gt;
            &lt;/copy&gt;
    &lt;/target&gt;
</pre>
<p><a href="https://gist.github.com/1272286">Gist</a><br />
Copy this to build.xml or to your project.xml ( > H5BP 2).</p>
<p>Its nearly done! But one thing still needs to be customized if you run H5BP 2, so preplace the following with code with the code from the <a href="https://github.com/paulirish/html5-boilerplate">latest</a> build.xml:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;replaceregexp match=&quot;&amp;lt;!-- CSS concatenated &#x5B;\d\w\s\W]*?!-- end CSS--&amp;gt;&quot; replace=&quot;&amp;lt;link rel='stylesheet' href='${style.css}'&amp;gt;&quot; flags=&quot;m&quot;&gt;
            &lt;fileset dir=&quot;${dir.intermediate}&quot; includes=&quot;${page-files}&quot;/&gt;
        &lt;/replaceregexp&gt;
</pre>
<p>with this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;replaceregexp match=&quot;&amp;lt;link rel=&#x5B;'&amp;quot;]?stylesheet&#x5B;'&amp;quot;]?\s+href=&#x5B;'&amp;quot;]?(.*)/${file.root.stylesheet}(?:\?.*)?&#x5B;'&amp;quot;]?\s*&amp;gt;&quot; 
        	replace=&quot;&amp;lt;link rel='stylesheet' href='\1/${css.sha}.css'&amp;gt;&quot; flags=&quot;m&quot;&gt;
            &lt;fileset dir=&quot;${dir.intermediate}&quot; includes=&quot;${page-files}&quot;/&gt;
&lt;/replaceregexp&gt;
</pre>
<p>and</p>
<pre class="brush: xml; title: ; notranslate">
 &lt;replaceregexp match=&quot;&amp;lt;!-- scripts concatenated &#x5B;\d\w\s\W]*?!-- end ((scripts)|(concatenated and minified scripts))--&amp;gt;&quot; replace=&quot;&amp;lt;script defer src='${scripts.js}\'&amp;gt;&amp;lt;/script&amp;gt;&quot; flags=&quot;m&quot;&gt;
            &lt;fileset dir=&quot;${dir.intermediate}&quot; includes=&quot;${page-files}&quot;/&gt;
        &lt;/replaceregexp&gt;
</pre>
<p>with this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;replaceregexp match=&quot;&amp;lt;!-- scripts concatenated &#x5B;\d\w\s\W]*&amp;lt;script.*src=&#x5B;'&amp;quot;]?(.*)/${file.root.script}(?:\?.*)?&#x5B;'&amp;quot;]?\s*&amp;gt;\s*&amp;lt;/script&amp;gt;&#x5B;\d\w\s\W]*&amp;lt;!-- end ((scripts)|(concatenated and minified scripts))\s*--&amp;gt;&quot; 
        	replace=&quot;&amp;lt;script defer src='\1/${scripts.sha}.js\'&amp;gt;&amp;lt;/script&amp;gt;&quot; flags=&quot;m&quot;&gt;
            &lt;fileset dir=&quot;${dir.intermediate}&quot; includes=&quot;${page-files}&quot;/&gt;
&lt;/replaceregexp&gt;
</pre>
<p>This respects js and css pathes in the replacements.</p>
<p>Now you can run the build local:</p>
<pre class="brush: xml; title: ; notranslate">
cd build
ant copyViews minify
</pre>
<p>So here you could be done if your with FTP or your favourite upload method, just upload the optimized files from the publish dir to their resp. location.</p>
<p>Next time more with integrating that in your git deployment.</p>The post <a href="https://nerdpress.org/2011/10/12/silex-twig-und-html5-boilerplate/">Silex, Twig und HTML5 BoilerPlate</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2011/10/12/silex-twig-und-html5-boilerplate/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
