mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-10 17:04:01 +02:00
PHP8
This commit is contained in:
@@ -6,11 +6,8 @@ use Psr\Http\Message\RequestInterface;
|
||||
|
||||
abstract class Handler
|
||||
{
|
||||
private ?Handler $successor = null;
|
||||
|
||||
public function __construct(Handler $handler = null)
|
||||
public function __construct(private ?Handler $successor = null)
|
||||
{
|
||||
$this->successor = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -7,13 +7,9 @@ use Psr\Http\Message\RequestInterface;
|
||||
|
||||
class HttpInMemoryCacheHandler extends Handler
|
||||
{
|
||||
private array $data;
|
||||
|
||||
public function __construct(array $data, ?Handler $successor = null)
|
||||
public function __construct(private array $data, ?Handler $successor = null)
|
||||
{
|
||||
parent::__construct($successor);
|
||||
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
protected function processing(RequestInterface $request): ?string
|
||||
|
@@ -8,15 +8,12 @@ namespace DesignPatterns\Behavioral\Command;
|
||||
*/
|
||||
class AddMessageDateCommand implements UndoableCommand
|
||||
{
|
||||
private Receiver $output;
|
||||
|
||||
/**
|
||||
* Each concrete command is built with different receivers.
|
||||
* There can be one, many or completely no receivers, but there can be other commands in the parameters.
|
||||
*/
|
||||
public function __construct(Receiver $console)
|
||||
public function __construct(private Receiver $output)
|
||||
{
|
||||
$this->output = $console;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -8,15 +8,12 @@ namespace DesignPatterns\Behavioral\Command;
|
||||
*/
|
||||
class HelloCommand implements Command
|
||||
{
|
||||
private Receiver $output;
|
||||
|
||||
/**
|
||||
* Each concrete command is built with different receivers.
|
||||
* There can be one, many or completely no receivers, but there can be other commands in the parameters
|
||||
*/
|
||||
public function __construct(Receiver $console)
|
||||
public function __construct(private Receiver $output)
|
||||
{
|
||||
$this->output = $console;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -4,13 +4,8 @@ namespace DesignPatterns\Behavioral\Iterator;
|
||||
|
||||
class Book
|
||||
{
|
||||
private string $author;
|
||||
private string $title;
|
||||
|
||||
public function __construct(string $title, string $author)
|
||||
public function __construct(private string $title, private string $author)
|
||||
{
|
||||
$this->author = $author;
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function getAuthor(): string
|
||||
|
@@ -4,14 +4,8 @@ namespace DesignPatterns\Behavioral\Mediator;
|
||||
|
||||
class UserRepositoryUiMediator implements Mediator
|
||||
{
|
||||
private UserRepository $userRepository;
|
||||
private Ui $ui;
|
||||
|
||||
public function __construct(UserRepository $userRepository, Ui $ui)
|
||||
public function __construct(private UserRepository $userRepository, private Ui $ui)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
$this->ui = $ui;
|
||||
|
||||
$this->userRepository->setMediator($this);
|
||||
$this->ui->setMediator($this);
|
||||
}
|
||||
|
@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Memento;
|
||||
|
||||
class Memento
|
||||
{
|
||||
private State $state;
|
||||
|
||||
public function __construct(State $stateToSave)
|
||||
public function __construct(private State $state)
|
||||
{
|
||||
$this->state = $stateToSave;
|
||||
}
|
||||
|
||||
public function getState(): State
|
||||
|
@@ -4,7 +4,7 @@ namespace DesignPatterns\Behavioral\Memento;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class State
|
||||
class State implements \Stringable
|
||||
{
|
||||
const STATE_CREATED = 'created';
|
||||
const STATE_OPENED = 'opened';
|
||||
|
@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\NullObject;
|
||||
|
||||
class Service
|
||||
{
|
||||
private Logger $logger;
|
||||
|
||||
public function __construct(Logger $logger)
|
||||
public function __construct(private Logger $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -12,7 +12,6 @@ use SplObserver;
|
||||
*/
|
||||
class User implements SplSubject
|
||||
{
|
||||
private string $email;
|
||||
private SplObjectStorage $observers;
|
||||
|
||||
public function __construct()
|
||||
@@ -32,7 +31,6 @@ class User implements SplSubject
|
||||
|
||||
public function changeEmail(string $email)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->notify();
|
||||
}
|
||||
|
||||
|
@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
class Item
|
||||
{
|
||||
private float $price;
|
||||
|
||||
public function __construct(float $price)
|
||||
public function __construct(private float $price)
|
||||
{
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
public function getPrice(): float
|
||||
|
@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
class NotSpecification implements Specification
|
||||
{
|
||||
private Specification $specification;
|
||||
|
||||
public function __construct(Specification $specification)
|
||||
public function __construct(private Specification $specification)
|
||||
{
|
||||
$this->specification = $specification;
|
||||
}
|
||||
|
||||
public function isSatisfiedBy(Item $item): bool
|
||||
|
@@ -4,13 +4,8 @@ namespace DesignPatterns\Behavioral\Specification;
|
||||
|
||||
class PriceSpecification implements Specification
|
||||
{
|
||||
private ?float $maxPrice;
|
||||
private ?float $minPrice;
|
||||
|
||||
public function __construct(?float $minPrice, ?float $maxPrice)
|
||||
public function __construct(private ?float $minPrice, private ?float $maxPrice)
|
||||
{
|
||||
$this->minPrice = $minPrice;
|
||||
$this->maxPrice = $maxPrice;
|
||||
}
|
||||
|
||||
public function isSatisfiedBy(Item $item): bool
|
||||
|
@@ -7,8 +7,6 @@ interface Comparator
|
||||
/**
|
||||
* @param mixed $a
|
||||
* @param mixed $b
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function compare($a, $b): int;
|
||||
}
|
||||
|
@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Strategy;
|
||||
|
||||
class Context
|
||||
{
|
||||
private Comparator $comparator;
|
||||
|
||||
public function __construct(Comparator $comparator)
|
||||
public function __construct(private Comparator $comparator)
|
||||
{
|
||||
$this->comparator = $comparator;
|
||||
}
|
||||
|
||||
public function executeStrategy(array $elements): array
|
||||
|
@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
class Group implements Role
|
||||
{
|
||||
private string $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
public function __construct(private string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
|
@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Visitor;
|
||||
|
||||
class User implements Role
|
||||
{
|
||||
private string $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
public function __construct(private string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
|
Reference in New Issue
Block a user