Skip to content
This repository

fixed several issues in cascade support #58

Merged
merged 1 commit into from over 1 year ago

3 participants

Lukas Kahwe Smith Christophe Coevoet Benjamin Eberlei
Lukas Kahwe Smith
Collaborator

fixed missing error handling for cascade, fixed typos in the yaml driver, fixed logic for building the bitmask

code taken from doctrine/phpcr-odm#200

...trine/ODM/CouchDB/Mapping/Driver/AnnotationDriver.php
... ... @@ -127,4 +119,23 @@ public function loadMetadataForClass($className, ClassMetadata $class)
127 119 }
128 120 }
129 121 }
  122 +
  123 + /**
  124 + * Gathers a list of cascade options found in the given cascade element.
  125 + *
  126 + * @param $cascadeList cascade list
  127 + * @return integer a bitmask of cascade options.
  128 + */
  129 + private function getCascadeMode($cascadeList)
  130 + {
  131 + $cascade = 0;
  132 + foreach ($cascadeList as $cascadeMode) {
2
Lukas Kahwe Smith Collaborator
lsmith77 added a note

btw this might require a newer doctrine common version, see doctrine/phpcr-odm#205 (comment)

Christophe Coevoet
stof added a note

@lsmith77 actually, the integer vs array issue is the one fixed in doctrine/phpcr-odm#209 IMO. Using a newer version of Doctrine was probably not related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Lukas Kahwe Smith
Collaborator

did not run the test suite .. and it seems like travis isnt properly enabled?

Lukas Kahwe Smith
Collaborator

probably also requires the changes done in doctrine/phpcr-odm#209

Benjamin Eberlei beberlei merged commit 23f95b7 into from
Lukas Kahwe Smith lsmith77 deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 07, 2013
Lukas Kahwe Smith lsmith77 fixed missing error handling for cascade, fixed typos in the yaml dri…
…ver, fixed logic for building the bitmask
add3bae
This page is out of date. Refresh to see the latest.
33 lib/Doctrine/ODM/CouchDB/Mapping/Driver/AnnotationDriver.php
@@ -94,23 +94,13 @@ public function loadMetadataForClass($className, ClassMetadata $class)
94 94 } else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Index) {
95 95 $mapping['indexed'] = true;
96 96 } else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceOne) {
97   - $cascade = 0;
98   - foreach ($fieldAnnot->cascade AS $cascadeMode) {
99   - $cascade += constant('Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode));
100   - }
101   - $fieldAnnot->cascade = $cascade;
102   -
103 97 $mapping = array_merge($mapping, (array) $fieldAnnot);
  98 + $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
104 99 unset($mapping['value']);
105 100 $class->mapManyToOne($mapping);
106 101 } else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceMany) {
107   - $cascade = 0;
108   - foreach ($fieldAnnot->cascade AS $cascadeMode) {
109   - $cascade += constant('Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode));
110   - }
111   - $fieldAnnot->cascade = $cascade;
112   -
113 102 $mapping = array_merge($mapping, (array) $fieldAnnot);
  103 + $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
114 104 unset($mapping['value']);
115 105 $class->mapManyToMany($mapping);
116 106 } else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Attachments) {
@@ -127,4 +117,23 @@ public function loadMetadataForClass($className, ClassMetadata $class)
127 117 }
128 118 }
129 119 }
  120 +
  121 + /**
  122 + * Gathers a list of cascade options found in the given cascade element.
  123 + *
  124 + * @param $cascadeList cascade list
  125 + * @return integer a bitmask of cascade options.
  126 + */
  127 + private function getCascadeMode(array $cascadeList)
  128 + {
  129 + $cascade = 0;
  130 + foreach ($cascadeList as $cascadeMode) {
  131 + $constantName = 'Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode);
  132 + if (!defined($constantName)) {
  133 + throw new MappingException("Cascade mode '$cascadeMode' not supported.");
  134 + }
  135 + $cascade |= constant($constantName);
  136 + }
  137 + return $cascade;
  138 + }
