@@ 1757-1786 (lines=30) @@ | ||
1754 | * |
|
1755 | * @return void |
|
1756 | */ |
|
1757 | private function cascadeRefresh($entity, array &$visited) |
|
1758 | { |
|
1759 | $class = $this->manager->getClassMetadata(get_class($entity)); |
|
1760 | $associationMappings = array_filter( |
|
1761 | $class->getAssociationMappings(), |
|
1762 | function ($assoc) { |
|
1763 | return $assoc['isCascadeRefresh']; |
|
1764 | } |
|
1765 | ); |
|
1766 | foreach ($associationMappings as $assoc) { |
|
1767 | $relatedEntities = $class->getReflectionProperty($assoc['fieldName'])->getValue($entity); |
|
1768 | switch (true) { |
|
1769 | case ($relatedEntities instanceof ApiCollection): |
|
1770 | // Unwrap so that foreach() does not initialize |
|
1771 | $relatedEntities = $relatedEntities->unwrap(); |
|
1772 | // break; is commented intentionally! |
|
1773 | case ($relatedEntities instanceof Collection): |
|
1774 | case (is_array($relatedEntities)): |
|
1775 | foreach ($relatedEntities as $relatedEntity) { |
|
1776 | $this->doRefresh($relatedEntity, $visited); |
|
1777 | } |
|
1778 | break; |
|
1779 | case ($relatedEntities !== null): |
|
1780 | $this->doRefresh($relatedEntities, $visited); |
|
1781 | break; |
|
1782 | default: |
|
1783 | // Do nothing |
|
1784 | } |
|
1785 | } |
|
1786 | } |
|
1787 | ||
1788 | /** |
|
1789 | * Cascades a detach operation to associated entities. |
|
@@ 1796-1825 (lines=30) @@ | ||
1793 | * |
|
1794 | * @return void |
|
1795 | */ |
|
1796 | private function cascadeDetach($entity, array &$visited) |
|
1797 | { |
|
1798 | $class = $this->manager->getClassMetadata(get_class($entity)); |
|
1799 | $associationMappings = array_filter( |
|
1800 | $class->getAssociationMappings(), |
|
1801 | function ($assoc) { |
|
1802 | return $assoc['isCascadeDetach']; |
|
1803 | } |
|
1804 | ); |
|
1805 | foreach ($associationMappings as $assoc) { |
|
1806 | $relatedEntities = $class->getReflectionProperty($assoc['fieldName'])->getValue($entity); |
|
1807 | switch (true) { |
|
1808 | case ($relatedEntities instanceof ApiCollection): |
|
1809 | // Unwrap so that foreach() does not initialize |
|
1810 | $relatedEntities = $relatedEntities->unwrap(); |
|
1811 | // break; is commented intentionally! |
|
1812 | case ($relatedEntities instanceof Collection): |
|
1813 | case (is_array($relatedEntities)): |
|
1814 | foreach ($relatedEntities as $relatedEntity) { |
|
1815 | $this->doDetach($relatedEntity, $visited); |
|
1816 | } |
|
1817 | break; |
|
1818 | case ($relatedEntities !== null): |
|
1819 | $this->doDetach($relatedEntities, $visited); |
|
1820 | break; |
|
1821 | default: |
|
1822 | // Do nothing |
|
1823 | } |
|
1824 | } |
|
1825 | } |
|
1826 | ||
1827 | /** |
|
1828 | * Cascades a merge operation to associated entities. |