Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
16 / 16
CRAP
100.00% covered (success)
100.00%
1 / 1
Manager
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
16 / 16
22
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
4
 addQueue
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addQueues
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getQueues
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getQueue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 hasQueue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __set
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 __get
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __isset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __unset
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 offsetSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetGet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetExists
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 offsetUnset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 count
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIterator
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Queue;
15
16use ReturnTypeWillChange;
17
18/**
19 * Queue manager class
20 *
21 * @category   Pop
22 * @package    Pop\Queue
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    1.2.0
27 */
28class Manager implements \ArrayAccess, \Countable, \IteratorAggregate
29{
30
31    /**
32     * Queues
33     * @var Queue[]
34     */
35    protected $queues = [];
36
37    /**
38     * Constructor
39     *
40     * Instantiate the queue manager object.
41     *
42     * @param  mixed $queues
43     */
44    public function __construct($queues = null)
45    {
46        if (null !== $queues) {
47            if (is_array($queues)) {
48                $this->addQueues($queues);
49            } else if ($queues instanceof Queue) {
50                $this->addQueue($queues);
51            }
52        }
53    }
54
55    /**
56     * Add queue
57     *
58     * @param  Queue $queue
59     * @return Manager
60     */
61    public function addQueue(Queue $queue)
62    {
63        $this->queues[$queue->getName()] = $queue;
64        return $this;
65    }
66
67    /**
68     * Add queues
69     *
70     * @param  array $queues
71     * @return Manager
72     */
73    public function addQueues(array $queues)
74    {
75        foreach ($queues as $queue) {
76            $this->addQueue($queue);
77        }
78        return $this;
79    }
80
81    /**
82     * Get queues
83     *
84     * @return array
85     */
86    public function getQueues()
87    {
88        return $this->queues;
89    }
90
91    /**
92     * Get queue
93     *
94     * @param  string $queue
95     * @return Queue
96     */
97    public function getQueue($queue)
98    {
99        return (isset($this->queues[$queue])) ? $this->queues[$queue] : null;
100    }
101
102    /**
103     * Has queue
104     *
105     * @param  string $queue
106     * @return boolean
107     */
108    public function hasQueue($queue)
109    {
110        return (isset($this->queues[$queue]));
111    }
112
113    /**
114     * Register a queue with the manager
115     *
116     * @param  string $name
117     * @param  mixed $value
118     * @return Manager
119     */
120    public function __set($name, $value)
121    {
122        $this->addQueue($value);
123        return $this;
124    }
125
126    /**
127     * Get a queue
128     *
129     * @param  string $name
130     * @return Queue
131     */
132    public function __get($name)
133    {
134        return $this->getQueue($name);
135    }
136
137    /**
138     * Determine if a queue is registered with the manager object
139     *
140     * @param  string $name
141     * @return boolean
142     */
143    public function __isset($name)
144    {
145        return isset($this->queues[$name]);
146    }
147
148    /**
149     * Unset a queue with the manager
150     *
151     * @param  string $name
152     * @return Manager
153     */
154    public function __unset($name)
155    {
156        if (isset($this->queues[$name])) {
157            unset($this->queues[$name]);
158        }
159        return $this;
160    }
161
162    /**
163     * Set a queue with the manager
164     *
165     * @param  string $offset
166     * @param  mixed $value
167     * @return Manager
168     */
169    #[ReturnTypeWillChange]
170    public function offsetSet($offset, $value)
171    {
172        return $this->__set($offset, $value);
173    }
174
175    /**
176     * Get a queue
177     *
178     * @param  string $offset
179     * @return Queue
180     */
181    #[ReturnTypeWillChange]
182    public function offsetGet($offset)
183    {
184        return $this->__get($offset);
185    }
186
187    /**
188     * Determine if a queue is registered with the manager object
189     *
190     * @param  string $offset
191     * @return boolean
192     */
193    public function offsetExists($offset): bool
194    {
195        return $this->__isset($offset);
196    }
197
198    /**
199     * Unset a queue from the manager
200     *
201     * @param  string $offset
202     * @return Manager
203     */
204    #[ReturnTypeWillChange]
205    public function offsetUnset($offset)
206    {
207        return $this->__unset($offset);
208    }
209
210    /**
211     * Return count
212     *
213     * @return int
214     */
215    public function count(): int
216    {
217        return count($this->queues);
218    }
219
220    /**
221     * Get iterator
222     *
223     * @return \ArrayIterator
224     */
225    public function getIterator(): \ArrayIterator
226    {
227        return new \ArrayIterator($this->queues);
228    }
229
230}