Skip to content

Instantly share code, notes, and snippets.

@EmanueleMinotto
EmanueleMinotto / gist:5990279
Created July 13, 2013 10:31
PHP Double access utility

Double access utility

This is an utility I made to access to common global variables in a mode I prefer: $_GET -> foo against $_GET['foo'].

Where's the utility?

  • you can use this function for other variables too
  • backward compatibility: array access is allowed too, so $_GET['foo'] is accepted
  • integer and float values will be converted from string to their respective values
  • usage on inclusion
  • prevent not defined cells errors
@EmanueleMinotto
EmanueleMinotto / -proof-of-concept
Last active December 16, 2015 14:38
PoC directory
/
Acme
Package
Library.php
LibraryTest.php
composer.json
.gitignore
.gitattributes
acmescript
ema:cli ema$ phpunit
PHPUnit 4.8.8 by Sebastian Bergmann and contributors.
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 63 / 227 ( 27%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 126 / 227 ( 55%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 189 / 227 ( 83%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE.
Time: 1.94 seconds, Memory: 35.25Mb
<?php
// File: app/config/importer.php
use Symfony\Component\Finder\Finder;
$finder = new Finder();
$files = $finder->files()->name('*.yml')->in(__DIR__.'/services')->in(__DIR__.'/vendors');
foreach ($files as $file) {
$loader->import($file->getRealpath());
}
@EmanueleMinotto
EmanueleMinotto / README.md
Created January 29, 2015 21:00
PHP Exceptions Handlers

Exceptions Handlers

Starting from an idea of @lastguest, I'm writing this code to allow a chain of handlers.

What's the problem? Main problem is that more than one exception handlers aren't allowed so easily.

@EmanueleMinotto
EmanueleMinotto / README.md
Created January 29, 2015 20:59
PHP Microframework

Microframework

This is a PHP (5.3+) microframework based on anonymous functions.

Features

  • requested URLs matched using regular expressions
  • request methods (matches using regular expressions too)
  • differenced FIFO queues for each $priority
  • command line usage
  • backward compatibility
  • integrated Dependency Injection and settings system
  • named patterns
@EmanueleMinotto
EmanueleMinotto / README.md
Created January 29, 2015 20:57
PHP Configuration

Configuration

This configuration system is based on default runtime configuration system.

Difference consists in SAPI access: PHP alone supports .user.ini files only using CGI/FastCGI SAPI, using this version custom configurations can be setted outside main php.ini.

@EmanueleMinotto
EmanueleMinotto / README.md
Created January 29, 2015 20:56
PHP PSR-0 implementation

Autoloader

This autoloader extends the PSR-0 standard.

It uses PHP SPL extensions and include_path directories.

<?php
namespace igorw\lusp;
// all functions return a pair of [val, env]
function evaluate($expr, $env = []) {
if (is_string($expr)) {
if (is_numeric($expr)) {
$val = (float) $expr;
<?php
use Doctrine\ORM\EntityManager,
Doctrine\ORM\Configuration,
Doctrine\ORM\Mapping\ClassMetadata;
/**
* Active Entity trait
*
* Limitations: a class can only ever be assocaited with ONE active entity manager. Multiple entity managers