This commit is contained in:
Dominik Liebler
2013-09-13 14:19:55 +02:00
parent 8452c63b7e
commit 8b82ed198d
47 changed files with 93 additions and 218 deletions

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Adapter;
/**

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Builder;
/**

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Builder;
/**
@ -20,14 +16,28 @@ namespace DesignPatterns\Builder;
*/
interface Builder
{
/**
* @return mixed
*/
public function createVehicle();
function createVehicle();
/**
* @return mixed
*/
public function addWheel();
function addWheel();
/**
* @return mixed
*/
public function addEngine();
function addEngine();
/**
* @return mixed
*/
public function addDoors();
function addDoors();
function getVehicle();
/**
* @return mixed
*/
public function getVehicle();
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Builder;
/**
@ -42,5 +38,4 @@ class CarBuilder implements Builder
{
return $this->car;
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Builder;
/**

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Builder\Parts;
/**

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Builder\Parts;
/**

@ -2,6 +2,9 @@
namespace DesignPatterns\Builder\Parts;
/**
* Class Door
*/
class Door
{

@ -2,6 +2,9 @@
namespace DesignPatterns\Builder\Parts;
/**
* Class Engine
*/
class Engine
{

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Builder\Parts;
/**
@ -11,12 +7,17 @@ namespace DesignPatterns\Builder\Parts;
*/
abstract class Vehicle
{
/**
* @var array
*/
protected $data;
/**
* @param string $key
* @param mixed $value
*/
public function setPart($key, $value)
{
$this->data[$key] = $value;
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\ChainOfResponsibilities;
/**
@ -16,7 +12,9 @@ namespace DesignPatterns\ChainOfResponsibilities;
*/
abstract class Handler
{
/**
* @var null
*/
private $successor = null;
/**

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\ChainOfResponsibilities;
/**

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\ChainOfResponsibilities\Responsible;
use DesignPatterns\ChainOfResponsibilities\Handler;
@ -33,5 +29,4 @@ class FastStorage extends Handler
return false;
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\ChainOfResponsibilities\Responsible;
use DesignPatterns\ChainOfResponsibilities\Handler;
@ -21,9 +17,14 @@ use DesignPatterns\ChainOfResponsibilities\Request;
*/
class SlowStorage extends Handler
{
/**
* @var array
*/
protected $_data = array();
/**
* @param array $data
*/
public function __construct($data = array())
{
$this->_data = $data;
@ -34,11 +35,11 @@ class SlowStorage extends Handler
if ('get' === $req->verb) {
if (array_key_exists($req->key, $this->_data)) {
$req->response = $this->_data[$req->key];
return true;
}
}
return false;
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Command;
/**

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Command;
/**

@ -5,7 +5,7 @@ namespace DesignPatterns\FactoryMethod;
/**
* Bicycle is a bicycle
*/
class Bicycle implements Vehicle
class Bicycle implements VehicleInterface
{
/**
* @var string

@ -28,7 +28,7 @@ abstract class FactoryMethod
*
* @param string $type a generic type
*
* @return Vehicle a new vehicle
* @return VehicleInterface a new vehicle
*/
abstract protected function createVehicle($type);
@ -37,7 +37,7 @@ abstract class FactoryMethod
*
* @param int $type
*
* @return Vehicle a new vehicle
* @return VehicleInterface a new vehicle
*/
public function create($type)
{

@ -5,7 +5,7 @@ namespace DesignPatterns\FactoryMethod;
/**
* Ferrari is a italian car
*/
class Ferrari implements Vehicle
class Ferrari implements VehicleInterface
{
/**
* @var string

@ -5,7 +5,7 @@ namespace DesignPatterns\FactoryMethod;
/**
* Porsche is a german car
*/
class Porsche implements Vehicle
class Porsche implements VehicleInterface
{
/**
* @var string

@ -3,14 +3,14 @@
namespace DesignPatterns\FactoryMethod;
/**
* Vehicle is a contract for a vehicle
* VehicleInterface is a contract for a vehicle
*/
interface Vehicle
interface VehicleInterface
{
/**
* sets the color of the vehicle
*
* @param string $rgb
*/
function setColor($rgb);
public function setColor($rgb);
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Mediator;
/**
@ -12,8 +8,11 @@ namespace DesignPatterns\Mediator;
*/
abstract class Colleague
{
// this ensures no change in subclasses
/**
* this ensures no change in subclasses
*
* @var MediatorInterface
*/
private $mediator;
// for subclasses
@ -22,10 +21,12 @@ abstract class Colleague
return $this->mediator;
}
/**
* @param MediatorInterface $medium
*/
public function __construct(MediatorInterface $medium)
{
// in this way, we are sure the concrete colleague knows the mediator
$this->mediator = $medium;
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Mediator;
use DesignPatterns\Mediator\Subsystem;

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Mediator\Subsystem;
use DesignPatterns\Mediator\Colleague;

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Mediator\Subsystem;
use DesignPatterns\Mediator\Colleague;

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Mediator\Subsystem;
use DesignPatterns\Mediator\Colleague;
@ -19,5 +15,4 @@ class Server extends Colleague
$data = $this->getMediator()->queryDb();
$this->getMediator()->sendResponse("Hello $data");
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\Adapter;
use DesignPatterns\Adapter\EBookAdapter;
@ -42,5 +38,4 @@ class AdapterTest extends \PHPUnit_Framework_TestCase
$book->open();
$book->turnPage();
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\Builder;
use DesignPatterns\Builder\Director;
@ -42,5 +38,4 @@ class DirectorTest extends \PHPUnit_Framework_TestCase
$newVehicle = $this->director->build($builder);
$this->assertInstanceOf('DesignPatterns\Builder\Parts\Vehicle', $newVehicle);
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\ChainOfResponsibilities;
use DesignPatterns\ChainOfResponsibilities\Request;
@ -74,5 +70,4 @@ class ChainTest extends \PHPUnit_Framework_TestCase
// the last rsponsible :
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly);
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\Command;
use DesignPatterns\Command\Invoker;
@ -32,5 +28,4 @@ class CommandTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString('Hello World');
$this->invoker->run();
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Test\Composite;
use DesignPatterns\Composite;
@ -35,5 +31,4 @@ class FormTest extends \PHPUnit_Framework_TestCase
{
$this->assertTrue(is_subclass_of('DesignPatterns\Composite\Form', 'DesignPatterns\Composite\FormElement'));
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Test\DataMapper;
use DesignPatterns\DataMapper\UserMapper;
@ -106,5 +102,4 @@ class UserMapperTest extends \PHPUnit_Framework_TestCase
$user = $this->mapper->findById(404);
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\Decorator;
use DesignPatterns\Decorator;
@ -64,5 +60,4 @@ class DecoratorTest extends \PHPUnit_Framework_TestCase
$dec = $this->getMockForAbstractClass('DesignPatterns\Decorator\Decorator', array($mock));
$this->assertNotNull($dec);
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\Facade;
use DesignPatterns\Facade\Facade as Computer;
@ -46,5 +42,4 @@ class FacadeTest extends \PHPUnit_Framework_TestCase
// but I can access to lower component
$this->assertEquals('Linux', $os->getName());
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\FactoryMethod;
use DesignPatterns\FactoryMethod\FactoryMethod;
@ -38,7 +34,7 @@ class FactoryMethodTest extends \PHPUnit_Framework_TestCase
// about the factory, all we know is it can produce vehicle
foreach ($this->type as $oneType) {
$vehicle = $shop->create($oneType);
$this->assertInstanceOf('DesignPatterns\FactoryMethod\Vehicle', $vehicle);
$this->assertInstanceOf('DesignPatterns\FactoryMethod\VehicleInterface', $vehicle);
}
}
@ -51,5 +47,4 @@ class FactoryMethodTest extends \PHPUnit_Framework_TestCase
{
$shop->create('spaceship');
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\FluentInterface;
use DesignPatterns\FluentInterface\SQL;
@ -24,5 +20,4 @@ class FluentInterfaceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('SELECT foo,bar FROM foobar AS f WHERE f.bar = ?', $query);
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\Iterator;
use DesignPatterns\Iterator\CardGame;
@ -64,5 +60,4 @@ class IteratorTest extends \PHPUnit_Framework_TestCase
$newDeck->append(new \ArrayIterator($joker));
$this->assertCount(33, $newDeck);
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\Mediator;
use DesignPatterns\Mediator\Mediator;
@ -35,5 +31,4 @@ class MediatorTest extends \PHPUnit_Framework_TestCase
// Anyway, it remains complexity in the Mediator that's why the pattern
// Observer is preferable in mnay situations.
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\NullObject;
use DesignPatterns\NullObject\NullLogger;
@ -31,5 +27,4 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString('We are in DesignPatterns\NullObject\Service::doSomething');
$service->doSomething();
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\SimpleFactory;
use DesignPatterns\SimpleFactory\ConcreteFactory;

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\Singleton;
use DesignPatterns\Singleton\Singleton;
@ -30,5 +26,4 @@ class SingletonTest extends \PHPUnit_Framework_TestCase
$meth = $refl->getMethod('__construct');
$this->assertTrue($meth->isPrivate());
}
}

@ -27,5 +27,4 @@ class StaticFactoryTest extends \PHPUnit_Framework_TestCase
$obj = StaticFactory::factory($type);
$this->assertInstanceOf('DesignPatterns\StaticFactory\FormatterInterface', $obj);
}
}

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\TemplateMethod;
use DesignPatterns\TemplateMethod;

@ -1,9 +1,5 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Tests\Visitor;
use DesignPatterns\Visitor;