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