Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / DI containers summary.md
Last active May 7, 2018 07:58
DI containers usage comparison
@mnapoli
mnapoli / friend-services.php
Created August 9, 2013 14:58
Tryout with Friend services
<?php
// http://3v4l.org/e9RNO
class Foo {
private $bar = 'hello world';
}
class FriendOfFoo {
public function doSomething($foo) {
return function() use ($foo) {
@mnapoli
mnapoli / gist:6864216
Last active December 24, 2015 21:19
Doctrine Expression API
<?php
interface Updatable
{
public function apply(Expression $e);
}
// Solution 1
// More powerful, but needs to parse and evaluate the string
class Expression
{
@mnapoli
mnapoli / aaa.md
Last active December 25, 2015 00:49
Thoughts for PHP-DI 4.0

The point of all this is that maybe YAML should be dropped altogether in favor of PHP definitions.

YAML is less verbose, but since PHP 5.4 (short arrays) and 5.5 (short class names) it's even.

Advantages of PHP:

  • autocompletion
  • refactoring support
  • click to go to a class
  • definitions using callbacks
@mnapoli
mnapoli / gist:6988778
Last active December 25, 2015 14:09
Anonymous classes FTW
<?php
class MyTest extends PHPUnit_Framework_TestCase
{
public function testSomeStuff()
{
// Build my mock
$mock = new class extends CrawlerInterface {
public function crawl($url) {
return ['some', 'data'];
@mnapoli
mnapoli / gist:7428000
Created November 12, 2013 09:25 — forked from incredimike/config.inc.php
Default phpMyAdmin configuration for exports.
<?php
# Add the following to /etc/phpmyadmin/conf.d/export.inc.php
$cfg['Export']['sql_drop_database'] = true;
$cfg['Export']['sql_drop_table'] = true;
$cfg['Export']['compression'] = 'zip';
$cfg['Export']['sql_disable_fk'] = true;
$cfg['Export']['sql_use_transaction'] = true;
@mnapoli
mnapoli / gist:7471722
Created November 14, 2013 18:21
Factory methods
<?php
class Image
{
private $width;
private $height;
private $content;
public static function createEmpty($width, $height, $bgcolor = null)
{