mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-01-17 13:38:18 +01:00
remove Interface-Suffix
This commit is contained in:
parent
27bd89dd63
commit
9cb7660704
@ -20,7 +20,7 @@ class Group implements Role
|
||||
return sprintf('Group: %s', $this->name);
|
||||
}
|
||||
|
||||
public function accept(RoleVisitorInterface $visitor)
|
||||
public function accept(RoleVisitor $visitor)
|
||||
{
|
||||
$visitor->visitGroup($this);
|
||||
}
|
||||
|
@ -25,18 +25,18 @@ Code
|
||||
|
||||
You can also find this code on `GitHub`_
|
||||
|
||||
RoleVisitorInterface.php
|
||||
|
||||
.. literalinclude:: RoleVisitorInterface.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
RoleVisitor.php
|
||||
|
||||
.. literalinclude:: RoleVisitor.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
RecordingVisitor.php
|
||||
|
||||
.. literalinclude:: RecordingVisitor.php
|
||||
:language: php
|
||||
:linenos:
|
||||
|
||||
Role.php
|
||||
|
||||
.. literalinclude:: Role.php
|
||||
@ -65,4 +65,4 @@ Tests/VisitorTest.php
|
||||
:linenos:
|
||||
|
||||
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Visitor
|
||||
.. __: http://en.wikipedia.org/wiki/Visitor_pattern
|
||||
.. __: http://en.wikipedia.org/wiki/Visitor_pattern
|
||||
|
30
Behavioral/Visitor/RecordingVisitor.php
Normal file
30
Behavioral/Visitor/RecordingVisitor.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
class RecordingVisitor implements RoleVisitor
|
||||
{
|
||||
/**
|
||||
* @var Role[]
|
||||
*/
|
||||
private $visited = [];
|
||||
|
||||
public function visitGroup(Group $role)
|
||||
{
|
||||
$this->visited[] = $role;
|
||||
}
|
||||
|
||||
public function visitUser(User $role)
|
||||
{
|
||||
$this->visited[] = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Role[]
|
||||
*/
|
||||
public function getVisited(): array
|
||||
{
|
||||
return $this->visited;
|
||||
}
|
||||
}
|
@ -5,5 +5,5 @@ namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
interface Role
|
||||
{
|
||||
public function accept(RoleVisitorInterface $visitor);
|
||||
public function accept(RoleVisitor $visitor);
|
||||
}
|
||||
|
@ -3,28 +3,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
class RoleVisitor implements RoleVisitorInterface
|
||||
/**
|
||||
* Note: the visitor must not choose itself which method to
|
||||
* invoke, it is the Visitee that make this decision
|
||||
*/
|
||||
interface RoleVisitor
|
||||
{
|
||||
/**
|
||||
* @var Role[]
|
||||
*/
|
||||
private $visited = [];
|
||||
public function visitUser(User $role);
|
||||
|
||||
public function visitGroup(Group $role)
|
||||
{
|
||||
$this->visited[] = $role;
|
||||
}
|
||||
|
||||
public function visitUser(User $role)
|
||||
{
|
||||
$this->visited[] = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Role[]
|
||||
*/
|
||||
public function getVisited(): array
|
||||
{
|
||||
return $this->visited;
|
||||
}
|
||||
public function visitGroup(Group $role);
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
/**
|
||||
* Note: the visitor must not choose itself which method to
|
||||
* invoke, it is the Visitee that make this decision
|
||||
*/
|
||||
interface RoleVisitorInterface
|
||||
{
|
||||
public function visitUser(User $role);
|
||||
|
||||
public function visitGroup(Group $role);
|
||||
}
|
@ -9,13 +9,13 @@ use PHPUnit\Framework\TestCase;
|
||||
class VisitorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Visitor\RoleVisitor
|
||||
* @var Visitor\RecordingVisitor
|
||||
*/
|
||||
private $visitor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->visitor = new Visitor\RoleVisitor();
|
||||
$this->visitor = new Visitor\RecordingVisitor();
|
||||
}
|
||||
|
||||
public function provideRoles()
|
||||
|
@ -20,7 +20,7 @@ class User implements Role
|
||||
return sprintf('User %s', $this->name);
|
||||
}
|
||||
|
||||
public function accept(RoleVisitorInterface $visitor)
|
||||
public function accept(RoleVisitor $visitor)
|
||||
{
|
||||
$visitor->visitUser($this);
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 57 KiB |
Loading…
x
Reference in New Issue
Block a user