Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ordered_service_collection.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 1.92 KiB


001  <?php
002  /**
003   *
004   * This file is part of the phpBB Forum Software package.
005   *
006   * @copyright (c) phpBB Limited <https://www.phpbb.com>
007   * @license GNU General Public License, version 2 (GPL-2.0)
008   *
009   * For full copyright and license information, please see
010   * the docs/CREDITS.txt file.
011   *
012   */
013   
014  namespace phpbb\di;
015   
016  use Symfony\Component\DependencyInjection\ContainerInterface;
017   
018  /**
019   * Collection of services in a specified order
020   */
021  class ordered_service_collection extends service_collection
022  {
023      /**
024       * @var bool
025       */
026      protected $is_ordered;
027   
028      /**
029       * @var array
030       */
031      protected $service_ids;
032   
033      /**
034       * Constructor
035       *
036       * @param ContainerInterface $container Container object
037       */
038      public function __construct(ContainerInterface $container)
039      {
040          $this->is_ordered = false;
041          $this->service_ids = array();
042   
043          parent::__construct($container);
044      }
045   
046      /**
047       * {@inheritdoc}
048       */
049      public function getIterator()
050      {
051          if (!$this->is_ordered)
052          {
053              $this->sort_services();
054          }
055   
056          return new service_collection_iterator($this);
057      }
058   
059      /**
060       * {@inheritdoc}
061       */
062      public function offsetExists($index)
063      {
064          if (!$this->is_ordered)
065          {
066              $this->sort_services();
067          }
068   
069          return parent::offsetExists($index);
070      }
071   
072      /**
073       * {@inheritdoc}
074       */
075      public function offsetGet($index)
076      {
077          if (!$this->is_ordered)
078          {
079              $this->sort_services();
080          }
081   
082          return parent::offsetGet($index);
083      }
084   
085      /**
086       * Adds a service ID to the collection
087       *
088       * @param string    $service_id
089       * @param int        $order
090       */
091      public function add($service_id, $order = 0)
092      {
093          $order = (int) $order;
094          $this->service_ids[$order][] = $service_id;
095          $this->is_ordered = false;
096      }
097   
098      protected function sort_services()
099      {
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  }
118