| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of the Cubiche package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Copyright (c) Cubiche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace Cubiche\Infrastructure\Geolocation\Doctrine\ODM\MongoDB\Metadata\Driver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Cubiche\Core\Metadata\ClassMetadataInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Cubiche\Core\Metadata\PropertyMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Cubiche\Infrastructure\Doctrine\ODM\MongoDB\Metadata\Exception\MappingException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Cubiche\Infrastructure\Doctrine\ODM\MongoDB\Metadata\Driver\XmlDriver as BaseXmlDriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * XmlDriver class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @author Ivannis Suárez Jerez <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class XmlDriver extends BaseXmlDriver | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |     protected function addMetadataFor(\SimpleXMLElement $xmlRoot, ClassMetadataInterface $classMetadata) | 
            
                                                        
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 30 |  |  |         foreach ($xmlRoot->xpath('//cubiche:coordinate') as $item) { | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |             // get the field tag | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |             $field = $item->xpath('..')[0]; | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |             $fieldMapping = $this->getMappingAttributes($field); | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |             $fieldName = $fieldMapping['name']; | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |             if ($field->getName() == 'field') { | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |                 if (isset($fieldMapping['id']) && $fieldMapping['id'] !== false) { | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |                     throw MappingException::inField( | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |                         'The cubiche:coordinate configuration is only for field tags that is not an id', | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |                         $classMetadata->className(), | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |                         $fieldName | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |                     ); | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |                 } | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |                 if (!isset($fieldMapping['type']) || | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |                     (isset($fieldMapping['type']) && $fieldMapping['type'] !== 'CubicheType') | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |                 ) { | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |                     throw MappingException::inField( | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |                         'The cubiche:coordinate parent should have a "type" value equal to CubicheType', | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |                         $classMetadata->className(), | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |                         $fieldName | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |                     ); | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |                 } | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |                 $propertyMetadata = new PropertyMetadata($classMetadata->className(), $fieldName); | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |                 $propertyMetadata->addMetadata('namespace', 'coordinate'); | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |                 $classMetadata->addPropertyMetadata($propertyMetadata); | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |             } else { | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |                 throw MappingException::inField( | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |                     'The cubiche:coordinate configuration is only for field tags that is not an id', | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |                     $classMetadata->className(), | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |                     $fieldName | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |                 ); | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 68 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |  |