CoreFiles by mySites.guru
GenericLinkProvider.php71 lines, 1,478 bytes, from Joomla_5.2.2-Stable-Full_Package.zip
Raw History Compare with 5.2.1
md5
42215bd0c422f1a7bdc920add891395a
sha1
b88204b2366c864bce050f1aba3cf1476ec7f0ae
sha256
e37edf50cf3777cfcb4a518ea0c386f0512d10505383bc82a6026d09ab2d0ae3
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\WebLink;

use Psr\Link\EvolvableLinkProviderInterface;
use Psr\Link\LinkInterface;

class GenericLinkProvider implements EvolvableLinkProviderInterface
{
    /**
     * @var LinkInterface[]
     */
    private array $links = [];

    /**
     * @param LinkInterface[] $links
     */
    public function __construct(array $links = [])
    {
        $that = $this;

        foreach ($links as $link) {
            $that = $that->withLink($link);
        }

        $this->links = $that->links;
    }

    public function getLinks(): array
    {
        return array_values($this->links);
    }

    public function getLinksByRel(string $rel): array
    {
        $links = [];

        foreach ($this->links as $link) {
            if (\in_array($rel, $link->getRels())) {
                $links[] = $link;
            }
        }

        return $links;
    }

    public function withLink(LinkInterface $link): static
    {
        $that = clone $this;
        $that->links[spl_object_id($link)] = $link;

        return $that;
    }

    public function withoutLink(LinkInterface $link): static
    {
        $that = clone $this;
        unset($that->links[spl_object_id($link)]);

        return $that;
    }
}

The same content is in 158 releases, Joomla 5.0.0-alpha1 to 6.3.0-alpha1. See them all, or every version of this file.