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