mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-17 13:21:17 +02:00
it was created the Creational namespace and append its patterns
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory;
|
namespace DesignPatterns\Creational\AbstractFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class AbstractFactory
|
* class AbstractFactory
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\AbstractFactory;
|
namespace DesignPatterns\Creational\AbstractFactory;
|
||||||
|
|
||||||
use DesignPatterns\AbstractFactory\AbstractFactory;
|
use DesignPatterns\Creational\AbstractFactory\AbstractFactory;
|
||||||
use DesignPatterns\AbstractFactory\HtmlFactory;
|
use DesignPatterns\Creational\AbstractFactory\HtmlFactory;
|
||||||
use DesignPatterns\AbstractFactory\JsonFactory;
|
use DesignPatterns\Creational\AbstractFactory\JsonFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractFactoryTest tests concrete factories
|
* AbstractFactoryTest tests concrete factories
|
||||||
@@ -34,7 +34,7 @@ class AbstractFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$factory->createText('footnotes')
|
$factory->createText('footnotes')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertContainsOnly('DesignPatterns\AbstractFactory\MediaInterface', $article);
|
$this->assertContainsOnly('DesignPatterns\Creational\AbstractFactory\MediaInterface', $article);
|
||||||
|
|
||||||
/* this is the time to look at the Builder pattern. This pattern
|
/* this is the time to look at the Builder pattern. This pattern
|
||||||
* helps you to create complex object like that article above with
|
* helps you to create complex object like that article above with
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory\Html;
|
namespace DesignPatterns\Creational\AbstractFactory\Html;
|
||||||
|
|
||||||
use DesignPatterns\AbstractFactory\Picture as BasePicture;
|
use DesignPatterns\Creational\AbstractFactory\Picture as BasePicture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Picture
|
* Class Picture
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory\Html;
|
namespace DesignPatterns\Creational\AbstractFactory\Html;
|
||||||
|
|
||||||
use DesignPatterns\AbstractFactory\Text as BaseText;
|
use DesignPatterns\Creational\AbstractFactory\Text as BaseText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Text
|
* Class Text
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory;
|
namespace DesignPatterns\Creational\AbstractFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class HtmlFactory
|
* Class HtmlFactory
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory\Json;
|
namespace DesignPatterns\Creational\AbstractFactory\Json;
|
||||||
|
|
||||||
use DesignPatterns\AbstractFactory\Picture as BasePicture;
|
use DesignPatterns\Creational\AbstractFactory\Picture as BasePicture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Picture
|
* Class Picture
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory\Json;
|
namespace DesignPatterns\Creational\AbstractFactory\Json;
|
||||||
|
|
||||||
use DesignPatterns\AbstractFactory\Text as BaseText;
|
use DesignPatterns\Creational\AbstractFactory\Text as BaseText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Text
|
* Class Text
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory;
|
namespace DesignPatterns\Creational\AbstractFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class JsonFactory
|
* Class JsonFactory
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory;
|
namespace DesignPatterns\Creational\AbstractFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface MediaInterface
|
* Interface MediaInterface
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory;
|
namespace DesignPatterns\Creational\AbstractFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Picture
|
* Class Picture
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\AbstractFactory;
|
namespace DesignPatterns\Creational\AbstractFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Text
|
* Class Text
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder;
|
namespace DesignPatterns\Creational\Builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BikeBuilder builds bike
|
* BikeBuilder builds bike
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder;
|
namespace DesignPatterns\Creational\Builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder;
|
namespace DesignPatterns\Creational\Builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CarBuilder builds car
|
* CarBuilder builds car
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder;
|
namespace DesignPatterns\Creational\Builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Director is part of the builder pattern. It knows the interface of the builder
|
* Director is part of the builder pattern. It knows the interface of the builder
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\Builder;
|
namespace DesignPatterns\Creational\Builder;
|
||||||
|
|
||||||
use DesignPatterns\Builder\Director;
|
use DesignPatterns\Creational\Builder\Director;
|
||||||
use DesignPatterns\Builder\CarBuilder;
|
use DesignPatterns\Creational\Builder\CarBuilder;
|
||||||
use DesignPatterns\Builder\BikeBuilder;
|
use DesignPatterns\Creational\Builder\BikeBuilder;
|
||||||
use DesignPatterns\Builder\BuilderInterface;
|
use DesignPatterns\Creational\Builder\BuilderInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DirectorTest tests the builder pattern
|
* DirectorTest tests the builder pattern
|
||||||
@@ -37,6 +37,6 @@ class DirectorTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testBuild(BuilderInterface $builder)
|
public function testBuild(BuilderInterface $builder)
|
||||||
{
|
{
|
||||||
$newVehicle = $this->director->build($builder);
|
$newVehicle = $this->director->build($builder);
|
||||||
$this->assertInstanceOf('DesignPatterns\Builder\Parts\Vehicle', $newVehicle);
|
$this->assertInstanceOf('DesignPatterns\Creational\Builder\Parts\Vehicle', $newVehicle);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder\Parts;
|
namespace DesignPatterns\Creational\Builder\Parts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bike is a bike
|
* Bike is a bike
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder\Parts;
|
namespace DesignPatterns\Creational\Builder\Parts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Car is a car
|
* Car is a car
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder\Parts;
|
namespace DesignPatterns\Creational\Builder\Parts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Door
|
* Class Door
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder\Parts;
|
namespace DesignPatterns\Creational\Builder\Parts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Engine
|
* Class Engine
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder\Parts;
|
namespace DesignPatterns\Creational\Builder\Parts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VehicleInterface is a contract for a vehicle
|
* VehicleInterface is a contract for a vehicle
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Builder\Parts;
|
namespace DesignPatterns\Creational\Builder\Parts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Wheel
|
* Class Wheel
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\FactoryMethod;
|
namespace DesignPatterns\Creational\FactoryMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bicycle is a bicycle
|
* Bicycle is a bicycle
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\FactoryMethod;
|
namespace DesignPatterns\Creational\FactoryMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class FactoryMethod
|
* class FactoryMethod
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\FactoryMethod;
|
namespace DesignPatterns\Creational\FactoryMethod;
|
||||||
|
|
||||||
use DesignPatterns\FactoryMethod\FactoryMethod;
|
use DesignPatterns\Creational\FactoryMethod\FactoryMethod;
|
||||||
use DesignPatterns\FactoryMethod\GermanFactory;
|
use DesignPatterns\Creational\FactoryMethod\GermanFactory;
|
||||||
use DesignPatterns\FactoryMethod\ItalianFactory;
|
use DesignPatterns\Creational\FactoryMethod\ItalianFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FactoryMethodTest tests the factory method pattern
|
* FactoryMethodTest tests the factory method pattern
|
||||||
@@ -34,7 +34,7 @@ class FactoryMethodTest extends \PHPUnit_Framework_TestCase
|
|||||||
// about the factory, all we know is it can produce vehicle
|
// about the factory, all we know is it can produce vehicle
|
||||||
foreach ($this->type as $oneType) {
|
foreach ($this->type as $oneType) {
|
||||||
$vehicle = $shop->create($oneType);
|
$vehicle = $shop->create($oneType);
|
||||||
$this->assertInstanceOf('DesignPatterns\FactoryMethod\VehicleInterface', $vehicle);
|
$this->assertInstanceOf('DesignPatterns\Creational\FactoryMethod\VehicleInterface', $vehicle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\FactoryMethod;
|
namespace DesignPatterns\Creational\FactoryMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ferrari is a italian car
|
* Ferrari is a italian car
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\FactoryMethod;
|
namespace DesignPatterns\Creational\FactoryMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GermanFactory is a vehicle factory in Germany
|
* GermanFactory is a vehicle factory in Germany
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\FactoryMethod;
|
namespace DesignPatterns\Creational\FactoryMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ItalianFactory is vehicle factory in Italy
|
* ItalianFactory is vehicle factory in Italy
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\FactoryMethod;
|
namespace DesignPatterns\Creational\FactoryMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Porsche is a german car
|
* Porsche is a german car
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\FactoryMethod;
|
namespace DesignPatterns\Creational\FactoryMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VehicleInterface is a contract for a vehicle
|
* VehicleInterface is a contract for a vehicle
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns;
|
namespace DesignPatterns\Creational\Multiton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Multiton
|
* class Multiton
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Pool;
|
namespace DesignPatterns\Creational\Pool;
|
||||||
|
|
||||||
class Pool
|
class Pool
|
||||||
{
|
{
|
@@ -1,14 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\Pool;
|
namespace DesignPatterns\Creational\Pool;
|
||||||
|
|
||||||
use DesignPatterns\Pool\Pool;
|
use DesignPatterns\Creational\Pool\Pool;
|
||||||
|
|
||||||
class TestWorker
|
class TestWorker
|
||||||
{
|
{
|
||||||
|
|
||||||
public $id = 1;
|
public $id = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PoolTest extends \PHPUnit_Framework_TestCase
|
class PoolTest extends \PHPUnit_Framework_TestCase
|
||||||
@@ -16,7 +15,7 @@ class PoolTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testPool()
|
public function testPool()
|
||||||
{
|
{
|
||||||
$pool = new Pool('DesignPatterns\Tests\Pool\TestWorker');
|
$pool = new Pool('DesignPatterns\Creational\Pool\TestWorker');
|
||||||
$worker = $pool->get();
|
$worker = $pool->get();
|
||||||
|
|
||||||
$this->assertEquals(1, $worker->id);
|
$this->assertEquals(1, $worker->id);
|
||||||
@@ -27,6 +26,5 @@ class PoolTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(5, $pool->get()->id);
|
$this->assertEquals(5, $pool->get()->id);
|
||||||
$this->assertEquals(1, $pool->get()->id);
|
$this->assertEquals(1, $pool->get()->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Pool;
|
namespace DesignPatterns\Creational\Pool;
|
||||||
|
|
||||||
class Processor
|
class Processor
|
||||||
{
|
{
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Pool;
|
namespace DesignPatterns\Creational\Pool;
|
||||||
|
|
||||||
class Worker
|
class Worker
|
||||||
{
|
{
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Prototype;
|
namespace DesignPatterns\Creational\Prototype;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BarBookPrototype
|
* Class BarBookPrototype
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Prototype;
|
namespace DesignPatterns\Creational\Prototype;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class BookPrototype
|
* class BookPrototype
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Prototype;
|
namespace DesignPatterns\Creational\Prototype;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FooBookPrototype
|
* Class FooBookPrototype
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Prototype;
|
namespace DesignPatterns\Creational\Prototype;
|
||||||
|
|
||||||
$fooPrototype = new FooBookPrototype();
|
$fooPrototype = new FooBookPrototype();
|
||||||
$barPrototype = new BarBookPrototype();
|
$barPrototype = new BarBookPrototype();
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\SimpleFactory;
|
namespace DesignPatterns\Creational\SimpleFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bicycle is a bicycle
|
* Bicycle is a bicycle
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\SimpleFactory;
|
namespace DesignPatterns\Creational\SimpleFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class ConcreteFactory
|
* class ConcreteFactory
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\SimpleFactory;
|
namespace DesignPatterns\Creational\SimpleFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scooter is a Scooter
|
* Scooter is a Scooter
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\SimpleFactory;
|
namespace DesignPatterns\Creational\SimpleFactory;
|
||||||
|
|
||||||
use DesignPatterns\SimpleFactory\ConcreteFactory;
|
use DesignPatterns\Creational\SimpleFactory\ConcreteFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SimpleFactoryTest tests the Simple Factory pattern
|
* SimpleFactoryTest tests the Simple Factory pattern
|
||||||
@@ -31,7 +31,7 @@ class SimpleFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testCreation($type)
|
public function testCreation($type)
|
||||||
{
|
{
|
||||||
$obj = $this->factory->createVehicle($type);
|
$obj = $this->factory->createVehicle($type);
|
||||||
$this->assertInstanceOf('DesignPatterns\SimpleFactory\VehicleInterface', $obj);
|
$this->assertInstanceOf('DesignPatterns\Creational\SimpleFactory\VehicleInterface', $obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\SimpleFactory;
|
namespace DesignPatterns\Creational\SimpleFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VehicleInterface is a contract for a vehicle
|
* VehicleInterface is a contract for a vehicle
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Singleton;
|
namespace DesignPatterns\Creational\Singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Singleton
|
* class Singleton
|
||||||
@@ -8,7 +8,7 @@ namespace DesignPatterns\Singleton;
|
|||||||
class Singleton
|
class Singleton
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var cached reference to singleton instance
|
* @var Singleton reference to singleton instance
|
||||||
*/
|
*/
|
||||||
private static $instance;
|
private static $instance;
|
||||||
|
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\Singleton;
|
namespace DesignPatterns\Creational\Singleton;
|
||||||
|
|
||||||
use DesignPatterns\Singleton\Singleton;
|
use DesignPatterns\Creational\Singleton\Singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SingletonTest tests the singleton pattern
|
* SingletonTest tests the singleton pattern
|
||||||
@@ -13,7 +13,7 @@ class SingletonTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testUniqueness()
|
public function testUniqueness()
|
||||||
{
|
{
|
||||||
$firstCall = Singleton::getInstance();
|
$firstCall = Singleton::getInstance();
|
||||||
$this->assertInstanceOf('DesignPatterns\Singleton\Singleton', $firstCall);
|
$this->assertInstanceOf('DesignPatterns\Creational\Singleton\Singleton', $firstCall);
|
||||||
$secondCall = Singleton::getInstance();
|
$secondCall = Singleton::getInstance();
|
||||||
$this->assertSame($firstCall, $secondCall);
|
$this->assertSame($firstCall, $secondCall);
|
||||||
}
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\StaticFactory;
|
namespace DesignPatterns\Creational\StaticFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FormatNumber
|
* Class FormatNumber
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\StaticFactory;
|
namespace DesignPatterns\Creational\StaticFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FormatString
|
* Class FormatString
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\StaticFactory;
|
namespace DesignPatterns\Creational\StaticFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FormatterInterface
|
* Class FormatterInterface
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\StaticFactory;
|
namespace DesignPatterns\Creational\StaticFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note1: Remember, static => global => evil
|
* Note1: Remember, static => global => evil
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace DesignPatterns\Tests\StaticFactory;
|
namespace DesignPatterns\Creational\StaticFactory;
|
||||||
|
|
||||||
use DesignPatterns\StaticFactory\StaticFactory;
|
use DesignPatterns\Creational\StaticFactory\StaticFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for Static Factory pattern
|
* Tests for Static Factory pattern
|
||||||
@@ -25,6 +25,6 @@ class StaticFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testCreation($type)
|
public function testCreation($type)
|
||||||
{
|
{
|
||||||
$obj = StaticFactory::factory($type);
|
$obj = StaticFactory::factory($type);
|
||||||
$this->assertInstanceOf('DesignPatterns\StaticFactory\FormatterInterface', $obj);
|
$this->assertInstanceOf('DesignPatterns\Creational\StaticFactory\FormatterInterface', $obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use DesignPatterns\Pool\Pool;
|
|
||||||
use DesignPatterns\Pool\Processor;
|
|
||||||
|
|
||||||
$pool = new Pool('DesignPatterns\Pool\Worker');
|
|
||||||
$processor = new Processor($pool);
|
|
||||||
|
|
||||||
$processor->process('image1.jpg');
|
|
||||||
$processor->process('image2.jpg');
|
|
||||||
$processor->process('image3.jpg');
|
|
||||||
$processor->process('image4.jpg');
|
|
||||||
$processor->process('image5.jpg');
|
|
||||||
$processor->process('image6.jpg');
|
|
||||||
$processor->process('image7.jpg');
|
|
||||||
$processor->process('image8.jpg');
|
|
Reference in New Issue
Block a user