Subscribers/GdprSubscriber.php
/**
     * Load or persist a PersonalData entity to a personal_data doctrine field.
     *
     * On Flush methods the process will encrypt the data if the field parameters are set isEncrypted= true.
     *
     * If the entity is newly created then set the createdOn date, and if updated then set the updatedON date.
     *
     * If loading the entity then the method will decrypt the data field.
     *
     * @param               $entity
     * @param EntityManager $em
     * @param bool          $isFlush
     * @param bool          $isNewEntity
     * @return bool
     * @throws GdprException
     */
Load or persist a PersonalData entity to a personal_data doctrine field.
On Flush methods the process will encrypt the data if the field parameters are set isEncrypted= true.

If the entity is newly created then set the createdOn date, and if updated then set the updatedON date.

If loading the entity then the method will decrypt the data field.


Load or persist a PersonalData entity to a personal_data doctrine field . On Flush methods the process will encrypt the data if the field parameters are set isEncrypted = true . If the entity is newly created then set the createdOn date and if updated then set the updatedON date . If loading the entity then the method will decrypt the data field .
protected function processFields($entity, EntityManager $em, $isFlush = true, $isNewEntity = true)
    {
        $properties = $this->getPersonalDataFields($entity, $em);
        $unitOfWork = $em->getUnitOfWork();
        $oid = spl_object_hash($entity);
        foreach ($properties as $refProperty) {
            $value = $refProperty->getValue($entity);
            if($value === null){
                continue;
            }
            if (!$value instanceof PersonalData) {
                $originalData = $value;
                $value = new PersonalData();
                $value
                    ->setData($originalData)
                    ->setCreatedOn(new \DateTime('now'))
                ;
            }
            if($isFlush) {
                $this->updateFromAnnotations(get_class($entity), $refProperty->getName(), $value);
                $now = new \DateTime('now');
                $value->setUpdatedOn($now);
                if($this->isDisabled === false && $value->isEncrypted === true) {
                    if(substr($value->getData(), -5) !== DoctrineEncryptSubscriberInterface::ENCRYPTED_SUFFIX) {
                        $encrypted = $this->encryptor->encrypt($value->getData());
                        $data = $encrypted.DoctrineEncryptSubscriberInterface::ENCRYPTED_SUFFIX;
                        $value->setData($data);
                    }
                }
            } else {
                $data = $this->decryptValue($value->getData());
                $value->setData($data);
            }
            $refProperty->setValue($entity, $value);
            if (!$isFlush) {
                $unitOfWork->setOriginalEntityProperty($oid, $refProperty->getName(), $value);
            }
        }
        return !empty($properties);
    }
protected function processFields ( $ entity , EntityManager $ em , $ isFlush = true , $ isNewEntity = true ) { $ properties = $ this -> getPersonalDataFields ( $ entity , $ em ) ; $ unitOfWork = $ em -> getUnitOfWork ( ) ; $ oid = spl_object_hash ( $ entity ) ; foreach ( $ properties as $ refProperty ) { $ value = $ refProperty -> getValue ( $ entity ) ; if ( $ value === null ) { continue ; } if ( ! $ value instanceof PersonalData ) { $ originalData = $ value ; $ value = new PersonalData ( ) ; $ value -> setData ( $ originalData ) -> setCreatedOn ( new \ DateTime ( 'now' ) ) ; } if ( $ isFlush ) { $ this -> updateFromAnnotations ( get_class ( $ entity ) , $ refProperty -> getName ( ) , $ value ) ; $ now = new \ DateTime ( 'now' ) ; $ value -> setUpdatedOn ( $ now ) ; if ( $ this -> isDisabled === false && $ value -> isEncrypted === true ) { if ( substr ( $ value -> getData ( ) , - 5 ) !== DoctrineEncryptSubscriberInterface :: ENCRYPTED_SUFFIX ) { $ encrypted = $ this -> encryptor -> encrypt ( $ value -> getData ( ) ) ; $ data = $ encrypted . DoctrineEncryptSubscriberInterface :: ENCRYPTED_SUFFIX ; $ value -> setData ( $ data ) ; } } } else { $ data = $ this -> decryptValue ( $ value -> getData ( ) ) ; $ value -> setData ( $ data ) ; } $ refProperty -> setValue ( $ entity , $ value ) ; if ( ! $ isFlush ) { $ unitOfWork -> setOriginalEntityProperty ( $ oid , $ refProperty -> getName ( ) , $ value ) ; } } return ! empty ( $ properties ) ; }
Load or persist a PersonalData entity to a personal_data doctrine field.
Load or persist a PersonalData entity to a personal_data doctrine field .
// Skip any empty values. // If the value is not an instance of PersonalData then convert it to one. // If the operation is an insertion/update then update with latest annotations and encrypt if required. // If the operation is a load then attempt to decrypt the data field. // Update the PersonalData object with the current entity annotations. // Set the updatedOn field // If encrypt bundle is not disabled, and the annotation is supposed to encrypt // If the value does not alreadty have the suffix <ENC> then encrypt it. // Set the PersonalData object back to the entity. //we don't want the object to be dirty immediately after reading