Skip to content

Instantly share code, notes, and snippets.

View Saeven's full-sized avatar

Alexandre Lemaire Saeven

View GitHub Profile
@Saeven
Saeven / gist:7308410
Created November 4, 2013 20:03
Using TwigRenderer directly, to render a view script and capture its output
$viewModel = new ViewModel();
$viewModel->setVariables(
array(
'reset_url' => $core->getCurrentSite() . "/reset/" . $reset_hash,
'ip_address' => $core::getIP(),
'promo_name' => $core->getPromotionName(),
)
);
@Saeven
Saeven / gist:8318339
Created January 8, 2014 15:18
Regex vs Filter/Count/Ctype
<?php
set_time_limit( 0 );
$searchText = 'Page and Brin originally nicknamed THEIR new search engine "BackRub", because the system checked backlinks to estimate the importance of a site.';
$start = microtime_float();
for( $i = 0 ; $i < 1000000 ; $i++ )
{
preg_match_all("/[A-Z]{1}[a-zA-z]*/", $searchText, $matches );
@Saeven
Saeven / gist:8651055
Created January 27, 2014 15:51
Subquery in ZF2 in AbstractTableGateway implementation
public function fetchAllWithVotes()
{
$resultset = $this->select( function( Select $select ){
$sub = new Select( 'votes' );
$sub->columns( array( 'total' => new Expression('COUNT(*)') ) )
->where( 'songs.id = votes.song_id' );
$select->columns(
array(
@Saeven
Saeven / PHP Mcrypt AES-256
Created January 11, 2016 18:14
AES-256 should not be confused with Rijndael-256.
<?php
class Foo
{
const COOKIE_KEY = '839914B48AE583605F004C784FEF155B39A2C142AD7A747582160E6C14E7EF16';
const COOKIE_IV = '864C9BB8032792391B88C76CF73276F2';
public function encrypt( $what )
{
@Saeven
Saeven / AbstractControllerFactory.php
Created March 9, 2016 20:28
Abstract controller factory test, to help the migration to zend-mvc 2.7.1 that removes the service locator entirely.
namespace Application\Factory\Controller;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class AbstractControllerFactory implements AbstractFactoryInterface
{
/**
* Determine if we can create a service with name
@Saeven
Saeven / LazyControllerFactory.php
Last active April 11, 2016 20:45
Lazy controller factory that auto-injects dependencies based on controller params.
<?php
class LazyControllerFactory implements AbstractFactoryInterface
{
/**
* Determine if we can create a service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
@Saeven
Saeven / # php70 - 2016-09-26_21-45-45.txt
Created September 27, 2016 01:53
php70 (josegonzalez/php/php70) on macOS 10.11.6 - Homebrew build logs
Homebrew build logs for josegonzalez/php/php70 on macOS 10.11.6
Build date: 2016-09-26 21:45:45
@Saeven
Saeven / doctrine_memcached.php
Last active February 25, 2017 05:09
Doctrine & Memcached
<?php
/*
* Typical database config
*/
// ....
'doctrine' => [
@Saeven
Saeven / IndexControllerSpec.php
Created March 1, 2017 17:12
Sample dispatch test
<?php
namespace Spec\Application\Controller;
use Application\Controller\Plugin\JsonWrapper;
use Application\Entity\User;
use Application\Mapper\ConfigurationMapper;
use Application\Mapper\CouponMapper;
use Application\Mapper\UserServerPlanMapper;
use Application\Service\CartService;
@Saeven
Saeven / MultibyteGuard.php
Created March 23, 2017 16:26
MultibyteGuardFilter
<?php
namespace LDP\Form\Filter;
class MultibyteGuard implements \Zend\Filter\FilterInterface
{
public function filter($value)
{
if (!mb_check_encoding($value, 'utf-8')) {
$value = '';