Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fixed several issues in cascade support #58

Merged
merged 1 commit into from

3 participants

@lsmith77
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)
}
}
}
+
+ /**
+ * Gathers a list of cascade options found in the given cascade element.
+ *
+ * @param $cascadeList cascade list
+ * @return integer a bitmask of cascade options.
+ */
+ private function getCascadeMode($cascadeList)
+ {
+ $cascade = 0;
+ foreach ($cascadeList as $cascadeMode) {
@lsmith77 Collaborator
lsmith77 added a note

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

@stof
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
@lsmith77
Collaborator

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

@lsmith77
Collaborator

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

@beberlei beberlei merged commit 23f95b7 into from
@lsmith77 lsmith77 deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 7, 2013
  1. @lsmith77

    fixed missing error handling for cascade, fixed typos in the yaml dri…

    lsmith77 authored
    …ver, fixed logic for building the bitmask
This page is out of date. Refresh to see the latest.
View
33 lib/Doctrine/ODM/CouchDB/Mapping/Driver/AnnotationDriver.php
@@ -94,23 +94,13 @@ public function loadMetadataForClass($className, ClassMetadata $class)
} else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Index) {
$mapping['indexed'] = true;
} else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceOne) {
- $cascade = 0;
- foreach ($fieldAnnot->cascade AS $cascadeMode) {
- $cascade += constant('Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode));
- }
- $fieldAnnot->cascade = $cascade;
-
$mapping = array_merge($mapping, (array) $fieldAnnot);
+ $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
unset($mapping['value']);
$class->mapManyToOne($mapping);
} else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceMany) {
- $cascade = 0;
- foreach ($fieldAnnot->cascade AS $cascadeMode) {
- $cascade += constant('Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode));
- }
- $fieldAnnot->cascade = $cascade;
-
$mapping = array_merge($mapping, (array) $fieldAnnot);
+ $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
unset($mapping['value']);
$class->mapManyToMany($mapping);
} else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Attachments) {
@@ -127,4 +117,23 @@ public function loadMetadataForClass($className, ClassMetadata $class)
}
}
}
+
+ /**
+ * Gathers a list of cascade options found in the given cascade element.
+ *
+ * @param $cascadeList cascade list
+ * @return integer a bitmask of cascade options.
+ */
+ private function getCascadeMode(array $cascadeList)
+ {
+ $cascade = 0;
+ foreach ($cascadeList as $cascadeMode) {
+ $constantName = 'Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode);
+ if (!defined($constantName)) {
+ throw new MappingException("Cascade mode '$cascadeMode' not supported.");
+ }
+ $cascade |= constant($constantName);
+ }
+ return $cascade;
+ }
}
View
13 lib/Doctrine/ODM/CouchDB/Mapping/Driver/XmlDriver.php
@@ -189,10 +189,10 @@ protected function loadMappingFile($file)
/**
* Gathers a list of cascade options found in the given cascade element.
*
- * @param $cascadeElement The cascade element.
- * @return array The list of cascade options.
+ * @param $cascadeElement cascade element.
+ * @return integer a bitmask of cascade options.
*/
- private function getCascadeMode($cascadeElement)
+ private function getCascadeMode(SimpleXMLElement $cascadeElement)
{
$cascade = 0;
foreach ($cascadeElement->children() as $action) {
@@ -202,8 +202,13 @@ private function getCascadeMode($cascadeElement)
// and we want to make sure that this driver doesn't need to know
// anything about the supported cascading actions
$cascadeMode = str_replace('cascade-', '', $action->getName());
- $cascade = constant('Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode));
+ $constantName = 'Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode);
+ if (!defined($constantName)) {
+ throw new MappingException("Cascade mode '$cascadeMode' not supported.");
+ }
+ $cascade |= constant($constantName);
}
+
return $cascade;
}
}
View
24 lib/Doctrine/ODM/CouchDB/Mapping/Driver/YamlDriver.php
@@ -115,7 +115,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
if (isset($element['referenceOne'])) {
foreach ($element['referenceOne'] AS $field => $referenceOneElement) {
$class->mapManyToOne(array(
- 'cascade' => (isset($referenceManyElement->cascade)) ? $this->getCascadeMode($referenceManyElement->cascade) : 0,
+ 'cascade' => (isset($referenceOneElement['cascade'])) ? $this->getCascadeMode($referenceOneElement['cascade']) : 0,
'targetDocument' => (string)$referenceOneElement['targetDocument'],
'fieldName' => $field,
'jsonName' => (isset($referenceOneElement['jsonName'])) ? (string)$referenceOneElement['jsonName'] : null,
@@ -126,7 +126,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
if (isset($element['referenceMany'])) {
foreach ($element['referenceMany'] AS $field => $referenceManyElement) {
$class->mapManyToMany(array(
- 'cascade' => (isset($referenceManyElement->cascade)) ? $this->getCascadeMode($referenceManyElement->cascade) : 0,
+ 'cascade' => (isset($referenceManyElement['cascade'])) ? $this->getCascadeMode($referenceManyElement['cascade']) : 0,
'targetDocument' => (string)$referenceManyElement['targetDocument'],
'fieldName' => $field,
'jsonName' => (isset($referenceManyElement['jsonName'])) ? (string)$referenceManyElement['jsonName'] : null,
@@ -166,4 +166,24 @@ protected function loadMappingFile($file)
{
return Yaml::parse($file);
}
+
+ /**
+ * Gathers a list of cascade options found in the given cascade element.
+ *
+ * @param array $cascadeElement The cascade element.
+ * @return integer a bitmask of cascade options.
+ */
+ private function getCascadeMode(array $cascadeElement)
+ {
+ $cascade = 0;
+ foreach ($cascadeElement as $cascadeMode) {
+ $constantName = 'Doctrine\ODM\CouchDB\Mapping\ClassMetadata::CASCADE_' . strtoupper($cascadeMode);
+ if (!defined($constantName)) {
+ throw new MappingException("Cascade mode '$cascadeMode' not supported.");
+ }
+ $cascade |= constant($constantName);
+ }
+
+ return $cascade;
+ }
}
Something went wrong with that request. Please try again.