[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/symfony/web-link/ -> GenericLinkProvider.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <[email protected]>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\WebLink;
  13  
  14  use Psr\Link\EvolvableLinkProviderInterface;
  15  use Psr\Link\LinkInterface;
  16  
  17  class GenericLinkProvider implements EvolvableLinkProviderInterface
  18  {
  19      /**
  20       * @var LinkInterface[]
  21       */
  22      private $links = [];
  23  
  24      /**
  25       * @param LinkInterface[] $links
  26       */
  27      public function __construct(array $links = [])
  28      {
  29          $that = $this;
  30  
  31          foreach ($links as $link) {
  32              $that = $that->withLink($link);
  33          }
  34  
  35          $this->links = $that->links;
  36      }
  37  
  38      /**
  39       * {@inheritdoc}
  40       */
  41      public function getLinks(): array
  42      {
  43          return array_values($this->links);
  44      }
  45  
  46      /**
  47       * {@inheritdoc}
  48       */
  49      public function getLinksByRel($rel): array
  50      {
  51          $links = [];
  52  
  53          foreach ($this->links as $link) {
  54              if (\in_array($rel, $link->getRels())) {
  55                  $links[] = $link;
  56              }
  57          }
  58  
  59          return $links;
  60      }
  61  
  62      /**
  63       * {@inheritdoc}
  64       *
  65       * @return static
  66       */
  67      public function withLink(LinkInterface $link)
  68      {
  69          $that = clone $this;
  70          $that->links[spl_object_id($link)] = $link;
  71  
  72          return $that;
  73      }
  74  
  75      /**
  76       * {@inheritdoc}
  77       *
  78       * @return static
  79       */
  80      public function withoutLink(LinkInterface $link)
  81      {
  82          $that = clone $this;
  83          unset($that->links[spl_object_id($link)]);
  84  
  85          return $that;
  86      }
  87  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer