Skip to content

Instantly share code, notes, and snippets.

Avatar
🇮🇹
Working remotely, since 2008

Enrico Zimuel ezimuel

🇮🇹
Working remotely, since 2008
View GitHub Profile
View gist:2050095
namespace Zend\Log;
use Zend\Log\Logger;
interface LoggerAware
{
public function setLogger(Logger $logger);
public function getLogger();
}
@ezimuel
ezimuel / gist:2051907
Created Mar 16, 2012
Prepare the INSERT for Zend\Log\Writer\Db
View gist:2051907
protected function prepareInsert($adapter, $table, array $fields)
{
$sql = 'INSERT INTO ' . $adapter->platform->quoteIdentifier($table) . ' (' .
implode(",",array_map(array($adapter->platform, 'quoteIdentifier'), $fields)) . ') VALUES (' .
implode(",",array_map(array($adapter->driver, 'formatParameterName'), $fields)) . ')';
return $sql;
}
@ezimuel
ezimuel / gist:2577720
Created May 2, 2012
Select with Zend\Db\TableGateway\TableGateway with an empty table
View gist:2577720
// The table queue is empty, I got this Fatal error: Uncaught exception 'Zend\Db\Adapter\Exception\InvalidQueryException' with message 'No database selected' in /.../library/Zend/Db/Adapter/Driver/Pdo/Statement.php on line 219
use Zend\Db\TableGateway\TableGateway,
Zend\Db\Adapter\Adapter as DbAdapter;
$options = array(
'driver' => 'pdo_mysql',
'username' => 'queue',
'password' => 'xxx',
'dbname' => 'queue',
@ezimuel
ezimuel / gist:2769399
Created May 22, 2012
Zend\InputFilter issue
View gist:2769399
use Zend\InputFilter\InputFilter,
Zend\InputFilter\Input;
$input = new Input('foo');
$input->getFilterChain()
->attachByName('stringtrim')
->attachByName('alpha');
$inputFilter = new InputFilter();
$inputFilter->add($input)
View gist:2769699
/**
* 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
Zend\Math\Math::randBytes fix
View gist:2838705
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 Jun 18, 2012 — forked from ircmaxell/password.php
Password API Example
View password.php
<?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 Jun 19, 2012
Idea for a Factory abstract class
View gist:2955319
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 Jun 22, 2012
Proposal for support ignore annotation with wildcard for Doctrine
View gist:2972974
namespace MyCompany\Annotations {
/**
* @Annotation
*/
class Foo
{
public $bar;
}
/**
View zend.barcode.objects.rst

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: