Skip to content

Instantly share code, notes, and snippets.

@mnapoli
mnapoli / DI containers summary.md
Last active May 7, 2018 07:58
DI containers usage comparison
@mnapoli
mnapoli / gist:5900314
Last active December 19, 2015 04:49
Controller as services with Property Injection
<?php
class UserController
{
/**
* @Inject
* @var RouterInterface
*/
private $router;
/**
@mnapoli
mnapoli / gist:5874705
Last active December 19, 2015 01:19
PHP 5.5 ::class feature
<?php
use A\Long\Namespace\User;
use Some\Namespace\ProductService;
// Doctrine: get entity
$user = $entityManager->find('A\Long\Namespace\User', 1234);
$user = $entityManager->find(User::class, 1234);
// Doctrine repositories
@mnapoli
mnapoli / behat-reference.feature
Last active February 12, 2024 10:54
Behat Mink reference
# Given
Given I am on [the] homepage
Given I am on "url"
# When
When I go to [the] homepage
When I go to "url"
When I reload the page
@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);
@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 / 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 / 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 / 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 / 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;
/**