Skip to content

Instantly share code, notes, and snippets.

@ronan-gloo
ronan-gloo / gist:5653498
Created May 26, 2013 17:51
Convert non-associative array to associative array
<?php
$segments = ['one', 'two', 'three'];
$copy = $segments;
$assoc = [];
foreach ($segments as $key => $seg)
{
$segment = next($copy);
@ronan-gloo
ronan-gloo / clone-new.php
Last active December 17, 2015 22:49
clone | new ArrayCollection
<?php
$clone = new ArrayCollection;
$steps = 10000;
$instances = [];
$start['new'] = microtime(true);
foreach (range(1, $steps) as $k) {
$instances[] = new ArrayCollection;
}
@ronan-gloo
ronan-gloo / gist:5721982
Last active December 18, 2015 03:58
Custom functions Doctrine 2 / ZF2
'doctrine' =>
[
'configuration' =>
[
'orm_default' =>
[
'string_functions' =>
[
'func_name' => 'class_name'
],
@ronan-gloo
ronan-gloo / gist:6052449
Last active December 20, 2015 01:58
Quelques paramètres méconnus du router zf2 (à partir de la 2.2 pour certains)
<?php
'router' =>
[
// Active le support du translator pour les portions de route marquées par {translation_key}
// Il faut lui injecter un translator
'router_class' => 'Zend\Mvc\Router\Http\TranslatorAwareTreeRouteStack',
// Valeurs par défaut pour toutes les routes
'default_params' =>
@ronan-gloo
ronan-gloo / gist:6071752
Created July 24, 2013 15:41
Gestion 404 dans les controleurs
<?php
// Remplacer:
if (!$page) {
$response = new Response();
$response->setStatusCode(404);
return $response;
}
// Par:
@ronan-gloo
ronan-gloo / gist:6278100
Last active December 21, 2015 08:28
ATOUM: Get last error in exception callback
<?php
function toto($pattern, $value) {
$split = preg_split($pattern, $value);
if ($error = error_get_last()) {
throw new Exception($error['message'], Exception::INVALID_PARAMETER);
}
}
<?php
class SoapClient
{
public function __call($method, $args)
{
return $this;
}
public function __get($prop)
@ronan-gloo
ronan-gloo / gist:9291902
Last active August 29, 2015 13:56
Scope varaible + méthode
<?php
class User {
private $password;
public function __construct($password)
{
$this->password = $password;
}
@ronan-gloo
ronan-gloo / gist:9342993
Created March 4, 2014 09:17
Cuisine et dépendances
<?php
// constructor
class Void
{
protected $mapper;
public function __construct(Mapper $mapper)
{
$this->mapper = $mapper;
@ronan-gloo
ronan-gloo / PrgDev.php
Created April 24, 2014 08:12
Prg for devmode
<?php
namespace Application\Controller\Plugin;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
/**
* Use this object to replace the original prg controller's plugin for dev convenience.
*/