Skip to content

Instantly share code, notes, and snippets.

View ezimuel's full-sized avatar
🇮🇹
Working remotely, since 2008

Enrico Zimuel ezimuel

🇮🇹
Working remotely, since 2008
View GitHub Profile
@ezimuel
ezimuel / gist:2769399
Created May 22, 2012 14:27
Zend\InputFilter issue
use Zend\InputFilter\InputFilter,
Zend\InputFilter\Input;
$input = new Input('foo');
$input->getFilterChain()
->attachByName('stringtrim')
->attachByName('alpha');
$inputFilter = new InputFilter();
$inputFilter->add($input)
/**
* Set data to use when validating and filtering
*
* @param array|Traversable $data
* @return InputFilterInterface
*/
public function setData($data)
{
if (!is_array($data) && !$data instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
@ezimuel
ezimuel / gist:2838705
Created May 30, 2012 20:25
Zend\Math\Math::randBytes fix
public static function randBytes($length, $strong = false)
{
if ($length <= 0) {
return false;
}
if (extension_loaded('openssl')) {
$rand = openssl_random_pseudo_bytes($length, $secure);
if ($secure === true) {
return $rand;
}
@ezimuel
ezimuel / password.php
Created June 18, 2012 17:37 — forked from ircmaxell/password.php
Password API Example
<?php
define('PASSWORD_SHA256', '$5$');
define('PASSWORD_SHA512', '$6$');
define('PASSWORD_BCRYPT', '$2y$');
define('PASSWORD_SCRYPT', '$7$'); // made up here
function password_hash($password, $algo = PASSWORD_BCRYPT, array $options = array()) {
$salt = '';
@ezimuel
ezimuel / gist:2955319
Created June 19, 2012 17:06
Idea for a Factory abstract class
interface FactoryInterface {
public static function factory($classname, $options = null);
public static function validate($classname);
public static function getClassMap();
}
abstract class AbstractFactory {
public static function factory($name, $options = null)
{
@ezimuel
ezimuel / gist:2972974
Created June 22, 2012 14:14
Proposal for support ignore annotation with wildcard for Doctrine
namespace MyCompany\Annotations {
/**
* @Annotation
*/
class Foo
{
public $bar;
}
/**
@ezimuel
ezimuel / zend.barcode.objects.rst
Created July 17, 2012 12:13
zend.barcode.objects

Zend\Barcode\Barcode Objects

Barcode objects allow you to generate barcodes independently of the rendering support. After generation, you can retrieve the barcode as an array of drawing instructions that you can provide to a renderer.

Objects have a large number of options. Most of them are common to all objects. These options can be set in three ways:

@ezimuel
ezimuel / gist:3129733
Created July 17, 2012 14:30
Script to convert all the ZF2 docs from DocBook to reStructuredText
<?php
require 'RstConvert.php';
$zf2Bin = '/path_to_zf2/bin';
$docbookPath = '/path_to_zf2/documentation/manual/en/module_specs';
foreach (glob("$docbookPath/*.xml") as $filename) {
$fileout = RstConvert::xmlFileNameToRst(basename($filename));
echo "Generating...$fileout\n";
ZF2 Documentation State of Art
------------------------------
Authentication (ok)
Barcode (ok)
Cache (to fix)
Captcha (ok)
Code (to be completed)
Config (ok)
Console (to be completed)
@ezimuel
ezimuel / pluginmanager.php
Last active November 7, 2015 16:54
Experimental plugin manager compliant with ContainerInterface
<?php
/**
* Experimantal plugin manager complaint with ContainerInterface with options support
* using the optional Interface rule of PHP
*/
use Interop\Container\ContainerInterface;
class PluginManager implements ContainerInterface
{