/** * @param \Doctrine\Common\EventArgs $args * @return boolean * * @author Etienne de Longeaux <*****@*****.**> */ protected function isChangePosition($eventArgs, $type) { $entity = $eventArgs->getEntity(); $entityManager = $eventArgs->getEntityManager(); $entity_name = get_class($entity); $metadata = $entityManager->getClassMetadata($entity_name); $reflectionClass = new ReflectionClass($entity); $properties = $reflectionClass->getProperties(); // $_is_change_position = false; if (isset($GLOBALS['ENTITIES'][$type]) && isset($GLOBALS['ENTITIES'][$type][$entity_name])) { if (is_array($GLOBALS['ENTITIES'][$type][$entity_name])) { $route = $this->container->get('request')->get('_route'); if (empty($route) || $route == "_internal") { $route = $this->container->get('sfynx.tool.route.factory')->getMatchParamOfRoute('_route', $this->container->get('request')->getLocale()); } if (in_array($route, $GLOBALS['ENTITIES'][$type][$entity_name])) { $_is_change_position = true; } } elseif ($GLOBALS['ENTITIES'][$type][$entity_name] == true) { $_is_change_position = true; } } else { foreach ($properties as $refProperty) { //print_r($this->annReader->getPropertyAnnotations($refProperty)); if ($this->annReader->getPropertyAnnotation($refProperty, $this->annotationclass)) { // we have annotation and if it decrypt operation, we must avoid duble decryption $propName = $refProperty->getName(); $methodName = \Sfynx\ToolBundle\Util\PiStringManager::capitalize($propName); if ($reflectionClass->hasMethod($getter = 'get' . $methodName) && $reflectionClass->hasMethod($setter = 'set' . $methodName)) { // we get the route name $route = $this->container->get('request')->get('_route'); if (empty($route) || $route == "_internal") { $route = $this->container->get('sfynx.tool.route.factory')->getMatchParamOfRoute('_route', $this->container->get('request')->getLocale()); } // $properties = $this->annReader->getPropertyAnnotation($refProperty, $this->annotationclass); if ($properties->routes === true || is_array($properties->routes) && in_array($route, $properties->routes)) { $_is_change_position = true; } } } } } return $_is_change_position; }
/** * Process (encrypt/decrypt) entities fields * * @param LifecycleEventArgs $args * @param Boolean $isEncryptOperation If true - encrypt, false - decrypt entity * * @return void * @access protected * @author etienne de Longeaux <*****@*****.**> */ protected function processFields(LifecycleEventArgs $args, $isEncryptOperation = true) { if ($this->_load_enabled == true) { $entity = $args->getEntity(); $em = $args->getEntityManager(); $className = get_class($entity); $metadata = $em->getClassMetadata($className); $encryptorMethod = $isEncryptOperation ? 'encrypt' : 'decrypt'; $reflectionClass = new ReflectionClass($entity); $properties = $reflectionClass->getProperties(); foreach ($properties as $refProperty) { foreach ($this->options as $key => $encrypter) { if (isset($encrypter['encryptor_annotation_name']) && isset($encrypter['encryptor_class']) && isset($encrypter['encryptor_options'])) { $this->encryptor = $this->getEncryptorService($key); if ($this->annReader->getPropertyAnnotation($refProperty, $encrypter['encryptor_annotation_name'])) { // we have annotation and if it decrypt operation, we must avoid duble decryption $propName = $refProperty->getName(); if ($refProperty->isPublic()) { $entity->{$propName} = $this->encryptor->{$encryptorMethod}($refProperty->getValue()); } else { $methodName = \Sfynx\ToolBundle\Util\PiStringManager::capitalize($propName); if ($reflectionClass->hasMethod($getter = 'get' . $methodName) && $reflectionClass->hasMethod($setter = 'set' . $methodName)) { if ($isEncryptOperation) { // we set the encrypt value $currentPropValue = $entity->{$getter}(); if (!empty($currentPropValue)) { $currentPropValue = $this->encryptor->{$encryptorMethod}($currentPropValue); } // we set locale value $entity->{$setter}($currentPropValue); } else { // we get the locale value $locale = $entity->getTranslatableLocale(); // if (!empty($locale) && !is_null($locale)) { } elseif (isset($_GET['_locale'])) { $locale = $_GET['_locale']; } else { $locale = $this->locale; } // if (!$this->annReader->getPropertyAnnotation($refProperty, 'Gedmo\\Mapping\\Annotation\\Translatable')) { if (!$this->hasInDecodedRegistry($className, $entity->getId(), $locale, $methodName)) { $currentPropValue = $entity->{$getter}(); if (!empty($currentPropValue)) { $currentPropValue = $this->encryptor->{$encryptorMethod}($currentPropValue); } $entity->{$setter}($currentPropValue); $this->addToDecodedRegistry($className, $entity->getId(), $locale, $methodName, $currentPropValue); } } else { $locales = $this->container->get('sfynx.auth.locale_manager')->getAllLocales(true); foreach ($locales as $key => $lang) { if ($lang['enabled'] == 1) { if (!$this->hasInDecodedRegistry($className, $entity->getId(), $lang['id'], $methodName)) { $currentPropValue_locale = $entity->translate($lang['id'])->{$getter}(); if (!empty($currentPropValue_locale)) { $currentPropValue_locale = $this->encryptor->{$encryptorMethod}($currentPropValue_locale); } if ($locale == $lang['id']) { $entity->{$setter}($currentPropValue_locale); } $entity->translate($lang['id'])->{$setter}($currentPropValue_locale); $this->addToDecodedRegistry($className, $entity->getId(), $lang['id'], $methodName, $currentPropValue_locale); //print_r($this->decodedRegistry); } } } } } } else { throw new \RuntimeException(sprintf("Property %s isn't public and doesn't has getter/setter")); } } } } else { throw new \RuntimeException(sprintf("encrypter %s is not correctly configured", $key)); } } } } }