Files
DesignPatternsPHP/Structural/Adapter/EBookAdapter.php
Dominik Liebler d151e309c5 PHP7 Adapter
2016-09-22 20:09:07 +02:00

48 lines
1.0 KiB
PHP

<?php
namespace DesignPatterns\Structural\Adapter;
/**
* This is the adapter here. Notice it implements BookInterface,
* therefore you don't have to change the code of the client which is using a Book
*/
class EBookAdapter implements BookInterface
{
/**
* @var EBookInterface
*/
protected $eBook;
/**
* @param EBookInterface $eBook
*/
public function __construct(EBookInterface $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: EBookInterface::getPage() will return two integers, but BookInterface
* supports only a current page getter, so we adapt the behavior here
*
* @return int
*/
public function getPage(): int
{
return $this->eBook->getPage()[0];
}
}