|
@@ 2116-2149 (lines=34) @@
|
| 2113 |
|
* |
| 2114 |
|
* @return void |
| 2115 |
|
*/ |
| 2116 |
|
private function cascadeRefresh($entity, array &$visited) |
| 2117 |
|
{ |
| 2118 |
|
$class = $this->em->getClassMetadata(get_class($entity)); |
| 2119 |
|
|
| 2120 |
|
$associationMappings = array_filter( |
| 2121 |
|
$class->associationMappings, |
| 2122 |
|
function ($assoc) { return $assoc['isCascadeRefresh']; } |
| 2123 |
|
); |
| 2124 |
|
|
| 2125 |
|
foreach ($associationMappings as $assoc) { |
| 2126 |
|
$relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity); |
| 2127 |
|
|
| 2128 |
|
switch (true) { |
| 2129 |
|
case ($relatedEntities instanceof PersistentCollection): |
| 2130 |
|
// Unwrap so that foreach() does not initialize |
| 2131 |
|
$relatedEntities = $relatedEntities->unwrap(); |
| 2132 |
|
// break; is commented intentionally! |
| 2133 |
|
|
| 2134 |
|
case ($relatedEntities instanceof Collection): |
| 2135 |
|
case (is_array($relatedEntities)): |
| 2136 |
|
foreach ($relatedEntities as $relatedEntity) { |
| 2137 |
|
$this->doRefresh($relatedEntity, $visited); |
| 2138 |
|
} |
| 2139 |
|
break; |
| 2140 |
|
|
| 2141 |
|
case ($relatedEntities !== null): |
| 2142 |
|
$this->doRefresh($relatedEntities, $visited); |
| 2143 |
|
break; |
| 2144 |
|
|
| 2145 |
|
default: |
| 2146 |
|
// Do nothing |
| 2147 |
|
} |
| 2148 |
|
} |
| 2149 |
|
} |
| 2150 |
|
|
| 2151 |
|
/** |
| 2152 |
|
* Cascades a detach operation to associated entities. |
|
@@ 2159-2192 (lines=34) @@
|
| 2156 |
|
* |
| 2157 |
|
* @return void |
| 2158 |
|
*/ |
| 2159 |
|
private function cascadeDetach($entity, array &$visited) |
| 2160 |
|
{ |
| 2161 |
|
$class = $this->em->getClassMetadata(get_class($entity)); |
| 2162 |
|
|
| 2163 |
|
$associationMappings = array_filter( |
| 2164 |
|
$class->associationMappings, |
| 2165 |
|
function ($assoc) { return $assoc['isCascadeDetach']; } |
| 2166 |
|
); |
| 2167 |
|
|
| 2168 |
|
foreach ($associationMappings as $assoc) { |
| 2169 |
|
$relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity); |
| 2170 |
|
|
| 2171 |
|
switch (true) { |
| 2172 |
|
case ($relatedEntities instanceof PersistentCollection): |
| 2173 |
|
// Unwrap so that foreach() does not initialize |
| 2174 |
|
$relatedEntities = $relatedEntities->unwrap(); |
| 2175 |
|
// break; is commented intentionally! |
| 2176 |
|
|
| 2177 |
|
case ($relatedEntities instanceof Collection): |
| 2178 |
|
case (is_array($relatedEntities)): |
| 2179 |
|
foreach ($relatedEntities as $relatedEntity) { |
| 2180 |
|
$this->doDetach($relatedEntity, $visited); |
| 2181 |
|
} |
| 2182 |
|
break; |
| 2183 |
|
|
| 2184 |
|
case ($relatedEntities !== null): |
| 2185 |
|
$this->doDetach($relatedEntities, $visited); |
| 2186 |
|
break; |
| 2187 |
|
|
| 2188 |
|
default: |
| 2189 |
|
// Do nothing |
| 2190 |
|
} |
| 2191 |
|
} |
| 2192 |
|
} |
| 2193 |
|
|
| 2194 |
|
/** |
| 2195 |
|
* Cascades a merge operation to associated entities. |