130 139 }
13 lib/Doctrine/ODM/CouchDB/Mapping/Driver/XmlDriver.php
@@ -189,10 +189,10 @@ protected function loadMappingFile($file)
189 189 /**
190 190 * Gathers a list of cascade options found in the given cascade element.
191 191 *
192   - * @param $cascadeElement The cascade element.
193   - * @return array The list of cascade options.
  192 + * @param $cascadeElement cascade element.
  193 + * @return integer a bitmask of cascade options.
194 194 */
195   - private function getCascadeMode($cascadeElement)
  195 + private function getCascadeMode(SimpleXMLElement $cascadeElement)
196 196 {
197 197 $cascade = 0;
198 198 foreach ($cascadeElement->children() as $action) {
@@ -202,8 +202,13 @@ private function getCascadeMode($cascadeElement)
202 202 // and we want to make sure that this driver doesn't need to know
203 203 // anything about the supported cascading actions
204 204 $cascadeMode = str_replace('cascade-', '', $action->getName());
205   - $cascade = constant('Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode));
  205 + $constantName = 'Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode);
  206 + if (!defined($constantName)) {
  207 + throw new MappingException("Cascade mode '$cascadeMode' not supported.");
  208 + }
  209 + $cascade |= constant($constantName);
206 210 }
  211 +
207 212 return $cascade;
208 213 }
209 214 }
24 lib/Doctrine/ODM/CouchDB/Mapping/Driver/YamlDriver.php
@@ -115,7 +115,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
115 115 if (isset($element['referenceOne'])) {
116 116 foreach ($element['referenceOne'] AS $field => $referenceOneElement) {
117 117 $class->mapManyToOne(array(
118   - 'cascade' => (isset($referenceManyElement->cascade)) ? $this->getCascadeMode($referenceManyElement->cascade) : 0,
  118 + 'cascade' => (isset($referenceOneElement['cascade'])) ? $this->getCascadeMode($referenceOneElement['cascade']) : 0,
119 119 'targetDocument' => (string)$referenceOneElement['targetDocument'],
120 120 'fieldName' => $field,
121 121 'jsonName' => (isset($referenceOneElement['jsonName'])) ? (string)$referenceOneElement['jsonName'] : null,
@@ -126,7 +126,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
126 126 if (isset($element['referenceMany'])) {
127 127 foreach ($element['referenceMany'] AS $field => $referenceManyElement) {
128 128 $class->mapManyToMany(array(
129   - 'cascade' => (isset($referenceManyElement->cascade)) ? $this->getCascadeMode($referenceManyElement->cascade) : 0,
  129 + 'cascade' => (isset($referenceManyElement['cascade'])) ? $this->getCascadeMode($referenceManyElement['cascade']) : 0,
130 130 'targetDocument' => (string)$referenceManyElement['targetDocument'],
131 131 'fieldName' => $field,
132 132 'jsonName' => (isset($referenceManyElement['jsonName'])) ? (string)$referenceManyElement['jsonName'] : null,
@@ -166,4 +166,24 @@ protected function loadMappingFile($file)
166 166 {
167 167 return Yaml::parse($file);
168 168 }
  169 +
  170 + /**
  171 + * Gathers a list of cascade options found in the given cascade element.
  172 + *
  173 + * @param array $cascadeElement The cascade element.
  174 + * @return integer a bitmask of cascade options.
  175 + */
  176 + private function getCascadeMode(array $cascadeElement)
  177 + {
  178 + $cascade = 0;
  179 + foreach ($cascadeElement as $cascadeMode) {
  180 + $constantName = 'Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode);
  181 + if (!defined($constantName)) {
  182 + throw new MappingException("Cascade mode '$cascadeMode' not supported.");
  183 + }
  184 + $cascade |= constant($constantName);
  185 + }
  186 +
  187 + return $cascade;
  188 + }
169 189 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.