| @@ 1698-1727 (lines=30) @@ | ||
| 1695 | * |
|
| 1696 | * @return void |
|
| 1697 | */ |
|
| 1698 | private function cascadeRefresh($entity, array &$visited) |
|
| 1699 | { |
|
| 1700 | $class = $this->manager->getClassMetadata(get_class($entity)); |
|
| 1701 | $associationMappings = array_filter( |
|
| 1702 | $class->getAssociationMappings(), |
|
| 1703 | function ($assoc) { |
|
| 1704 | return $assoc['isCascadeRefresh']; |
|
| 1705 | } |
|
| 1706 | ); |
|
| 1707 | foreach ($associationMappings as $assoc) { |
|
| 1708 | $relatedEntities = $class->getReflectionProperty($assoc['fieldName'])->getValue($entity); |
|
| 1709 | switch (true) { |
|
| 1710 | case ($relatedEntities instanceof ApiCollection): |
|
| 1711 | // Unwrap so that foreach() does not initialize |
|
| 1712 | $relatedEntities = $relatedEntities->unwrap(); |
|
| 1713 | // break; is commented intentionally! |
|
| 1714 | case ($relatedEntities instanceof Collection): |
|
| 1715 | case (is_array($relatedEntities)): |
|
| 1716 | foreach ($relatedEntities as $relatedEntity) { |
|
| 1717 | $this->doRefresh($relatedEntity, $visited); |
|
| 1718 | } |
|
| 1719 | break; |
|
| 1720 | case ($relatedEntities !== null): |
|
| 1721 | $this->doRefresh($relatedEntities, $visited); |
|
| 1722 | break; |
|
| 1723 | default: |
|
| 1724 | // Do nothing |
|
| 1725 | } |
|
| 1726 | } |
|
| 1727 | } |
|
| 1728 | ||
| 1729 | /** |
|
| 1730 | * Cascades a detach operation to associated entities. |
|
| @@ 1737-1766 (lines=30) @@ | ||
| 1734 | * |
|
| 1735 | * @return void |
|
| 1736 | */ |
|
| 1737 | private function cascadeDetach($entity, array &$visited) |
|
| 1738 | { |
|
| 1739 | $class = $this->manager->getClassMetadata(get_class($entity)); |
|
| 1740 | $associationMappings = array_filter( |
|
| 1741 | $class->getAssociationMappings(), |
|
| 1742 | function ($assoc) { |
|
| 1743 | return $assoc['isCascadeDetach']; |
|
| 1744 | } |
|
| 1745 | ); |
|
| 1746 | foreach ($associationMappings as $assoc) { |
|
| 1747 | $relatedEntities = $class->getReflectionProperty($assoc['fieldName'])->getValue($entity); |
|
| 1748 | switch (true) { |
|
| 1749 | case ($relatedEntities instanceof ApiCollection): |
|
| 1750 | // Unwrap so that foreach() does not initialize |
|
| 1751 | $relatedEntities = $relatedEntities->unwrap(); |
|
| 1752 | // break; is commented intentionally! |
|
| 1753 | case ($relatedEntities instanceof Collection): |
|
| 1754 | case (is_array($relatedEntities)): |
|
| 1755 | foreach ($relatedEntities as $relatedEntity) { |
|
| 1756 | $this->doDetach($relatedEntity, $visited); |
|
| 1757 | } |
|
| 1758 | break; |
|
| 1759 | case ($relatedEntities !== null): |
|
| 1760 | $this->doDetach($relatedEntities, $visited); |
|
| 1761 | break; |
|
| 1762 | default: |
|
| 1763 | // Do nothing |
|
| 1764 | } |
|
| 1765 | } |
|
| 1766 | } |
|
| 1767 | ||
| 1768 | /** |
|
| 1769 | * Cascades a merge operation to associated entities. |
|