Skip to content

Instantly share code, notes, and snippets.

View stefanorg's full-sized avatar

Stefano stefanorg

View GitHub Profile
@stefanorg
stefanorg / php_error_reporting
Created October 29, 2014 18:48
php error reporting in php file
ini_set('display_errors',1);
error_reporting(E_ALL);
@stefanorg
stefanorg / composer-production
Created November 12, 2014 22:33
Composer production ready install
composer install --no-dev --prefer-dist --optimize-autoloader
@stefanorg
stefanorg / PHP CLI DEBUG
Last active November 25, 2015 08:29
phpstorm remote cli debuggin zf2 cli application
XDEBUG_CONFIG="idekey=PHPSTORM" XDEBUG_SESSION_START="PHPSTORM" PHP_IDE_CONFIG="serverName=THE_SERVER_NAME_I_SET_IN_PHPSTORM" php public/index.php
@stefanorg
stefanorg / random-string-generator
Created January 10, 2015 13:01
Random string generator
<?php
namespace Utils;
/**
* Class RandomStringGenerator
* @package Utils
*
* Solution taken from here:
* http://stackoverflow.com/a/13733588/1056679
function random_text( $type = 'alnum', $length = 8 )
{
switch ( $type ) {
case 'alnum':
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'alpha':
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'hexdec':
@stefanorg
stefanorg / zray_prepend.php
Created October 1, 2015 22:22
zray prepend scrip
<?php
$allowedIps = array('127.0.0.1');
$zray_disable = true;
if (isset($_SERVER['REMOTE_ADDR']) && in_array($_SERVER['REMOTE_ADDR'], $allowedIps)) {
$zray_disable = false;
}
if ($zray_disable == true) {
if (function_exists('zray_disable')) {
zray_disable();
@stefanorg
stefanorg / UnitTest.php
Created November 1, 2015 20:14
dummy unit test
<?php
/**
* @backupGlobals disabled
* @backupStaticAttributes disabled
*/
class ServiceTest extends \Codeception\TestCase\Test
{
use \Codeception\Specify;
@stefanorg
stefanorg / find-missing-return-types.php
Created January 23, 2016 06:29 — forked from Ocramius/find-missing-return-types.php
Script to find classes/interfaces/traits with missing return types: ADD THEM TO YOUR SHIT.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$namespace = 'PutYourProjectNamespaceHere\\';
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/src')), '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH) as $file) {
require_once $file[0];
}
@stefanorg
stefanorg / CastsValueObject.php
Created February 28, 2016 20:10 — forked from cmaas/CastsValueObject.php
A Trait to automatically cast value objects in Laravel without needing a Mutator and an Accessor.
<?php
trait CastsValueObjects
{
protected function castAttribute($key, $value)
{
$castToClass = $this->getValueObjectCastType($key);
// no Value Object? simply pass this up to the parent
if (!$castToClass) {
return parent::castAttribute($key, $value);
class InvalidRowException extends \Exception
{
// One off error messages can use this method...
public static function create(Row $row, $reason)
{
return new static("Row " . $row->getIndex() . " is invalid because: " . $reason);
}
// ...and predefined methods can use it internally.
public static function blankLine(Row $row)