Example #1
0
 /**
  *
  */
 public function loadVirtualRoutes()
 {
     $routes = $this->db->connect()->getRepository('\\Fraym\\Route\\Entity\\VirtualRoute')->findAll();
     foreach ($routes as $route) {
         $this->addVirtualRoute($route->key, $route->route, array($route->class, $route->method));
     }
 }
Example #2
0
 /**
  * @return $this
  */
 public function init()
 {
     if (APC_ENABLED && ENV !== \Fraym\Core::ENV_DEVELOPMENT) {
         $this->cache = new \Doctrine\Common\Cache\ApcCache();
     } else {
         $this->cache = new \Doctrine\Common\Cache\ArrayCache();
     }
     $this->annotationReader = new \Doctrine\Common\Annotations\AnnotationReader();
     $this->cachedAnnotationReader = new \Doctrine\Common\Annotations\CachedReader($this->annotationReader, $this->cache);
     \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('Fraym\\Annotation', $this->core->getApplicationDir());
     \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(function ($class) {
         return class_exists($class, true);
     });
     \Doctrine\Common\Annotations\AnnotationRegistry::registerFile($this->core->getApplicationDir() . "/Fraym/Annotation/Registry.php");
     // For extension update, run always update schema
     if (is_file(self::UPDATE_SCHEMA_TRIGGER_FILE)) {
         $this->db->connect()->updateSchema();
         unlink(self::UPDATE_SCHEMA_TRIGGER_FILE);
     }
     return $this;
 }
Example #3
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;
 }
Example #4
0
 /**
  * @param $xmlString
  * @return bool|mixed|string
  * @throws \Exception
  */
 public function exec($xmlString)
 {
     $xmlString = is_array($xmlString) ? $xmlString[0] : $xmlString;
     $this->xmlString = $xmlString;
     $xml = $this->getXMLObjectFromString($this->xmlString);
     if ($xml === false) {
         throw new \Exception('XML Error');
     } elseif ($this->isBlockEnable($xml) === false) {
         return '';
     } elseif ($this->isBlockCached($xml) === true) {
         return $this->xmlString;
     } elseif ($this->isAllowedDevice($xml) === false) {
         return '';
     }
     if ($this->getXMLAttr($xml, 'id')) {
         $this->core->startTimer('blockExecution_' . $this->getXMLAttr($xml, 'id'));
     }
     if ($this->getXMLAttr($xml, 'cached') == '1') {
         $this->db->connect();
     }
     switch (strtolower($this->getXMLAttr($xml, 'type'))) {
         case 'css':
             return $this->execBlockOfTypeCSS($xml);
             break;
         case 'js':
             return $this->execBlockOfTypeJS($xml);
             break;
         case 'module':
             $blockHtml = $this->execBlockOfTypeModule($xml);
             break;
         case 'content':
             $blockHtml = $this->execBlockOfTypeContent($xml);
             break;
         case 'cache':
             $blockHtml = $this->execBlockOfTypeCache($xml);
             break;
         case 'php':
             $blockHtml = $this->execBlockOfTypePhp($xml);
             break;
         case 'image':
             $blockHtml = $this->execBlockOfTypeImage($xml);
             break;
         default:
             // extensions
             $blockHtml = $this->execBlockOfTypeExtension($xml);
             break;
     }
     return $this->processBlockAttributes($xml, $blockHtml);
 }
Example #5
0
 /**
  * Checks the session if the user is logged in.
  *
  * @Inject
  * @param \Fraym\Database\Database $db
  * @param \Fraym\Session\Session $session
  */
 public function __construct(\Fraym\Database\Database $db, \Fraym\Session\Session $session)
 {
     // call connect on caching
     $this->db = $db->connect();
     $this->session = $session;
     $userId = $this->session->get('userId', false);
     if ($this->user === false && $userId !== false) {
         $this->setUserId($userId);
         $this->session->addOnDestroyCallback(array(&$this, 'setUserAsOffline'));
     }
 }
Example #6
0
 /**
  * @param $xmlString
  * @return bool|mixed|string
  * @throws \Exception
  */
 public function exec($xmlString)
 {
     $xmlString = is_array($xmlString) ? $xmlString[0] : $xmlString;
     $this->xmlString = $xmlString;
     $xml = $this->getXmlObjectFromString($this->xmlString);
     if ($xml === false) {
         throw new \Exception('XML Error. XML Block is not supported: ' . $this->xmlString);
     } elseif ($this->isBlockEnable($xml) === false) {
         return '';
     } elseif ($this->isBlockCached($xml) === true) {
         return $this->xmlString;
     } elseif ($this->isAllowedDevice($xml) === false) {
         return '';
     }
     if ($this->getXmlAttr($xml, 'id')) {
         // interleaved unique content elements -> push element
         if ($this->user->isAdmin()) {
             $block = $this->getBaseBlock($this->getXmlAttr($xml, 'id'));
             $blockId = $block->id;
         } else {
             $blockId = $this->getXmlAttr($xml, 'id');
         }
         $this->parsingBlockIds[$blockId] = $blockId;
         $this->core->startTimer('blockExecution_' . $blockId);
     }
     if ($this->getXmlAttr($xml, 'cached') == '1') {
         $this->db->connect()->setUpTranslateable();
     }
     $blockType = strtolower($this->getXmlAttr($xml, 'type'));
     switch ($blockType) {
         case 'css':
             return $this->execBlockOfTypeCss($xml);
             break;
         case 'js':
             return $this->execBlockOfTypeJS($xml);
             break;
         case 'link':
             return $this->execBlockOfTypeLink($xml);
             break;
         case 'module':
             $blockHtml = $this->execBlockOfTypeModule($xml);
             break;
         case 'content':
             $blockHtml = $this->execBlockOfTypeContent($xml);
             break;
         case 'cache':
             $blockHtml = $this->execBlockOfTypeCache($xml);
             break;
         case 'php':
             $blockHtml = $this->execBlockOfTypePhp($xml);
             break;
         case 'image':
             $blockHtml = $this->execBlockOfTypeImage($xml);
             break;
         case 'javascript':
             $blockHtml = $this->execBlockOfTypeJavascript($xml);
             break;
         default:
             // extensions & custom block types
             if (isset($this->customBlockTypes[$blockType])) {
                 $blockHtml = call_user_func($this->customBlockTypes[$blockType]);
             } else {
                 $blockHtml = $this->execBlockOfTypeExtension($xml);
             }
             break;
     }
     return $this->processBlockAttributes($xml, $blockHtml);
 }
Example #7
0
File: Route.php Project: fraym/core
 /**
  * Trys to load a site by the requested URI.
  *
  * @return bool
  */
 public function loadSite()
 {
     // Connect database after tring to load the cache
     $this->db->connect()->setUpTranslateable()->setUpSortable();
     $this->renderSite($this->parseRoute());
 }