Exemplo n.º 1
0
 public function load($controller, $action)
 {
     /**
      * Opening template file
      */
     $dirs = \Biome\Biome::getDirs('views');
     $template_file = '';
     foreach ($dirs as $dir) {
         $path = $dir . '/' . $controller . '.xml';
         if (!file_exists($path)) {
             continue;
         }
         $template_file = $path;
     }
     if (!file_exists($template_file)) {
         throw new \Biome\Core\View\Exception\TemplateNotFoundException('Missing template file for ' . $controller . '->' . $action);
     }
     $tree = TemplateReader::loadFilename($template_file);
     View\Component::$view = $this;
     if ($tree['value'] instanceof \Biome\Component\ViewsComponent) {
         $node = $tree['value'];
         $node->load($action);
         $this->_tree = $node;
     }
 }
Exemplo n.º 2
0
 private static function classloader($class_name, $type)
 {
     $dirs = \Biome\Biome::getDirs($type);
     if (empty($dirs)) {
         return FALSE;
     }
     $filename = '';
     foreach ($dirs as $d) {
         if (!file_exists($d)) {
             continue;
         }
         $files = scandir($d);
         foreach ($files as $f) {
             if ($f[0] == '.') {
                 continue;
             }
             if (strtolower($f) == strtolower($class_name) . '.php') {
                 $filename = $d . '/' . $f;
             }
         }
     }
     if (file_exists($filename)) {
         Logger::debug('Load class in ' . $filename);
         include_once $filename;
         return TRUE;
     }
     return FALSE;
 }
Exemplo n.º 3
0
 public static function getObjects()
 {
     $modelsDirs = \Biome\Biome::getDirs('models');
     /**
      * List existings models.
      */
     $objects_list = array();
     foreach ($modelsDirs as $dir) {
         if (!file_exists($dir)) {
             continue;
         }
         $filenames = scandir($dir);
         foreach ($filenames as $file) {
             if ($file[0] == '.') {
                 continue;
             }
             $object_name = substr($file, 0, -4);
             $objects_list[$object_name] = $object_name;
         }
     }
     $objects = array();
     foreach ($objects_list as $object_name) {
         $objects[$object_name] = self::get($object_name);
     }
     return $objects;
 }
Exemplo n.º 4
0
 protected function load()
 {
     $lang_dirs = \Biome\Biome::getDirs('resources');
     $reverse_locales = array_reverse($this->locales);
     foreach ($lang_dirs as $dir) {
         /**
          * Read default language file.
          */
         $locale_dir = $dir . '/string/';
         if (!file_exists($locale_dir)) {
             continue;
         }
         $files = scandir($locale_dir);
         foreach ($files as $file) {
             if ($file[0] == '.') {
                 continue;
             }
             if (substr($file, -4) != '.xml') {
                 continue;
             }
             $xmlFile = $locale_dir . '/' . $file;
             $this->read($xmlFile);
         }
         /**
          * Read locale language file.
          */
         foreach ($reverse_locales as $locale) {
             $raw = explode('_', $locale);
             $locale = $raw[0];
             $locale_dir = $dir . '/string/' . $locale . '/';
             if (!file_exists($locale_dir)) {
                 continue;
             }
             $files = scandir($locale_dir);
             foreach ($files as $file) {
                 if ($file[0] == '.') {
                     continue;
                 }
                 if (substr($file, -4) != '.xml') {
                     continue;
                 }
                 $xmlFile = $locale_dir . '/' . $file;
                 $this->read($xmlFile);
             }
         }
     }
 }
Exemplo n.º 5
0
 public static function loadFilename($filename)
 {
     $xml_contents = file_get_contents($filename);
     $reader = new Reader();
     /**
      * Loading components
      */
     $components_list = array();
     $components = scandir(__DIR__ . '/../../Component/');
     foreach ($components as $file) {
         if ($file[0] == '.') {
             continue;
         }
         if (substr($file, -4) != '.php') {
             continue;
         }
         $componentName = substr($file, 0, -strlen('Component.php'));
         $components_list['{http://github.com/mermetbt/Biome/}' . strtolower($componentName)] = 'Biome\\Component\\' . $componentName . 'Component';
     }
     $components_dirs = \Biome\Biome::getDirs('components');
     $components_dirs = array_reverse($components_dirs);
     foreach ($components_dirs as $dir) {
         if (!file_exists($dir)) {
             continue;
         }
         $components = scandir($dir);
         foreach ($components as $file) {
             if ($file[0] == '.') {
                 continue;
             }
             if (substr($file, -4) != '.php') {
                 continue;
             }
             $componentName = substr($file, 0, -strlen('Component.php'));
             $components_list['{http://github.com/mermetbt/Biome/}' . strtolower($componentName)] = $componentName . 'Component';
         }
     }
     $reader->elementMap = $components_list;
     /**
      * Parsing XML template
      */
     $reader->xml($xml_contents);
     $tree = $reader->parse();
     return $tree;
 }
