Skip to content

Instantly share code, notes, and snippets.

@mnapoli
mnapoli / gist:3752568
Created September 19, 2012 21:57
PHP Dependency Injection
class MyClass {
/**
* @Inject
* @var MyService
*/
private $service;
}
@mnapoli
mnapoli / reference.yml
Last active January 12, 2023 00:08
Doctrine YAML configuration reference
# Inspired from http://blog.hio.fr/2011/09/17/doctrine2-yaml-mapping-example.html
MyEntity:
type: entity
repositoryClass: MyRepositoryClass
table: my_entity
namedQueries:
all: "SELECT u FROM __CLASS__ u"
# Class-Table-Inheritance
@mnapoli
mnapoli / php-hotkey.ahk
Created October 17, 2012 08:46
Autohotkey script for PHP developers on the BÉPO layout
; PHP developer shortcuts for BÉPO keyboard layouts
; Need AutoHotkey_L to support unicode encoding (http://www.autohotkey.com/download/)
; "->" for PHP (when typing <Alt>+8)
!-::
Send ->
return
@mnapoli
mnapoli / DDC1734Article.php
Created December 3, 2012 08:53
Test for Doctrine Issue DDC-1734
<?php
namespace Doctrine\Tests\Models\DDC1734;
/**
* @Entity
*/
class DDC1734Article
{
@mnapoli
mnapoli / SchemaValidationTest.php
Created December 10, 2012 09:56
Doctrine schema validation in a PHPUnit test
<?php
/**
* @author Matthieu Napoli
* @link http://en.mnapoli.fr/doctrine-schema-validation-in-a-phpunit-test/
* @license WTFPL - Do What The Fuck You Want To Public License (http://sam.zoy.org/wtfpl/)
*/
use Doctrine\ORM\Tools\SchemaValidator;
/**
@mnapoli
mnapoli / install.sh
Created December 13, 2012 14:33
Basic linux package installation for development
sudo apt-get install subversion git mercurial python perl ruby
@mnapoli
mnapoli / DI-Configuration.md
Last active December 15, 2015 06:19
PHP-DI alternative configuration options

Reflections on PHP-DI configuration.

Currently, the configuration is in PHP or annotations, PHP config has the following advantages:

  • PHP developpers know PHP
  • IDE autocompletion/error detection
  • Bean definition using closures

Disadvantages of PHP:

@mnapoli
mnapoli / optional singleton pattern.php
Last active December 15, 2015 07:09
"Optional singleton" pattern
<?php
// See also http://en.mnapoli.fr/the-optional-singleton-pattern/
class MyService
{
private static $singletonInstance = null;
/**
* Keep the constructor public
*/
@mnapoli
mnapoli / Gearman-Windows.md
Last active January 5, 2023 07:58
Installing Gearman on windows

Gearman can be installed on Windows through cygwin.

Install Cygwin packages

Install cygwin packages (through setup.exe):

  • gcc
  • make
  • libuuid1-devel
  • libiconv
@mnapoli
mnapoli / Collection.php
Last active December 16, 2015 16:49
Collection and Map interface
<?php
/**
* In this example, a collection is a map of values indexed by a key (numeric or string)
*/
interface Collection extends Countable, IteratorAggregate, ArrayAccess
{
function add($value);
function set($key, $value);