src/Sulu/Component/Persistence/RelationTrait.php
public function compareData(
        $entities,
        array $requestEntities,
        callable $compare = null,
        callable $add = null,
        callable $update = null,
        callable $delete = null
    ) {
        $success = true;

        if (!empty($entities)) {
            foreach ($entities as $entity) {
                $matchedEntry = null;
                $matchedKey = null;

                // find match callback
                $compare($entity, $requestEntities, $matchedEntry, $matchedKey);

                if (null == $matchedEntry && null != $delete) {
                    // delete entity if it is not listed anymore
                    $delete($entity);
                } elseif (null != $update) {
                    // update entity if it is matched
                    $success = $update($entity, $matchedEntry);
                    if (!$success) {
                        break;
                    }
                }

                // Remove done element from array
                if (null !== $matchedKey) {
                    unset($requestEntities[$matchedKey]);
                }
            }
        }

        // The entity which have not been delete or updated have to be added
        if (!empty($requestEntities) && null != $add) {
            foreach ($requestEntities as $entity) {
                if (!$success) {
                    break;
                }
                $success = $add($entity);
            }
        }

        return $success;
    }
public function compareData(
        $entities,
        array $requestEntities,
        callable $compare = null,
        callable $add = null,
        callable $update = null,
        callable $delete = null
    ) {
        $success = true;

        if (!empty($entities)) {
            foreach ($entities as $entity) {
                $matchedEntry = null;
                $matchedKey = null;

                // find match callback
                $compare($entity, $requestEntities, $matchedEntry, $matchedKey);

                if (null == $matchedEntry && null != $delete) {
                    // delete entity if it is not listed anymore
                    $delete($entity);
                } elseif (null != $update) {
                    // update entity if it is matched
                    $success = $update($entity, $matchedEntry);
                    if (!$success) {
                        break;
                    }
                }

                // Remove done element from array
                if (null !== $matchedKey) {
                    unset($requestEntities[$matchedKey]);
                }
            }
        }

        // The entity which have not been delete or updated have to be added
        if (!empty($requestEntities) && null != $add) {
            foreach ($requestEntities as $entity) {
                if (!$success) {
                    break;
                }
                $success = $add($entity);
            }
        }

        return $success;
    }
public function compareData ( $ entities , array $ requestEntities , callable $ compare = null , callable $ add = null , callable $ update = null , callable $ delete = null ) { $ success = true ; if ( ! empty ( $ entities ) ) { foreach ( $ entities as $ entity ) { $ matchedEntry = null ; $ matchedKey = null ; // find match callback $ compare ( $ entity , $ requestEntities , $ matchedEntry , $ matchedKey ) ; if ( null == $ matchedEntry && null != $ delete ) { // delete entity if it is not listed anymore $ delete ( $ entity ) ; } elseif ( null != $ update ) { // update entity if it is matched $ success = $ update ( $ entity , $ matchedEntry ) ; if ( ! $ success ) { break ; } } // Remove done element from array if ( null !== $ matchedKey ) { unset ( $ requestEntities [ $ matchedKey ] ) ; } } } // The entity which have not been delete or updated have to be added if ( ! empty ( $ requestEntities ) && null != $ add ) { foreach ( $ requestEntities as $ entity ) { if ( ! $ success ) { break ; } $ success = $ add ( $ entity ) ; } } return $ success ; }
function compares entities with data of array and makes callback.

@param $entities
@param array $requestEntities
@param callable $compare
@param callable $add
@param callable $update
@param callable $delete

@return bool
function compares entities with data of array and makes callback .