Exemplo n.º 6
0
 public function renderComponent()
 {
     $components_dirs = \Biome\Biome::getDirs('components');
     $components_dirs[] = __DIR__ . '/../../Component/';
     $components_dirs = array_reverse($components_dirs);
     foreach ($components_dirs as $dir) {
         if (file_exists($dir . '/templates/' . $this->_nodename . '.php')) {
             $component_template_file = $dir . '/templates/' . $this->_nodename . '.php';
         }
     }
     if (file_exists($component_template_file)) {
         ob_start();
         $view = self::$view;
         include $component_template_file;
         $content = ob_get_contents();
         ob_end_clean();
     } else {
         throw new \Exception('Template file not found: ' . $component_template_file . ' for component ' . get_called_class() . ' - ' . $this->_fullname);
     }
     return $content;
 }
Exemplo n.º 7
0
 public function building()
 {
     $filename = $this->getAttribute('src');
     $dirs = \Biome\Biome::getDirs('views');
     $template_file = '';
     foreach ($dirs as $dir) {
         $path = $dir . '/' . $filename;
         if (!file_exists($path)) {
             continue;
         }
         $template_file = $path;
     }
     if (!file_exists($template_file)) {
         throw new \Exception('Unable to load template file: ' . $filename);
     }
     $nodes = TemplateReader::loadFilename($template_file);
     // 		print_r($nodes);
     //
     // 		echo '<br/>';
     // 		print_r($this->value);
     // 		die();
     $this->_value = $nodes['value']->_value;
     return TRUE;
 }
Exemplo n.º 8
0
 /**
  * This method generate all the route available in the controllers.
  */
 public function autoroute()
 {
     /**
      * Generating all routes.
      */
     $cache = NULL;
     $classname_routes = NULL;
     if (\Biome\Biome::hasService('staticcache')) {
         $cache = \Biome\Biome::getService('staticcache');
         $classname_routes = $cache->get('classname_routes');
     }
     if (empty($classname_routes)) {
         $controllers_dirs = \Biome\Biome::getDirs('controllers');
         $controllers_dirs = array_reverse($controllers_dirs);
         foreach ($controllers_dirs as $dir) {
             $files = scandir($dir);
             foreach ($files as $file) {
                 if ($file[0] == '.') {
                     continue;
                 }
                 if (substr($file, -14) != 'Controller.php') {
                     continue;
                 }
                 $controller_name = substr($file, 0, -14);
                 $controller_name = strtolower($controller_name);
                 // Skip if already defined!
                 if (isset($this->classname_routes[$controller_name])) {
                     continue;
                 }
                 $this->classname_routes[$controller_name] = $this->getRoutesFromControllerName($controller_name);
             }
         }
         if (!empty($cache)) {
             $cache->store('classname_routes', $this->classname_routes);
         }
     } else {
         $this->classname_routes = $classname_routes;
     }
     foreach ($this->classname_routes as $controller_name => $actions) {
         foreach ($actions as $type => $action) {
             foreach ($action as $name => $meta) {
                 $method = function (Request $request, Response $response, array $args) use($type, $controller_name, $name, $meta) {
                     /* Initialize the controller. */
                     $ctrl = new $meta['controller']($request, $response);
                     $method_params = array();
                     foreach ($meta['parameters'] as $param) {
                         switch (strtolower($param['type'])) {
                             case 'biome\\core\\orm\\models':
                                 $type_param = $ctrl->objectName();
                                 break;
                             case 'biome\\core\\collection':
                                 $type_param = $ctrl->collectionName() . 'Collection';
                                 break;
                             default:
                                 $type_param = $param['type'];
                         }
                         $method_params[] = $this->parameterInjection($type_param, $param['name'], $param['required'], $args);
                     }
                     /* Execute the action. */
                     return $ctrl->process($type, $controller_name, $name, $meta['action'], $method_params);
                 };
                 $route_path = $meta['path'];
                 $this->addRoute($type, $route_path, $method);
                 $this->routes_list[] = array('method' => $type, 'path' => $route_path);
                 if ($name == 'index') {
                     $route_path = '/' . $controller_name;
                     $this->addRoute($type, $route_path, $method);
                     $this->routes_list[] = array('method' => $type, 'path' => $route_path);
                 }
                 if ($controller_name == 'index' && $name == 'index') {
                     $route_path = '/' . $controller_name . '/' . $name;
                     $this->addRoute($type, $route_path, $method);
                     $this->routes_list[] = array('method' => $type, 'path' => $route_path);
                 }
             }
         }
     }
 }