Files
DesignPatternsPHP/Structural/Adapter/EBookAdapter.php
2019-08-21 08:12:28 +02:00

48 lines
998 B
PHP

<?php declare(strict_types=1);
namespace DesignPatterns\Structural\Adapter;
/**
* This is the adapter here. Notice it implements Book,
* therefore you don't have to change the code of the client which is using a Book
*/
class EBookAdapter implements Book
{
/**
* @var EBook
*/
protected $eBook;
/**
* @param EBook $eBook
*/
public function __construct(EBook $eBook)
{
$this->eBook = $eBook;
}
/**
* This class makes the proper translation from one interface to another.
*/
public function open()
{
$this->eBook->unlock();
}
public function turnPage()
{
$this->eBook->pressNext();
}
/**
* notice the adapted behavior here: EBook::getPage() will return two integers, but Book
* supports only a current page getter, so we adapt the behavior here
*
* @return int
*/
public function getPage(): int
{
return $this->eBook->getPage()[0];
}
}