Пример #1
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__);
                     }
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  * @return $this
  */
 public function load()
 {
     $phpFiles = $this->fileManager->findFiles('Hook' . DIRECTORY_SEPARATOR . '*.php');
     foreach ($phpFiles as $phpFile) {
         require_once $phpFile;
         $loadedClasses = get_declared_classes();
         $class = end($loadedClasses);
         $reflector = new \ReflectionClass($class);
         $parentClass = $reflector->getParentClass();
         if ($parentClass) {
             $shortNameClass = str_replace('Fraym\\Hook\\', 'Fraym\\', $reflector->getName());
             $shortNameClassHook = $parentClass->getName();
             if ($shortNameClass === $shortNameClassHook) {
                 $this->serviceLocator->set($parentClass->name, $this->serviceLocator->get($class));
                 $this->_hooks[$class] = $parentClass->name;
             }
         }
     }
     return $this;
 }
Пример #3
0
 /**
  * Executes the extension function to render the view for the extension config.
  */
 private function getExtensionConfigView()
 {
     $id = $this->request->gp('id', false);
     $blockId = $this->request->gp('blockId', null);
     if ($id) {
         $extension = $this->db->getRepository('\\Fraym\\Block\\Entity\\BlockExtension')->findOneById($id);
         if ($extension) {
             $instance = $this->serviceLocator->get($extension->class);
             $configMethod = $extension->configMethod;
             if (method_exists($instance, $configMethod)) {
                 $instance->{$configMethod}($blockId);
             }
         }
     }
 }
Пример #4
0
 /**
  * @param $id
  * @return bool
  */
 public function unregisterExtension($id)
 {
     $entry = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Registry')->findOneById($id);
     if ($entry) {
         $this->db->remove($entry);
         $this->db->flush();
         $unregisteredExtensions = $this->getUnregisteredExtensions();
         foreach ($unregisteredExtensions as $class => $classAnnotation) {
             $this->removeEntities($classAnnotation);
             if (isset($classAnnotation->onUnregister)) {
                 call_user_func_array(array($this->serviceLocator->get($class), $classAnnotation->onUnregister), array($classAnnotation));
             }
         }
         return true;
     }
     return false;
 }
Пример #5
0
 /**
  * @param $id
  * @return bool
  */
 public function unregisterExtension($id)
 {
     $entry = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Registry')->findOneById($id);
     if ($entry) {
         $className = $entry->className;
         $this->db->remove($entry);
         $this->db->flush();
         $unregisteredExtensions = $this->getUnregisteredExtensions();
         $extension = $unregisteredExtensions[$className];
         $this->removeEntities($extension);
         if (isset($extension->onUnregister)) {
             call_user_func_array([$this->serviceLocator->get($className), $extension->onUnregister], [$extension]);
         }
         return true;
     }
     return false;
 }
Пример #6
0
 /**
  * @return bool
  */
 protected function install()
 {
     if ($this->writeConfig($this->_configFile)) {
         // Disable max script exec time, because creating database shema takes some time
         set_time_limit(0);
         include_once $this->_configFile;
         $this->serviceLocator->set('db.options', ['driver' => DB_DRIVER, 'user' => DB_USER, 'password' => DB_PASS, 'host' => DB_HOST, 'dbname' => DB_NAME, 'charset' => DB_CHARSET]);
         $this->cache->clearAll();
         $this->db->connect()->getSchemaTool()->dropDatabase();
         $this->db->createSchema();
         if (($errors = $this->initConfigurations()) !== true) {
             unlink($this->_configFile);
             $this->view->assign('error', implode('<br />', $errors));
             return false;
         }
         return true;
     }
     return false;
 }
Пример #7
0
 /**
  * @return mixed
  */
 public function fileViewer()
 {
     if ($this->user->isAdmin() === false) {
         return;
     }
     $fileContent = $this->request->post('fileContent', false);
     $storage = $this->request->gp('storage');
     $path = $this->request->gp('path');
     $cmd = $this->request->gp('cmd');
     $cropOpt = $this->request->gp('cropOpt');
     $fullPath = $this->fileManager->pathExists($storage, $path);
     if ($fullPath) {
         $content = '';
         $inlineImage = null;
         if (is_file($fullPath)) {
             if ($fileContent) {
                 file_put_contents($fullPath, $fileContent);
             }
             $content = file_get_contents($fullPath);
         }
         $pathinfo = pathinfo($fullPath);
         if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], array('png', 'gif', 'jpg', 'jpeg', 'bmp', 'tiff'))) {
             if ($cmd === 'crop') {
                 $cropFilename = dirname($fullPath) . DIRECTORY_SEPARATOR . 'crop_' . implode('_', $cropOpt) . basename($fullPath);
                 /**
                  * var \Imagine\Gd\Imagine $imagine
                  */
                 $imagine = $this->serviceLocator->get('Imagine');
                 $image = $imagine->open($fullPath);
                 $image->crop(new \Imagine\Image\Point($cropOpt['x'], $cropOpt['y']), new \Imagine\Image\Box($cropOpt['w'], $cropOpt['h']))->save($cropFilename);
                 $fullPath = $cropFilename;
             }
             $size = getimagesize($fullPath);
             $inlineImage = 'data:' . $size['mime'] . ';base64,' . base64_encode(file_get_contents($fullPath));
         }
         $this->view->assign('inlineImage', $inlineImage);
         $this->view->assign('storage', $storage);
         $this->view->assign('file', basename($fullPath));
         $this->view->assign('path', $path);
         $this->view->assign('content', $content);
     }
     return $this->siteManagerController->getIframeContent($this->view->fetch('FileViewer'));
 }
