| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Alchemy\Resource\Metadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Assert\Assertion; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 7 |  |  | class ArrayMetadataIterator implements MetadataIterator | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  |      * @var Metadata[] | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |     private $resources; | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |      * @param Metadata[] $metadataResources | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public function __construct(array $metadataResources) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         Assertion::allIsInstanceOf($metadataResources, Metadata::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $this->resources = $metadataResources; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      * (PHP 5 >= 5.0.0)<br/> | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      * Move forward to next element | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      * @link http://php.net/manual/en/iterator.next.php | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * @return void Any returned value is ignored. | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function next() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         next($this->resources); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * (PHP 5 >= 5.0.0)<br/> | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * Return the key of the current element | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      * @link http://php.net/manual/en/iterator.key.php | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      * @return mixed scalar on success, or null on failure. | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function key() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         return key($this->resources); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * (PHP 5 >= 5.0.0)<br/> | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      * Checks if current position is valid | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      * @link http://php.net/manual/en/iterator.valid.php | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * @return boolean The return value will be casted to boolean and then evaluated. | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * Returns true on success or false on failure. | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function valid() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return key($this->resources) !== null; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      * (PHP 5 >= 5.0.0)<br/> | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * Rewind the Iterator to the first element | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * @link http://php.net/manual/en/iterator.rewind.php | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * @return void Any returned value is ignored. | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function rewind() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         reset($this->resources); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |      * @return Metadata | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public function current() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         return current($this->resources); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 76 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |  |