G
G
ganjo8882018-11-27 17:08:09
PHP
ganjo888, 2018-11-27 17:08:09

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>';
    }

}

Tell me what needs to be fixed and how to do it better.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question