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. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
service_collection.php
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 to be configured at container compile time.
020 */
021 class service_collection extends \ArrayObject
022 {
023 /**
024 * @var ContainerInterface
025 */
026 protected $container;
027
028 /**
029 * @var array
030 */
031 protected $service_classes;
032
033 /**
034 * Constructor
035 *
036 * @param ContainerInterface $container Container object
037 */
038 public function __construct(ContainerInterface $container)
039 {
040 $this->container = $container;
041 $this->service_classes = array();
042 }
043
044 /**
045 * {@inheritdoc}
046 */
047 public function getIterator()
048 {
049 return new service_collection_iterator($this);
050 }
051
052 /**
053 * {@inheritdoc}
054 */
055 public function offsetGet($index)
056 {
057 return $this->container->get($index);
058 }
059
060 /**
061 * Add a service to the collection
062 *
063 * @param string $name The service name
064 * @return void
065 */
066 public function add($name)
067 {
068 $this->offsetSet($name, false);
069 }
070
071 /**
072 * Add a service's class to the collection
073 *
074 * @param string $service_id
075 * @param string $class
076 */
077 public function add_service_class($service_id, $class)
078 {
079 $this->service_classes[$service_id] = $class;
080 }
081
082 /**
083 * Get services' classes
084 *
085 * @return array
086 */
087 public function get_service_classes()
088 {
089 return $this->service_classes;
090 }
091
092 /**
093 * Returns the service associated to a class
094 *
095 * @return mixed
096 * @throw \RuntimeException if the
097 */
098 public function get_by_class($class)
099 {
100 $service_id = null;
101
102 foreach ($this->service_classes as $id => $service_class)
103 {
104 if ($service_class === $class)
105 {
106 if ($service_id !== null)
107 {
108 throw new \RuntimeException('More than one service definitions found for class "'.$class.'" in collection.');
109 }
110
111 $service_id = $id;
112 }
113 }
114
115 if ($service_id === null)
116 {
117 throw new \RuntimeException('No service found for class "'.$class.'" in collection.');
118 }
119
120 return $this->offsetGet($service_id);
121 }
122 }
123