| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * This software consists of voluntary contributions made by many individuals | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * and is licensed under the MIT license. For more information, see | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * <http://www.doctrine-project.org>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | namespace Doctrine\ODM\MongoDB\Mapping\Driver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Doctrine\Common\Persistence\Mapping\ClassMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as MappingClassMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Doctrine\ODM\MongoDB\Utility\CollectionHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Symfony\Component\Yaml\Yaml; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Symfony\Component\Yaml\Exception\ParseException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * The YamlDriver reads the mapping metadata from yaml schema files. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @since       1.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | class YamlDriver extends FileDriver | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     const DEFAULT_FILE_EXTENSION = '.dcm.yml'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 13 |  |     public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 13 |  |         parent::__construct($locator, $fileExtension); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 13 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 9 |  |     public function loadMetadataForClass($className, ClassMetadata $class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         /* @var $class ClassMetadataInfo */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 9 |  |         $element = $this->getElement($className); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 9 |  |         if ( ! $element) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 9 |  |         $element['type'] = isset($element['type']) ? $element['type'] : 'document'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 9 |  |         if (isset($element['db'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 2 |  |             $class->setDatabase($element['db']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 9 |  |         if (isset($element['collection'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 9 |  |             $class->setCollection($element['collection']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 9 |  |         if (isset($element['writeConcern'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 2 |  |             $class->setWriteConcern($element['writeConcern']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 9 |  |         if ($element['type'] == 'document') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 9 |  |             if (isset($element['repositoryClass'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 9 |  |                 $class->setCustomRepositoryClass($element['repositoryClass']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 72 | 1 | View Code Duplication |         } elseif ($element['type'] === 'mappedSuperclass') { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             $class->setCustomRepositoryClass( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 isset($element['repositoryClass']) ? $element['repositoryClass'] : null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             $class->isMappedSuperclass = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 1 |  |         } elseif ($element['type'] === 'embeddedDocument') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 1 |  |             $class->isEmbeddedDocument = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 9 |  |         if (isset($element['indexes'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 3 |  |             foreach($element['indexes'] as $index) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 3 |  |                 $class->addIndex($index['keys'], isset($index['options']) ? $index['options'] : array()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 9 |  |         if (isset($element['shardKey'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 2 |  |             $this->setShardKey($class, $element['shardKey']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 88 | 9 | View Code Duplication |         if (isset($element['inheritanceType'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             $class->setInheritanceType(constant(MappingClassMetadata::class . '::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType']))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 9 |  |         if (isset($element['discriminatorField'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 2 |  |             $class->setDiscriminatorField($this->parseDiscriminatorField($element['discriminatorField'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 9 |  |         if (isset($element['discriminatorMap'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 2 |  |             $class->setDiscriminatorMap($element['discriminatorMap']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 9 |  |         if (isset($element['defaultDiscriminatorValue'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 2 |  |             $class->setDefaultDiscriminatorValue($element['defaultDiscriminatorValue']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 100 | 9 | View Code Duplication |         if (isset($element['changeTrackingPolicy'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             $class->setChangeTrackingPolicy(constant(MappingClassMetadata::class . '::CHANGETRACKING_' . strtoupper($element['changeTrackingPolicy']))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 9 |  |         if (isset($element['requireIndexes'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             $class->setRequireIndexes($element['requireIndexes']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 9 |  |         if (isset($element['slaveOkay'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             $class->setSlaveOkay($element['slaveOkay']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 9 |  |         if (isset($element['fields'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 9 |  |             foreach ($element['fields'] as $fieldName => $mapping) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 9 |  |                 if (is_string($mapping)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 1 |  |                     $type = $mapping; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 1 |  |                     $mapping = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 1 |  |                     $mapping['type'] = $type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 9 |  |                 if ( ! isset($mapping['fieldName'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 8 |  |                     $mapping['fieldName'] = $fieldName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 9 |  |                 if (isset($mapping['type']) && ! empty($mapping['embedded'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 2 |  |                     $this->addMappingFromEmbed($class, $fieldName, $mapping, $mapping['type']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 9 |  |                 } elseif (isset($mapping['type']) && ! empty($mapping['reference'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 2 |  |                     $this->addMappingFromReference($class, $fieldName, $mapping, $mapping['type']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 9 |  |                     $this->addFieldMapping($class, $mapping); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 128 | 9 | View Code Duplication |         if (isset($element['embedOne'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 3 |  |             foreach ($element['embedOne'] as $fieldName => $embed) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 3 |  |                 $this->addMappingFromEmbed($class, $fieldName, $embed, 'one'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 133 | 9 | View Code Duplication |         if (isset($element['embedMany'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 3 |  |             foreach ($element['embedMany'] as $fieldName => $embed) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 | 3 |  |                 $this->addMappingFromEmbed($class, $fieldName, $embed, 'many'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 138 | 9 | View Code Duplication |         if (isset($element['referenceOne'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 | 3 |  |             foreach ($element['referenceOne'] as $fieldName => $reference) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 | 3 |  |                 $this->addMappingFromReference($class, $fieldName, $reference, 'one'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 143 | 9 | View Code Duplication |         if (isset($element['referenceMany'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 3 |  |             foreach ($element['referenceMany'] as $fieldName => $reference) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 3 |  |                 $this->addMappingFromReference($class, $fieldName, $reference, 'many'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 | 9 |  |         if (isset($element['lifecycleCallbacks'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 | 3 |  |             foreach ($element['lifecycleCallbacks'] as $type => $methods) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 | 3 |  |                 foreach ($methods as $method) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 | 3 |  |                     $class->addLifecycleCallback($method, constant('Doctrine\ODM\MongoDB\Events::' . $type)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 9 |  |         if (isset($element['alsoLoadMethods'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 | 1 |  |             foreach ($element['alsoLoadMethods'] as $methodName => $fieldName) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 1 |  |                 $class->registerAlsoLoadMethod($methodName, $fieldName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 | 9 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 | 9 |  |     private function addFieldMapping(ClassMetadataInfo $class, $mapping) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     { | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 164 | 9 | View Code Duplication |         if (isset($mapping['name'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 | 2 |  |             $name = $mapping['name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 | 9 |  |         } elseif (isset($mapping['fieldName'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 | 9 |  |             $name = $mapping['fieldName']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |             throw new \InvalidArgumentException('Cannot infer a MongoDB name from the mapping'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 9 |  |         $class->mapField($mapping); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 174 | 9 | View Code Duplication |         if ( ! (isset($mapping['index']) || isset($mapping['unique']) || isset($mapping['sparse']))) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 | 9 |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         // Multiple index specifications in one field mapping is ambiguous | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 5 |  |         if ((isset($mapping['index']) && is_array($mapping['index'])) + | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 | 5 |  |             (isset($mapping['unique']) && is_array($mapping['unique'])) + | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 | 5 |  |             (isset($mapping['sparse']) && is_array($mapping['sparse'])) > 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |             throw new \InvalidArgumentException('Multiple index specifications found among index, unique, and/or sparse fields'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         // Index this field if either "index", "unique", or "sparse" are set | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 | 5 |  |         $keys = array($name => 'asc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         /* The "order" option is only used in the index specification and should | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |          * not be passed along as an index option. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 | 5 |  |         if (isset($mapping['index']['order'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 | 2 |  |             $keys[$name] = $mapping['index']['order']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 | 2 |  |             unset($mapping['index']['order']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 | 5 |  |         } elseif (isset($mapping['unique']['order'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 | 2 |  |             $keys[$name] = $mapping['unique']['order']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 | 2 |  |             unset($mapping['unique']['order']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 | 3 |  |         } elseif (isset($mapping['sparse']['order'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             $keys[$name] = $mapping['sparse']['order']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |             unset($mapping['sparse']['order']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         /* Initialize $options from any array value among index, unique, and | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |          * sparse. Any boolean values for unique or sparse should be merged into | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |          * the options afterwards to ensure consistent parsing. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 | 5 |  |         $options = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 | 5 |  |         $unique = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 | 5 |  |         $sparse = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 | 5 |  |         if (isset($mapping['index']) && is_array($mapping['index'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 | 2 |  |             $options = $mapping['index']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 214 | 5 | View Code Duplication |         if (isset($mapping['unique'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 | 5 |  |             if (is_array($mapping['unique'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 | 2 |  |                 $options = $mapping['unique'] + array('unique' => true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 | 3 |  |                 $unique = (boolean) $mapping['unique']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 222 | 5 | View Code Duplication |         if (isset($mapping['sparse'])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 | 3 |  |             if (is_array($mapping['sparse'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |                 $options = $mapping['sparse'] + array('sparse' => true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 | 3 |  |                 $sparse = (boolean) $mapping['sparse']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 | 5 |  |         if (isset($unique)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 | 3 |  |             $options['unique'] = $unique; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 | 5 |  |         if (isset($sparse)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 | 3 |  |             $options['sparse'] = $sparse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 | 5 |  |         $class->addIndex($keys, $options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 | 5 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 | 5 |  |     private function addMappingFromEmbed(ClassMetadataInfo $class, $fieldName, $embed, $type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 | 5 |  |         $defaultStrategy = $type == 'one' ? ClassMetadataInfo::STORAGE_STRATEGY_SET : CollectionHelper::DEFAULT_STRATEGY; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |         $mapping = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 | 5 |  |             'type'            => $type, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |             'embedded'        => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 | 5 |  |             'targetDocument'  => isset($embed['targetDocument']) ? $embed['targetDocument'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 | 5 |  |             'collectionClass' => isset($embed['collectionClass']) ? $embed['collectionClass'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 | 5 |  |             'fieldName'       => $fieldName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 | 5 |  |             'strategy'        => isset($embed['strategy']) ? (string) $embed['strategy'] : $defaultStrategy, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 | 5 |  |         if (isset($embed['name'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 | 2 |  |             $mapping['name'] = $embed['name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 | 5 |  |         if (isset($embed['discriminatorField'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 | 2 |  |             $mapping['discriminatorField'] = $this->parseDiscriminatorField($embed['discriminatorField']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 | 5 |  |         if (isset($embed['discriminatorMap'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 | 2 |  |             $mapping['discriminatorMap'] = $embed['discriminatorMap']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 | 5 |  |         if (isset($embed['defaultDiscriminatorValue'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 | 2 |  |             $mapping['defaultDiscriminatorValue'] = $embed['defaultDiscriminatorValue']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 | 5 |  |         $this->addFieldMapping($class, $mapping); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 | 5 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 | 5 |  |     private function addMappingFromReference(ClassMetadataInfo $class, $fieldName, $reference, $type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 | 5 |  |         $defaultStrategy = $type == 'one' ? ClassMetadataInfo::STORAGE_STRATEGY_SET : CollectionHelper::DEFAULT_STRATEGY; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         $mapping = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 | 5 |  |             'cascade'          => isset($reference['cascade']) ? $reference['cascade'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 | 5 |  |             'orphanRemoval'    => isset($reference['orphanRemoval']) ? $reference['orphanRemoval'] : false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 | 5 |  |             'type'             => $type, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |             'reference'        => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 | 5 |  |             'simple'           => isset($reference['simple']) ? (boolean) $reference['simple'] : false, // deprecated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 | 5 |  |             'storeAs'          => isset($reference['storeAs']) ? (string) $reference['storeAs'] : ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF_WITH_DB, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 | 5 |  |             'targetDocument'   => isset($reference['targetDocument']) ? $reference['targetDocument'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 | 5 |  |             'collectionClass'  => isset($reference['collectionClass']) ? $reference['collectionClass'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 | 5 |  |             'fieldName'        => $fieldName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 | 5 |  |             'strategy'         => isset($reference['strategy']) ? (string) $reference['strategy'] : $defaultStrategy, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 | 5 |  |             'inversedBy'       => isset($reference['inversedBy']) ? (string) $reference['inversedBy'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 | 5 |  |             'mappedBy'         => isset($reference['mappedBy']) ? (string) $reference['mappedBy'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 | 5 |  |             'repositoryMethod' => isset($reference['repositoryMethod']) ? (string) $reference['repositoryMethod'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 | 5 |  |             'limit'            => isset($reference['limit']) ? (integer) $reference['limit'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 | 5 |  |             'skip'             => isset($reference['skip']) ? (integer) $reference['skip'] : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 | 5 |  |         if (isset($reference['name'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 | 2 |  |             $mapping['name'] = $reference['name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 | 5 |  |         if (isset($reference['discriminatorField'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 | 2 |  |             $mapping['discriminatorField'] = $this->parseDiscriminatorField($reference['discriminatorField']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 | 5 |  |         if (isset($reference['discriminatorMap'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 | 2 |  |             $mapping['discriminatorMap'] = $reference['discriminatorMap']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 | 5 |  |         if (isset($reference['defaultDiscriminatorValue'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 | 2 |  |             $mapping['defaultDiscriminatorValue'] = $reference['defaultDiscriminatorValue']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 | 5 |  |         if (isset($reference['sort'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |             $mapping['sort'] = $reference['sort']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 | 5 |  |         if (isset($reference['criteria'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |             $mapping['criteria'] = $reference['criteria']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 | 5 |  |         $this->addFieldMapping($class, $mapping); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 | 5 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |      * Parses the class or field-level "discriminatorField" option. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |      * If the value is an array, check the "name" option before falling back to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |      * the deprecated "fieldName" option (for BC). Otherwise, the value must be | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |      * a string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |      * @param array|string $discriminatorField | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |      * @throws \InvalidArgumentException if the value is neither a string nor an | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |      *                                   array with a "name" or "fieldName" key. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 319 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 320 | 2 |  |     private function parseDiscriminatorField($discriminatorField) | 
            
                                                                        
                            
            
                                    
            
            
                | 321 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 322 | 2 |  |         if (is_string($discriminatorField)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 323 | 2 |  |             return $discriminatorField; | 
            
                                                                        
                            
            
                                    
            
            
                | 324 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 325 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 326 | 2 |  |         if ( ! is_array($discriminatorField)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 327 |  |  |             throw new \InvalidArgumentException('Expected array or string for discriminatorField; found: ' . gettype($discriminatorField)); | 
            
                                                                        
                            
            
                                    
            
            
                | 328 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 329 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 330 | 2 |  |         if (isset($discriminatorField['name'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 331 |  |  |             return (string) $discriminatorField['name']; | 
            
                                                                        
                            
            
                                    
            
            
                | 332 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 333 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 334 | 2 |  |         if (isset($discriminatorField['fieldName'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 335 | 2 |  |             return (string) $discriminatorField['fieldName']; | 
            
                                                                        
                            
            
                                    
            
            
                | 336 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 337 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 338 |  |  |         throw new \InvalidArgumentException('Expected "name" or "fieldName" key in discriminatorField array; found neither.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 339 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 | 9 |  |     protected function loadMappingFile($file) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 | 9 |  |             return Yaml::parse(file_get_contents($file)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |         catch (ParseException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |             $e->setParsedFile($file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |             throw $e; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 | 2 |  |     private function setShardKey(ClassMetadataInfo $class, array $shardKey) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 | 2 |  |         $keys = $shardKey['keys']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 | 2 |  |         $options = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 | 2 |  |         if (isset($shardKey['options'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 | 2 |  |             $allowed = array('unique', 'numInitialChunks'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 | 2 |  |             foreach ($shardKey['options'] as $name => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 | 2 |  |                 if ( ! in_array($name, $allowed, true)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |                     continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 | 2 |  |                 $options[$name] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 | 2 |  |         $class->setShardKey($keys, $options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 | 2 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 372 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 373 |  |  |  | 
            
                        
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.