Skip to content

Instantly share code, notes, and snippets.

View beberlei's full-sized avatar
💯

Benjamin Eberlei beberlei

💯
View GitHub Profile
@beberlei
beberlei / http.php
Created March 25, 2012 08:29
pecl/http API suggestions
<?php
// Case 1: Current API - Untestable without direct HTTP Connection to Amazon
class MyAmazonService
{
public function getItems($searchTerm)
{
$request = (new http\Request\Factory)->createRequest();
$response = $reqeust->setUrl("http://www.amazon.de/search?terms=" . $searchTerm)->send();
<?php
namespace Beberlei\WorkflowBundle\Tests\EndToEnd;
use Beberlei\WorkflowBundle\Tests\ControllerTestCase;
class WorkflowActivityExecutionTest extends ControllerTestCase
{
public function testScenario()
{
@beberlei
beberlei / README.md
Created February 8, 2012 08:25
Collection Filters - Readme Driven Development

Filter Language for Collections

Why?

You often need subsets of objects in a collection and want to access them efficiently in your domain model. But you certainly don't want to access the EntityManager or any other object manager here to craft a query. FilterExpressions for collections allow to go back to the database and query for all objects matching the crafted expression. Additionally they also work against in meemory ArrayCollection exactly the same. This way you don't (except for the SQL performance when it haunts you ;)) have to think about the context and can focus on your domain logic.

In Doctrine ORM this will be done by building DQL under the hood, in memory it will be done using Collection#filter(Closure $closure);

Technical Requirements:

@beberlei
beberlei / build.sh
Created January 14, 2012 18:21
ZeroMQ Server (REQ-REP) that embeds PHP
cd /path/php-5.3.9
./configure --enable-embedd
ln -s /path/php-5.3.9/libs/libphp5.so /usr/lib/libphp5.so
ldconfig
g++ -o zmqembed zmqembed.c -I/path/php-5.3.9 -I/path/php-5.3.9/main -I/path/php-5.3.9/Zend -I/path/php-5.3.9/TSRM -L/path/php-5.3.9/libs -lphp5 -lzmq
@beberlei
beberlei / packages_phpunit.php
Created January 4, 2012 23:33
Script to generate packages.json of PHPUnit + dependencies
<?php
/**
* Generates a package JSON that allows to install phpunit + dependencies
* from versions 3.5.12 up to now.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*
* @example
*
* {
@beberlei
beberlei / composer.json
Created December 12, 2011 10:39
A minimal Symfony Components Framework
{
"require": {
"php": ">=5.3.2",
"symfony/symfony": "2.1-dev"
}
}
@beberlei
beberlei / packagist_proxy.php
Created December 9, 2011 21:09
Composer/Packagist Proxy
<?php
$baseUrl = "http://localhost/packagist";
$baseDir = "/var/www/packagist";
if (!file_exists($baseDir)) {
echo "Base dir $baseDir for local packagist proxy does not exist\n";
exit(1);
}
$packagesJson = $baseDir . "/packages.json";
@beberlei
beberlei / MyWebTestCase.php
Created September 17, 2011 12:14
Easily Inject authenticated Symfony User into functional test
<?php
use Liip\FunctionalTestBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @group functional
*/
@beberlei
beberlei / DateTimeConverter.php
Created August 15, 2011 17:53
DateTime converter
<?php
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Convert a date from the request to a DateTime instance.
*
* The semantics are controller semantics $varDate matches to a route parameter {var}
@beberlei
beberlei / workflow.php
Created August 9, 2011 20:34
SheldonWinsFriend-Workflow
<?php
/**
* Sheldons Friend Making Algorithm for ezcWorkflow (with CouchDB backend (yet to be released))
*
* Code shall not be reused without my permission, it is only for teaching purposes.
*
* kontakt@beberlei.de
*/
require_once "ezc/Base/base.php";