Пример #8
0
 /**
  * @param $xml
  * @return string
  */
 protected function execBlockOfTypeModule($xml)
 {
     $html = '';
     if ($this->execModule === true) {
         $class = (string) $xml->class;
         $function = (string) $xml->method;
         $result = null;
         ob_start();
         if (empty($function) === false) {
             $instance = $this->serviceLocator->get($class);
             $result = $instance->{$function}($xml);
         }
         if ($result === true || $result === null) {
             $html = ob_get_clean();
         } else {
             ob_clean();
         }
     }
     return $html;
 }
Пример #9
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $template = null;
     $dataSource = null;
     $locale = $this->locale->getLocale();
     $variables = unserialize((string) $xml->dynamicTemplateConfig);
     if (!empty((string) $xml->dynamicTemplate)) {
         $template = $this->getTemplatePath() . DIRECTORY_SEPARATOR . (string) $xml->dynamicTemplate;
     }
     $obj = $this->getTemplateXmlObject((string) $xml->dynamicTemplate);
     if (isset($obj->dataSource)) {
         $dataSource = $obj->dataSource;
         $class = (string) $dataSource->class;
         $method = (string) $dataSource->method;
         if (method_exists($class, $method)) {
             $classObj = $this->serviceLocator->get($class);
             $dataSource = $classObj->{$method}($locale->id, $variables);
         }
     }
     $this->dynamicTemplateController->render($template, $locale->id, $variables, $dataSource);
 }
Пример #10
0
 /**
  * @param $name
  * @return null
  */
 public function getInstance($name)
 {
     return $this->serviceLocator->get($name);
 }
Пример #11
0
 /**
  * @return bool
  */
 public function checkVirtualRoute()
 {
     foreach ($this->virutalRoutes as $data) {
         $isRelativeRoute = substr($data->route, 0, 1) === '/' ? false : true;
         $route = rtrim($this->getSiteBaseURI(false), '/') . $data->route;
         if ($this->core->isCLI() && $route == $this->getRequestRoute(false, false) || ($isRelativeRoute === true && ltrim($this->getAddionalURI(), '/') == $data->route || $isRelativeRoute === false && $route == $this->getRequestRoute(false, false))) {
             $controller = $data->controller;
             $action = $data->action;
             $instance = $this->serviceLocator->get($controller);
             return $instance->{$action}();
         }
     }
     return false;
 }
Пример #12
0
 /**
  * @param bool $inContext
  * @return bool
  */
 public function getVirtualRouteContent($inContext = false)
 {
     $requestRoute = $this->getRequestRoute(false, false);
     $requestRouteWithoutBase = $this->getRequestRoute(true, true);
     $addionalUri = $this->getAddionalUri();
     $siteBaseUri = $this->getSiteBaseUri(false);
     foreach ($this->virutalRoutes as $data) {
         if ($data->inContext !== $inContext) {
             continue;
         }
         $route = null;
         $callbackResult = false;
         if (is_array($data->route)) {
             $callback = [$this->serviceLocator->get(key($data->route)), reset($data->route)];
             $callbackResult = call_user_func_array($callback, [$data, $requestRouteWithoutBase]);
         } else {
             $route = rtrim($siteBaseUri, '/') . $data->route;
         }
         if ($callbackResult === true || $this->core->isCLI() && $route === $requestRoute || ($route === $requestRoute || $data->regex === true && preg_match($data->route, $addionalUri, $this->routeMatches))) {
             $allowAccess = false;
             if (count($data->permission)) {
                 $className = key($data->permission);
                 $methodName = reset($data->permission);
                 $obj = $this->serviceLocator->get($className);
                 $allowAccess = $obj->{$methodName}();
             }
             if (count($data->permission) === 0 || $allowAccess) {
                 if ($inContext && is_array($data->contextCallback)) {
                     if (count($data->contextCallback) === 2) {
                         $menuItemTranslation = call_user_func([$this->serviceLocator->get($data->contextCallback[0]), $data->contextCallback[1]]);
                         if ($menuItemTranslation) {
                             $this->setupPage($menuItemTranslation);
                         }
                     }
                     return true;
                 } elseif ($inContext === false) {
                     $controller = $data->controller;
                     $action = $data->action;
                     $instance = $this->serviceLocator->get($controller);
                     return $instance->{$action}();
                 }
             }
         }
     }
     return false;
 }