Example #1
0
File: Route.php Project: fraym/core
 /**
  * @return $this
  */
 protected function initAnnotationRoutes()
 {
     \Doctrine\Common\Annotations\AnnotationRegistry::registerFile($this->core->getApplicationDir() . '/Fraym/Annotation/Route.php');
     $coreFiles = $this->fileManager->findFiles($this->core->getApplicationDir() . DIRECTORY_SEPARATOR . 'Fraym' . DIRECTORY_SEPARATOR . '*.php');
     $extensionFiles = $this->fileManager->findFiles($this->core->getApplicationDir() . DIRECTORY_SEPARATOR . 'Extension' . DIRECTORY_SEPARATOR . '*.php');
     foreach (array_merge($coreFiles, $extensionFiles) as $file) {
         $classname = basename($file, '.php');
         $namespace = str_ireplace($this->core->getApplicationDir(), '', dirname($file));
         $namespace = str_replace('/', '\\', $namespace) . '\\';
         $namespace = preg_replace('#^' . preg_quote('\\') . 'Extension' . preg_quote('\\') . '#', '\\Fraym\\Extension\\', $namespace);
         $namespace = preg_replace('#^' . preg_quote('\\') . 'Test' . preg_quote('\\') . '#', '\\Fraym\\Test\\', $namespace);
         $namespace = preg_replace('#^' . preg_quote('\\') . 'Hook' . preg_quote('\\') . '#', '\\Fraym\\Hook\\', $namespace);
         $class = $namespace . $classname;
         if (is_file($file)) {
             require_once $file;
             if (class_exists($class)) {
                 $this->initClassAnnotationRoutes($class);
                 foreach (get_class_methods($class) as $method) {
                     $key = null;
                     $refMethod = new \ReflectionMethod($class, $method);
                     $methodAnnotation = $this->db->getAnnotationReader()->getMethodAnnotation($refMethod, 'Fraym\\Annotation\\Route');
                     if (empty($methodAnnotation) === false) {
                         $route = $methodAnnotation->value;
                         $key = $methodAnnotation->name;
                         $regex = $methodAnnotation->regex;
                         $permission = $methodAnnotation->permission;
                         $callback = [$class, $method];
                         $contextCallback = null;
                         $this->addVirtualRoute($key, $route, $callback, $contextCallback, $regex, $permission);
                     }
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * @param \Doctrine\ORM\Event\OnFlushEventArgs $eventArgs
  */
 public function onFlush(\Doctrine\ORM\Event\OnFlushEventArgs $eventArgs)
 {
     $em = $eventArgs->getEntityManager();
     $uow = $em->getUnitOfWork();
     foreach ($uow->getScheduledEntityUpdates() as $entity) {
         $lifecycleCallbacks = $this->db->getAnnotationReader()->getClassAnnotation(new \ReflectionClass($entity), 'Fraym\\Annotation\\LifecycleCallback');
         if (is_object($lifecycleCallbacks)) {
             foreach ($lifecycleCallbacks as $lifecycleEvent => $lifecycleCallback) {
                 if (__FUNCTION__ === $lifecycleEvent && count($lifecycleCallback)) {
                     foreach ($lifecycleCallback as $class => $method) {
                         $this->serviceLocator->get($class)->{$method}($entity, $eventArgs, __FUNCTION__);
                     }
                 }
             }
         }
     }
 }
Example #3
0
 /**
  * @param $entity
  * @param $propertyName
  * @param $locale
  * @param string $defaultValue
  * @return string
  */
 public function getEntityTranslation($entity, $propertyName, $locale, $defaultValue = '')
 {
     if (is_object($entity)) {
         $repository = $this->db->getRepository('\\Gedmo\\Translatable\\Entity\\Translation');
         $translations = $repository->findTranslations($entity);
         $property = new \ReflectionProperty($entity, $propertyName);
         $annotation = $this->db->getAnnotationReader()->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column');
         $value = isset($translations[$locale][$propertyName]) ? $translations[$locale][$propertyName] : $entity->{$propertyName};
         if (is_string($value) && $annotation->type === 'array') {
             $value = unserialize($value);
         } elseif (is_string($value) && $annotation->type === 'date') {
             $value = \DateTime::createFromFormat('Y-m-d', $value);
         } elseif (is_string($value) && $annotation->type === 'datetime') {
             $value = \DateTime::createFromFormat('Y-m-d H:i:s', $value);
         } elseif (is_bool($value) === false && ($annotation->type === 'boolean' || $annotation->type === 'bool')) {
             $value = $value == 1 ? true : ($value === null ? null : false);
         }
         return $value;
     }
     return $defaultValue;
 }