Skip to content

Instantly share code, notes, and snippets.

View Saeven's full-sized avatar

Alexandre Lemaire Saeven

View GitHub Profile
@Saeven
Saeven / samplerank.php
Created October 23, 2017 13:51
Ranking query
/**
* Retrieve a particular user's rank and details, considering descending sort order on that column
* @param $column The column name used for sorting
* @param $user_id The user ID whose rank we want to obtain
* @return array
* @throws \Exception
*/
public function getUserRank( $column, $user_id )
{
if( !is_numeric( $user_id ) )
@Saeven
Saeven / assetic.config.php
Created April 6, 2017 16:01
Same controller-based gist for Assetic
<?php
return [
'controllers' => [
\SilverStarMember\Controller\IndexController::class => [
'@member_css',
'@member_js',
],
],
@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 = '';
@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 / doctrine_memcached.php
Last active February 25, 2017 05:09
Doctrine & Memcached
<?php
/*
* Typical database config
*/
// ....
'doctrine' => [
@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 / 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 / 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 / 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 / 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(