Пример #1
0
 public function load($className)
 {
     $config = \vendor\Config::get('autoload');
     $file = $config['class_path'] . '/' . str_replace("\\", "/", $className) . '.php';
     if (file_exists($file)) {
         require $file;
     } else {
         return false;
     }
 }
Пример #2
0
 public function start($route)
 {
     $this->config = \vendor\Config::get('routes');
     if (empty($route) || $route == '/') {
         if (isset($this->config['default'])) {
             $route = $this->config['default'];
         } else {
             $this->error();
         }
     }
     try {
         foreach ($this->config['routes'] as $path => $defaults) {
             $regex = '@' . preg_replace('@:([\\w]+)@', '(?P<$1>[^/]+)', str_replace(')', ')?', (string) $path)) . '@';
             $matches = [];
             if (preg_match($regex, $route, $matches)) {
                 $options = $defaults;
                 foreach ($matches as $key => $value) {
                     if (is_numeric($key)) {
                         continue;
                     }
                     $options[$key] = $value;
                     if (isset($defaults[$key])) {
                         if (strpos($defaults[$key], ":key") !== false) {
                             $options[$key] = str_replace(":key", $value, $defaults[$key]);
                         }
                     }
                 }
                 if (isset($options['controller']) && isset($options['action'])) {
                     $callable = [$options['controller'], $options['action'] . 'Action'];
                     if (is_callable($callable)) {
                         $callable = [new $options['controller'](), $options['action'] . 'Action'];
                         $callable($options);
                         return;
                     } else {
                         $this->error();
                     }
                 } else {
                     $this->error();
                 }
             }
         }
     } catch (\vendor\Controller\Exception $e) {
         $this->error();
     }
 }
Пример #3
0
<?php

// require '../src/vendor/TopicData.php';
// require '../src/vendor/Template.php';
//autoloader
require_once '../src/vendor/Config.php';
\vendor\Config::setDirectory('../config');
$config = \vendor\Config::get('autoload');
require_once $config['class_path'] . '/vendor/Autoloader.php';
// $data= new \vendor\TopicData();
// $topics = $data->getAllTopics();
// $template = new \vendor\Template("../views/app.phtml");
// $template->render("../views/index/list.phtml", ['topic' => $topics]);
//the auto route old method
/* 
if (!isset($_SERVER['PATH_INFO']) || empty($_SERVER['PATH_INFO']) || $_SERVER['PATH_INFO'] == '/') {
	$route = 'list';
} else {
	$route = $_SERVER['PATH_INFO'];
}
*/
//auto load new method
// $route = null;
if (isset($_SERVER['PATH_INFO'])) {
    $route = $_SERVER['PATH_INFO'];
}
$router = new \vendor\Router();
$router->start($route);
Пример #4
0
 function __construct()
 {
     $this->config = \vendor\Config::get('site');
     $this->template = new \vendor\Template($this->config['view_path'] . "/app.phtml");
 }
Пример #5
0
 protected function __construct()
 {
     $config = \vendor\Config::get('database');
     $this->connection = new \PDO("mysql:host=" . $config['hostname'] . ";dbname=" . $config['dbname'], $config['username'], $config['password']);
 }
Пример #6
0
 /**
  * Simple rendering function
  * @param  [object] $template link to view
  * @param  array  $data     [description]
  * @return [type]           [description]
  */
 protected function renderkan($temp, $data = array())
 {
     $config = \vendor\Config::get('site');
     // die($this->config['view_path']);
     $this->template->render($this->config['view_path'] . "/" . $temp, $data);
 }