mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-14 03:46:25 +02:00
it was created the Behavioral namespace and append its patterns
This commit is contained in:
Behavioral
ChainOfResponsibilities
Command
Iterator
Mediator
NullObject
Observer
Specification
AbstractSpecification.phpEither.phpItem.phpNot.phpPlus.phpPriceSpecification.phpSpecificationInterface.phpSpecificationTest.php
State
Strategy
TemplateMethod
Visitor
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Behavioral\Tests\ChainOfResponsibilities;
|
||||
namespace DesignPatterns\Behavioral\ChainOfResponsibilities;
|
||||
|
||||
use DesignPatterns\Behavioral\ChainOfResponsibilities\Request;
|
||||
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Behavioral\Command\Tests;
|
||||
namespace DesignPatterns\Behavioral\Command;
|
||||
|
||||
use DesignPatterns\Behavioral\Command\Invoker;
|
||||
use DesignPatterns\Behavioral\Command\Receiver;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Behavioral\Iterator\Tests;
|
||||
namespace DesignPatterns\Behavioral\Iterator;
|
||||
|
||||
use DesignPatterns\Behavioral\Iterator\Book;
|
||||
use DesignPatterns\Behavioral\Iterator\BookList;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Mediator;
|
||||
namespace DesignPatterns\Behavioral\Mediator;
|
||||
|
||||
/**
|
||||
* Colleague is an abstract colleague who works together but he only knows
|
||||
|
@ -1,20 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Mediator;
|
||||
namespace DesignPatterns\Behavioral\Mediator;
|
||||
|
||||
use DesignPatterns\Mediator\Subsystem;
|
||||
use DesignPatterns\Behavioral\Mediator\Subsystem;
|
||||
|
||||
/**
|
||||
* Mediator is the concrete Mediator for this design pattern.
|
||||
*
|
||||
* In this example, I have made a "Hello World" with the Mediator Pattern.
|
||||
*/
|
||||
class Mediator implements MediatorInterface
|
||||
{
|
||||
|
||||
// you could have an array
|
||||
/**
|
||||
* @var Subsystem\Server
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
/**
|
||||
* @var Subsystem\Database
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* @var Subsystem\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
@ -39,7 +48,6 @@ class Mediator implements MediatorInterface
|
||||
|
||||
/**
|
||||
* query db
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function queryDb()
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Mediator;
|
||||
namespace DesignPatterns\Behavioral\Mediator;
|
||||
|
||||
/**
|
||||
* MediatorInterface is a contract for the Mediator
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace DesignPatterns\Tests\Mediator;
|
||||
|
||||
use DesignPatterns\Mediator\Mediator;
|
||||
use DesignPatterns\Mediator\Subsystem\Database;
|
||||
use DesignPatterns\Mediator\Subsystem\Client;
|
||||
use DesignPatterns\Mediator\Subsystem\Server;
|
||||
use DesignPatterns\Behavioral\Mediator\Mediator;
|
||||
use DesignPatterns\Behavioral\Mediator\Subsystem\Database;
|
||||
use DesignPatterns\Behavioral\Mediator\Subsystem\Client;
|
||||
use DesignPatterns\Behavioral\Mediator\Subsystem\Server;
|
||||
|
||||
/**
|
||||
* MediatorTest tests hello world
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Mediator\Subsystem;
|
||||
namespace DesignPatterns\Behavioral\Mediator\Subsystem;
|
||||
|
||||
use DesignPatterns\Mediator\Colleague;
|
||||
use DesignPatterns\Behavioral\Mediator\Colleague;
|
||||
|
||||
/**
|
||||
* Client is a client that make request et get response
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Mediator\Subsystem;
|
||||
namespace DesignPatterns\Behavioral\Mediator\Subsystem;
|
||||
|
||||
use DesignPatterns\Mediator\Colleague;
|
||||
use DesignPatterns\Behavioral\Mediator\Colleague;
|
||||
|
||||
/**
|
||||
* Database is a database service
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Mediator\Subsystem;
|
||||
namespace DesignPatterns\Behavioral\Mediator\Subsystem;
|
||||
|
||||
use DesignPatterns\Mediator\Colleague;
|
||||
use DesignPatterns\Behavioral\Mediator\Colleague;
|
||||
|
||||
/**
|
||||
* Server serves responses
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\NullObject;
|
||||
namespace DesignPatterns\Behavioral\NullObject;
|
||||
|
||||
/**
|
||||
* LoggerInterface is a contract for logging something
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Tests\NullObject;
|
||||
namespace DesignPatterns\Behavioral\NullObject;
|
||||
|
||||
use DesignPatterns\NullObject\NullLogger;
|
||||
use DesignPatterns\NullObject\Service;
|
||||
use DesignPatterns\NullObject\PrintLogger;
|
||||
use DesignPatterns\Behavioral\NullObject\NullLogger;
|
||||
use DesignPatterns\Behavioral\NullObject\Service;
|
||||
use DesignPatterns\Behavioral\NullObject\PrintLogger;
|
||||
|
||||
/**
|
||||
* LoggerTest tests for different loggers
|
||||
@ -24,7 +24,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
|
||||
public function testStandardLogger()
|
||||
{
|
||||
$service = new Service(new PrintLogger());
|
||||
$this->expectOutputString('We are in DesignPatterns\NullObject\Service::doSomething');
|
||||
$this->expectOutputString('We are in DesignPatterns\Behavioral\NullObject\Service::doSomething');
|
||||
$service->doSomething();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\NullObject;
|
||||
namespace DesignPatterns\Behavioral\NullObject;
|
||||
|
||||
/**
|
||||
* Performance concerns : ok there is a call for nothing but we spare an "if is_null"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\NullObject;
|
||||
namespace DesignPatterns\Behavioral\NullObject;
|
||||
|
||||
/**
|
||||
* PrintLogger is a logger that prints the log entry to standard output
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\NullObject;
|
||||
namespace DesignPatterns\Behavioral\NullObject;
|
||||
|
||||
/**
|
||||
* Service is dummy service that uses a logger
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Tests\Observer;
|
||||
namespace DesignPatterns\Behavioral\Observer;
|
||||
|
||||
use DesignPatterns\Observer\UserObserver;
|
||||
use DesignPatterns\Observer\User;
|
||||
use DesignPatterns\Behavioral\Observer\UserObserver;
|
||||
use DesignPatterns\Behavioral\Observer\User;
|
||||
|
||||
/**
|
||||
* ObserverTest tests the Observer pattern
|
||||
@ -23,7 +23,7 @@ class ObserverTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotify()
|
||||
{
|
||||
$this->expectOutputString('DesignPatterns\Observer\User has been updated');
|
||||
$this->expectOutputString('DesignPatterns\Behavioral\Observer\User has been updated');
|
||||
$subject = new User();
|
||||
|
||||
$subject->attach($this->observer);
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Observer;
|
||||
namespace DesignPatterns\Behavioral\Observer;
|
||||
|
||||
/**
|
||||
* Observer pattern : The observed object (the subject)
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Observer;
|
||||
namespace DesignPatterns\Behavioral\Observer;
|
||||
|
||||
/**
|
||||
* class UserObserver
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace DesignPatterns\Specification;
|
||||
namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
/**
|
||||
* An abstract specification allows the creation of wrapped specifications
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace DesignPatterns\Specification;
|
||||
namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
/**
|
||||
* A logical OR specification
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace DesignPatterns\Specification;
|
||||
namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
/**
|
||||
* An trivial item
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace DesignPatterns\Specification;
|
||||
namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
/**
|
||||
* A logical Not specification
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace DesignPatterns\Specification;
|
||||
namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
/**
|
||||
* A logical AND specification
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace DesignPatterns\Specification;
|
||||
namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
/**
|
||||
* A specification to check an Item is priced between min and max
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace DesignPatterns\Specification;
|
||||
namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
/**
|
||||
* An interface for a specification
|
||||
|
6
Behavioral/Specification/Test/SpecificationTest.php → Behavioral/Specification/SpecificationTest.php
6
Behavioral/Specification/Test/SpecificationTest.php → Behavioral/Specification/SpecificationTest.php
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Tests\Specification;
|
||||
namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
use DesignPatterns\Specification\PriceSpecification;
|
||||
use DesignPatterns\Specification\Item;
|
||||
use DesignPatterns\Behavioral\Specification\PriceSpecification;
|
||||
use DesignPatterns\Behavioral\Specification\Item;
|
||||
|
||||
/**
|
||||
* SpecificationTest tests the specification pattern
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Status;
|
||||
namespace DesignPatterns\Behavioral\State;
|
||||
|
||||
/**
|
||||
* Class CreateOrder
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Status;
|
||||
namespace DesignPatterns\Behavioral\State;
|
||||
|
||||
/**
|
||||
* Class OrderController
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Status;
|
||||
namespace DesignPatterns\Behavioral\State;
|
||||
|
||||
/**
|
||||
* Class OrderFactory
|
||||
@ -9,7 +9,7 @@ class OrderFactory
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
throw Exception('Can not instance the OrderFactory class!');
|
||||
throw new \Exception('Can not instance the OrderFactory class!');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Status;
|
||||
namespace DesignPatterns\Behavioral\State;
|
||||
|
||||
/**
|
||||
* Class OrderInterface
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Status;
|
||||
namespace DesignPatterns\Behavioral\State;
|
||||
|
||||
/**
|
||||
* Class ShippingOrder
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Strategy;
|
||||
namespace DesignPatterns\Behavioral\Strategy;
|
||||
|
||||
/**
|
||||
* Class ComparatorInterface
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Strategy;
|
||||
namespace DesignPatterns\Behavioral\Strategy;
|
||||
|
||||
/**
|
||||
* Class DateComparator
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Strategy;
|
||||
namespace DesignPatterns\Behavioral\Strategy;
|
||||
|
||||
/**
|
||||
* Class IdComparator
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Strategy;
|
||||
namespace DesignPatterns\Behavioral\Strategy;
|
||||
|
||||
/**
|
||||
* Class ObjectCollection
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Tests\Strategy;
|
||||
namespace DesignPatterns\Behavioral\Strategy;
|
||||
|
||||
use DesignPatterns\Strategy\DateComparator;
|
||||
use DesignPatterns\Strategy\IdComparator;
|
||||
use DesignPatterns\Strategy\ObjectCollection;
|
||||
use DesignPatterns\Strategy\Strategy;
|
||||
use DesignPatterns\Behavioral\Strategy\DateComparator;
|
||||
use DesignPatterns\Behavioral\Strategy\IdComparator;
|
||||
use DesignPatterns\Behavioral\Strategy\ObjectCollection;
|
||||
use DesignPatterns\Behavioral\Strategy\Strategy;
|
||||
|
||||
/**
|
||||
* Tests for Static Factory pattern
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\TemplateMethod;
|
||||
namespace DesignPatterns\Behavioral\TemplateMethod;
|
||||
|
||||
/**
|
||||
* BeachJourney is vacation at the beach
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\TemplateMethod;
|
||||
namespace DesignPatterns\Behavioral\TemplateMethod;
|
||||
|
||||
/**
|
||||
* CityJourney is a journey in a city
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\TemplateMethod;
|
||||
namespace DesignPatterns\Behavioral\TemplateMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Tests\TemplateMethod;
|
||||
namespace DesignPatterns\Behavioral\TemplateMethod;
|
||||
|
||||
use DesignPatterns\TemplateMethod;
|
||||
use DesignPatterns\Behavioral\TemplateMethod;
|
||||
|
||||
/**
|
||||
* JourneyTest tests all journeys
|
||||
@ -29,7 +29,7 @@ class JourneyTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testLasVegas()
|
||||
{
|
||||
$journey = $this->getMockForAbstractClass('DesignPatterns\TemplateMethod\Journey');
|
||||
$journey = $this->getMockForAbstractClass('DesignPatterns\Behavioral\TemplateMethod\Journey');
|
||||
$journey->expects($this->once())
|
||||
->method('enjoyVacation')
|
||||
->will($this->returnCallback(array($this, 'mockUpVacation')));
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Visitor;
|
||||
namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
/**
|
||||
* An example of a Visitor: Group
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Visitor;
|
||||
namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
/**
|
||||
* class Role
|
||||
@ -12,7 +12,7 @@ abstract class Role
|
||||
*
|
||||
* Feel free to override it if your object must call another visiting behavior
|
||||
*
|
||||
* @param \DesignPatterns\Visitor\RoleVisitorInterface $visitor
|
||||
* @param \DesignPatterns\Behavioral\Visitor\RoleVisitorInterface $visitor
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Visitor;
|
||||
namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
/**
|
||||
* Visitor Pattern
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Visitor;
|
||||
namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
/**
|
||||
* Visitor Pattern
|
||||
@ -18,14 +18,14 @@ interface RoleVisitorInterface
|
||||
/**
|
||||
* Visit a User object
|
||||
*
|
||||
* @param \DesignPatterns\Visitor\User $role
|
||||
* @param \DesignPatterns\Behavioral\Visitor\User $role
|
||||
*/
|
||||
public function visitUser(User $role);
|
||||
|
||||
/**
|
||||
* Visit a Group object
|
||||
*
|
||||
* @param \DesignPatterns\Visitor\Group $role
|
||||
* @param \DesignPatterns\Behavioral\Visitor\Group $role
|
||||
*/
|
||||
public function visitGroup(Group $role);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Visitor;
|
||||
namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
/**
|
||||
* Visitor Pattern
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace DesignPatterns\Tests\Visitor;
|
||||
|
||||
use DesignPatterns\Visitor;
|
||||
use DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
/**
|
||||
* VisitorTest tests the visitor pattern
|
||||
@ -40,7 +40,7 @@ class VisitorTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testUnknownObject()
|
||||
{
|
||||
$mock = $this->getMockForAbstractClass('DesignPatterns\Visitor\Role');
|
||||
$mock = $this->getMockForAbstractClass('DesignPatterns\Behavioral\Visitor\Role');
|
||||
$mock->accept($this->visitor);
|
||||
}
|
||||
|
@ -3,7 +3,10 @@
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Design Patterns">
|
||||
<directory>./Tests</directory>
|
||||
<directory>./Behavioral/*/*Test.php</directory>
|
||||
<directory>./Creational/*/*/Test.php</directory>
|
||||
<directory>./More/*/*/Test.php</directory>
|
||||
<directory>./Structural/*/*/Test.php</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
|
Reference in New Issue
Block a user