protected function hasChangedUsingReflection($entity)
    {
        // Get all the properties in the original entity and the current one
        $hashId                  = $this->getHashId($entity);
        $currentEntityReflection = new ReflectionClass($entity);
        $currentProperties       = $currentEntityReflection->getProperties();
        $currentPropertiesAsHash = [];

        $originalData             = $this->originalData[$hashId];
        $originalEntityReflection = new ReflectionClass($originalData);
        $originalProperties       = $originalEntityReflection->getProperties();
        $originalPropertiesAsHash = [];

        // Map each property name to its value for the current entity
        foreach ($currentProperties as $currentProperty) {
            $currentProperty->setAccessible(true);
            $currentPropertiesAsHash[$currentProperty->getName()] = $currentProperty->getValue($entity);
        }

        // Map each property name to its value for the original entity
        foreach ($originalProperties as $originalProperty) {
            $originalProperty->setAccessible(true);
            $originalPropertiesAsHash[$originalProperty->getName()] = $originalProperty->getValue($originalData);
        }

        if (count($originalProperties) != count($currentProperties)) {
            // Clearly there's a difference here, so update
            return true;
        }

        // Compare all the property values to see if they are identical
        foreach ($originalPropertiesAsHash as $name => $value) {
            if (!array_key_exists($name, $currentPropertiesAsHash) || $currentPropertiesAsHash[$name] !== $value) {
                return true;
            }
        }

        return false;
    }
protected function hasChangedUsingReflection($entity)
    {
        // Get all the properties in the original entity and the current one
        $hashId                  = $this->getHashId($entity);
        $currentEntityReflection = new ReflectionClass($entity);
        $currentProperties       = $currentEntityReflection->getProperties();
        $currentPropertiesAsHash = [];

        $originalData             = $this->originalData[$hashId];
        $originalEntityReflection = new ReflectionClass($originalData);
        $originalProperties       = $originalEntityReflection->getProperties();
        $originalPropertiesAsHash = [];

        // Map each property name to its value for the current entity
        foreach ($currentProperties as $currentProperty) {
            $currentProperty->setAccessible(true);
            $currentPropertiesAsHash[$currentProperty->getName()] = $currentProperty->getValue($entity);
        }

        // Map each property name to its value for the original entity
        foreach ($originalProperties as $originalProperty) {
            $originalProperty->setAccessible(true);
            $originalPropertiesAsHash[$originalProperty->getName()] = $originalProperty->getValue($originalData);
        }

        if (count($originalProperties) != count($currentProperties)) {
            // Clearly there's a difference here, so update
            return true;
        }

        // Compare all the property values to see if they are identical
        foreach ($originalPropertiesAsHash as $name => $value) {
            if (!array_key_exists($name, $currentPropertiesAsHash) || $currentPropertiesAsHash[$name] !== $value) {
                return true;
            }
        }

        return false;
    }
protected function hasChangedUsingReflection ( $ entity ) { // Get all the properties in the original entity and the current one $ hashId = $ this -> getHashId ( $ entity ) ; $ currentEntityReflection = new ReflectionClass ( $ entity ) ; $ currentProperties = $ currentEntityReflection -> getProperties ( ) ; $ currentPropertiesAsHash = [ ] ; $ originalData = $ this -> originalData [ $ hashId ] ; $ originalEntityReflection = new ReflectionClass ( $ originalData ) ; $ originalProperties = $ originalEntityReflection -> getProperties ( ) ; $ originalPropertiesAsHash = [ ] ; // Map each property name to its value for the current entity foreach ( $ currentProperties as $ currentProperty ) { $ currentProperty -> setAccessible ( true ) ; $ currentPropertiesAsHash [ $ currentProperty -> getName ( ) ] = $ currentProperty -> getValue ( $ entity ) ; } // Map each property name to its value for the original entity foreach ( $ originalProperties as $ originalProperty ) { $ originalProperty -> setAccessible ( true ) ; $ originalPropertiesAsHash [ $ originalProperty -> getName ( ) ] = $ originalProperty -> getValue ( $ originalData ) ; } if ( count ( $ originalProperties ) != count ( $ currentProperties ) ) { // Clearly there's a difference here, so update return true ; } // Compare all the property values to see if they are identical foreach ( $ originalPropertiesAsHash as $ name => $ value ) { if ( ! array_key_exists ( $ name , $ currentPropertiesAsHash ) || $ currentPropertiesAsHash [ $ name ] !== $ value ) { return true ; } } return false ; }
Checks to see if an entity has changed using reflection

@param   object $entity The entity to check for changes

@return  boolean  True if the entity has changed, otherwise false
Checks to see if an entity has changed using reflection