Skip to content

Instantly share code, notes, and snippets.

View ThijsFeryn's full-sized avatar

Thijs Feryn ThijsFeryn

View GitHub Profile
@ThijsFeryn
ThijsFeryn / symfony_esi.php
Last active November 9, 2015 13:33
A page built using Symfony Components containing 3 content blocks: the main content block with a TTL of 10 seconds and 2 content blocks loaded via ESI. The first one has a TTL of 20 seconds, the second one doesn't cache
<?php
require_once __DIR__.'/vendor/autoload.php';
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$esi = new Esi;
$request = Request::createFromGlobals();
$response = new Response();
$content = '<h1>This pages refreshes every 10 seconds</h1>';
@ThijsFeryn
ThijsFeryn / composer.json
Created November 12, 2015 14:14
Simple ESI rendering example using Silex and Varnish v4. The render_esi function in Twig renders ESI tags when the right Surrogate-Capability header is thrown, otherwise it uses internal subrequests.
{
"require": {
"silex/silex": "1.3.*",
"symfony/twig-bridge": "2.7",
"twig/twig": "1.23.*"
}
}
@ThijsFeryn
ThijsFeryn / 1_scalar_type.php
Created November 30, 2015 14:09
PHP 7 scalar type hints
<?php
/**
* Scalar type declarations
*/
//declare(strict_types=1);
function add(int $a, int $b) {
return $a + $b;
}
@ThijsFeryn
ThijsFeryn / 2_return_type.php
Created November 30, 2015 14:14
PHP 7 return type declarations
<?php
/**
* Return type declarations
*/
//declare(strict_types=1);
function add(int $a, int $b): int{
return (string)($a + $b);
}
@ThijsFeryn
ThijsFeryn / 3_anonymous_classes.php
Created November 30, 2015 14:14
PHP 7 anonymous classes
<?php
/**
* Anonymous classes
*/
$foo = new class {
public function foo() {
return "bar";
}
};
@ThijsFeryn
ThijsFeryn / 4_closure_call.php
Created November 30, 2015 14:15
PHP 7 Closure::call()
<?php
/**
* Closure::call()
*/
class Foo
{
private $foo = 'bar';
}
@ThijsFeryn
ThijsFeryn / 5_generator_delegation.php
Created November 30, 2015 14:16
PHP 7 generator delegation
<?php
/**
* Generator delegation
*/
function gen()
{
yield 1;
yield 2;
yield from gen2();
@ThijsFeryn
ThijsFeryn / 6_generator_return.php
Created November 30, 2015 14:16
PHP 7 generator return
<?php
/**
* Generator return expressions
*/
$gen = (function() {
yield 1;
yield 2;
return 3;
@ThijsFeryn
ThijsFeryn / 7_null_coalesce.php
Created November 30, 2015 14:17
PHP 7 null coalesce operator
<?php
/**
* Null coalesce operator
*/
$array = ['foo'=>'bar'];
//PHP5 style
$message = isset($array['foo']) ? $array['foo'] : 'not set';
echo $message.PHP_EOL;
@ThijsFeryn
ThijsFeryn / 8_space_ship.php
Created November 30, 2015 14:17
PHP 7 space ship operator
<?php
/**
* Space ship operator
*/
$array = [
"1 <=> 1" => 1 <=> 1,
"1 <=> 2" =>1 <=> 2,
"2 <=> 1" => 2 <=> 1
];