Answer the question
In order to leave comments, you need to log in
Am I using the Decorator correctly in php?
interface Output
{
public function getLinks($images);
}
class LinksOutput implements Output
{
public function getLinks($images)
{
uasort($images, function ($a, $b) {
return $a['width'] > $b['width'] ? 1 : -1;
});
$result = '';
foreach ($images as $val) {
$result .= "<pre>" . $val['link'] . "<br> Ширина " . $val['width'] . "<br>";
}
return $result;
}
}
class RedactOutput implements Output
{
protected $link;
public function __construct(Output $link)
{
$this->link = $link;
}
public function getLinks($images)
{
return '<strong>' . $this->link->getLinks($images) . '</strong>';
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question