[ Index ]

PHP Cross Reference of phpBB-3.3.12-deutsch

title

Body

[close]

/phpbb/di/ -> ordered_service_collection.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\di;
  15  
  16  use Symfony\Component\DependencyInjection\ContainerInterface;
  17  
  18  /**
  19   * Collection of services in a specified order
  20   */
  21  class ordered_service_collection extends service_collection
  22  {
  23      /**
  24       * @var bool
  25       */
  26      protected $is_ordered;
  27  
  28      /**
  29       * @var array
  30       */
  31      protected $service_ids;
  32  
  33      /**
  34       * Constructor
  35       *
  36       * @param ContainerInterface $container Container object
  37       */
  38  	public function __construct(ContainerInterface $container)
  39      {
  40          $this->is_ordered = false;
  41          $this->service_ids = array();
  42  
  43          parent::__construct($container);
  44      }
  45  
  46      /**
  47       * {@inheritdoc}
  48       */
  49  	public function getIterator()
  50      {
  51          if (!$this->is_ordered)
  52          {
  53              $this->sort_services();
  54          }
  55  
  56          return new service_collection_iterator($this);
  57      }
  58  
  59      /**
  60       * {@inheritdoc}
  61       */
  62  	public function offsetExists($index)
  63      {
  64          if (!$this->is_ordered)
  65          {
  66              $this->sort_services();
  67          }
  68  
  69          return parent::offsetExists($index);
  70      }
  71  
  72      /**
  73       * {@inheritdoc}
  74       */
  75  	public function offsetGet($index)
  76      {
  77          if (!$this->is_ordered)
  78          {
  79              $this->sort_services();
  80          }
  81  
  82          return parent::offsetGet($index);
  83      }
  84  
  85      /**
  86       * Adds a service ID to the collection
  87       *
  88       * @param string    $service_id
  89       * @param int        $order
  90       */
  91  	public function add($service_id, $order = 0)
  92      {
  93          $order = (int) $order;
  94          $this->service_ids[$order][] = $service_id;
  95          $this->is_ordered = false;
  96      }
  97  
  98  	protected function sort_services()
  99      {
 100          if ($this->is_ordered)
 101          {
 102              return;
 103          }
 104  
 105          $this->exchangeArray(array());
 106          ksort($this->service_ids);
 107          foreach ($this->service_ids as $service_order_group)
 108          {
 109              foreach ($service_order_group as $service_id)
 110              {
 111                  $this->offsetSet($service_id, null);
 112              }
 113          }
 114  
 115          $this->is_ordered = true;
 116      }
 117  }


Generated: Sun Jun 23 12:25:44 2024 Cross-referenced by PHPXref 0.7.1