mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-29 20:52:52 +02:00
24 lines
424 B
PHP
24 lines
424 B
PHP
<?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;
|
|
}
|
|
}
|