mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
EduardoGR adding strategy context in order to complete the pattern
This commit is contained in:
23
Behavioral/Strategy/Context.php
Normal file
23
Behavioral/Strategy/Context.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Behavioral\Strategy;
|
||||
|
||||
class Context
|
||||
{
|
||||
/**
|
||||
* @var ComparatorInterface
|
||||
*/
|
||||
private $comparator;
|
||||
|
||||
public function __construct(ComparatorInterface $comparator)
|
||||
{
|
||||
$this->comparator = $comparator;
|
||||
}
|
||||
|
||||
public function executeStrategy(array $elements) : array
|
||||
{
|
||||
uasort($elements, [$this->comparator, 'compare']);
|
||||
|
||||
return $elements;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user