示例#1
0
 public function execute()
 {
     $suffix = "Controller";
     Router::parseUri();
     try {
         $_cc = ucfirst(Router::getController()) . $suffix;
         Loader::autoload($_cc);
         if (!class_exists($_cc, false) && !interface_exists($_cc, false)) {
             throw new Exception('Class ' . $_cc . ' does not exist');
         }
         $class = new ReflectionClass($_cc);
         if ($class->isAbstract()) {
             throw new Exception('Cannot create instances of abstract ' . $_cc . '');
         }
         // Create a new instance of the controller
         $controller = $class->newInstance();
         // Execute the "before action" method
         //$class->getMethod('before')->invoke($controller);
         // Execute the main action with the parameters
         $class->getMethod(Router::getAction() . 'Action')->invokeArgs($controller, Router::getParams());
         // Execute the "after action" method
         //$class->getMethod('after')->invoke($controller);
     } catch (Exception $e) {
         throw $e;
     }
     return $this;
 }
示例#2
0
 /**
  * This method launches the application.
  */
 public function run()
 {
     $router = new Router($this);
     $controller = $router->getController();
     $controller->execute();
     $this->response->setPage($controller->getPage());
     $this->response->send();
 }
示例#3
0
文件: Tracer.php 项目: Rgss/imp
 /**
  * 初始化
  * 
  */
 public function init()
 {
     $this->set('currentUrl', Request::currentUrl());
     $this->set('refererUrl', Request::refererUrl());
     $this->set('controller', Router::getController());
     $this->set('action', Router::getAction());
     $this->set('get', Request::getGet());
     $this->set('post', Request::getPost());
 }
示例#4
0
 public static function dispatch(Router $router)
 {
     // ob_start();
     $className = ucfirst($router->getController()) . 'Controller';
     $actionName = $router->getAction() . 'Action';
     $controllerFile = CONTROLLER_DIR . '/' . $className . '.class.php';
     if (file_exists($controllerFile)) {
         include_once $controllerFile;
         $app = new $className($router->getParams(), $router->getController());
         $app->{$actionName}();
         // $output = ob_get_clean();
         // echo $output;
     } else {
         // throw new Exception('Controller not found. className:['.$className.']');
         Log::fatal('Controller not found. className:[%s]', var_export($className, 1));
         trigger_error('Controller not found. className:[' . var_export($className, 1) . ']', E_USER_ERROR);
     }
 }
 private function file_path($tpl = null)
 {
     $tplDir = Router::getController();
     $tplName = isset($tpl) ? $tpl : Router::getAction();
     $templateFile = VIEW_DIR . $tplDir . DS . $tplName . '.phtml';
     if (!file_exists($templateFile)) {
         throw new Exception("{$templateFile} not found", 404);
     }
     return $templateFile;
 }
 public function __construct()
 {
     $this->controller = Router::getController();
     // get current controller
     $this->action = Router::getAction();
     // get current action/method
     // check if there is an ID on current route (URL)
     if (Router::hasID()) {
         $this->id = Router::getID();
         // get ID
     }
 }
 protected final function _call($path, $args = array())
 {
     $parts = explode('/', $path);
     if ($parts[0] == '') {
         array_shift($parts);
     }
     $router = new Router();
     $controller = $router->getController(new Context('controller', $parts[0], $parts[1], $args));
     if ($controller) {
         return $controller->_execute(false);
     }
     return false;
 }
 public function run()
 {
     if (Tipkin\Config::get('maintenance-mode') == 'on') {
         $this->httpResponse->redirect('/maintenance.html');
         exit;
     }
     $router = new Router($this);
     $controller = $router->getController();
     if (!is_null($controller)) {
         $controller->execute();
         $this->httpResponse->setPage($controller->page());
     }
 }
 public function run()
 {
     if ($this->user->isAdminAuthenticated()) {
         $router = new Router($this);
         $controller = $router->getController();
     } else {
         require dirname(__FILE__) . '/modules/connexion/ConnexionController.class.php';
         $controller = new ConnexionController($this, 'connexion', 'index');
     }
     if (!is_null($controller)) {
         $controller->execute();
         $this->httpResponse->setPage($controller->page());
     }
 }
示例#10
0
 /**
  * Invoke controller based on URL structure
  */
 function invokeController()
 {
     $url = "";
     if (isset($_GET['url'])) {
         $url = $_GET['url'];
     }
     /** @var ControllerInterface $controller */
     $controller = Router::getController($url);
     if ((int) method_exists($controller, $controller->getAction() . 'Action')) {
         call_user_func_array(array($controller, $controller->getAction() . 'Action'), array());
     } else {
         /* Error Generation Code Here */
     }
 }
示例#11
0
 public function displaySingle($file = null, $data = null, $print = true)
 {
     if ($file == null) {
         throw new Exception('模板文件错误');
     }
     $file = Router::getController() . "/" . $file;
     if (is_array($data)) {
         foreach ($data as $k => $v) {
             $this->smarty->assign($k, $v);
         }
     }
     if ($print) {
         ob_start();
         $this->smarty->display($file . ".html");
         ob_end_flush();
         return;
     } else {
         return $this->smarty->fetch($file . ".html");
     }
 }
示例#12
0
 public function __construct()
 {
     // parent::__construct();
     config::getInstance();
     config::getConfig();
     $router = new Router();
     $router->explodeUri();
     /*
     apenas para checagem dos caminhos
     //echo '<p>ROUT FILE: '.$routFile.'</p>';
     echo '<pre >';
     echo '<p>ROTA COMPLETA: '.$this->getRoute().'</p>';
     echo '<p>NOME Controller: '.$this->getController().'</p>';
     echo '<p>NOME METODO: '.$this->getAction().'</p>';
     echo '</pre>';
     */
     define('ROUTE', $router->getRoute());
     define('CONTROLLER', $router->getController());
     define('ACTION', $router->getAction());
     $filename = BASEPATH . DIRECTORY_SEPARATOR . APPPATH . DIRECTORY_SEPARATOR . CONTROLLERS . DIRECTORY_SEPARATOR . ROUTE . CONTROLLER . '.controller.php';
     if (file_exists($filename)) {
         require_once $filename;
         $_controllerName = CONTROLLER;
         $_controller = new $_controllerName();
         $action = ACTION;
         if (method_exists($_controller, $action)) {
             $_controller->{$action}();
         } else {
             require_once BASEPATH . DIRECTORY_SEPARATOR . APPPATH . DIRECTORY_SEPARATOR . CONTROLLERS . DIRECTORY_SEPARATOR . 'error404.controller.php';
             $errorController = new error404();
             $errorController->index();
         }
     } else {
         require_once BASEPATH . DIRECTORY_SEPARATOR . APPPATH . DIRECTORY_SEPARATOR . CONTROLLERS . DIRECTORY_SEPARATOR . 'error404.controller.php';
         $errorController = new error404();
         $errorController->index();
     }
 }
示例#13
0
 public function __construct()
 {
     $this->controller = Router::getController();
 }
示例#14
0
<?php

//test
session_start();
$_SESSION['auth'] = 'user';
require_once 'router.php';
require_once 'baseController.php';
function __autoload($class)
{
    $class = './controllers/' . $class . '.php';
    require_once $class;
}
$router = new Router();
$controller = $router->getController();
$action = $router->getAction();
$obj = new $controller();
$obj->{$action}();
示例#15
0
<?php

defined(SYS_PATH) or define("SYS_PATH", dirname(__FILE__) . "/");
require_once SYS_PATH . "classes/loader.php";
ini_set("display_errors", 1);
Loader::addAutoLoad();
Loader::addMap();
Registry::init();
Router::addMap();
Router::init();
var_dump(Router::getParams());
if (Router::getParams() == NULL) {
    Subdomain::init();
}
$controller = Router::getController();
$action = Router::getAction();
if ($controller == 'site' or $controller == 'admin' or $controller == 'stylecheet') {
    $controller::init($action);
} else {
    header("Location: http://myclankonto.net/");
}
示例#16
0
文件: index.php 项目: OSPFIA32/osp
// Merge $_GET and $_POST
$request = $_GET;
$request['type'] = $_SERVER['REQUEST_METHOD'];
if ($_SERVER['REQUEST_METHOD'] == 'PUT' || $_SERVER['REQUEST_METHOD'] == 'DELETE') {
    parse_str(file_get_contents("php://input"), $post_vars);
} else {
    $post_vars = $_POST;
}
$request['data'] = $post_vars;
$request['path'] = explode("/", substr(@$_SERVER['PATH_INFO'], 1));
//Create User Test
/*
$request['type'] = 'POST';
$post = array(
  'name' => 'TestName',
  'description' => 'TestDescription',
  'startDate' => '01.01.1970 01:00:00',
  'endDate' => '01.01.1970 02:00:00'
);
$request['data']['data'] = $post;
$request['path'] = array(
  0 => 'api',
  1 => 'events'
);
echo("<pre>");
print_r($request);
echo("</pre>");
*/
// Create Controller and print content
echo Router::getController($request)->display();
示例#17
0
 public function default_assign()
 {
     $global_assign = array('user_info' => isset($_SESSION['user_info']) ? $_SESSION['user_info'] : "", 'static_url' => Config::get('static_url'), 'base_url' => Config::get('app_url'), 'cur_url' => Router::getController() . "/" . Router::getAction() . "/", 'menus' => $this->_getMenus());
     $this->view->assign($global_assign);
 }
示例#18
0
    exit;
}
if (!AppConfig::DEBUG_MODE) {
    error_reporting(0);
}
require_once 'core/includes.php';
require_once PHAXSIC_SHELL;
require_once PHAXSIC_SHELLMAPPER;
#Global environment settings
date_default_timezone_set(AppConfig::DEFAULT_TIMEZONE);
if (function_exists('mb_internal_encoding')) {
    mb_internal_encoding(AppConfig::CHARSET);
    if (AppConfig::DEFAULT_LANGUAGE == 'en' || AppConfig::DEFAULT_LANGUAGE == 'ja') {
        mb_language(AppConfig::DEFAULT_LANGUAGE);
    } else {
        mb_language('uni');
    }
}
$url_mapper = new ShellMapper();
$context = $url_mapper->map($_SERVER['argv']);
if (!$context) {
    trigger_error("Controller or Action not found", E_USER_ERROR);
    exit;
}
$router = new Router();
$controller = $router->getController($context);
if (!$controller) {
    trigger_error("Controller or Action not found", E_USER_ERROR);
    exit;
}
$controller->_execute();
示例#19
0
<?php

//эту функцию потом перенести в ядро
function __autoload($class_name)
{
    $config = (include 'config.php');
    $file = "include/" . $class_name . ".php";
    if (file_exists($file)) {
        include $file;
    } else {
        die("Класс {$class_name} не найден");
    }
}
Router::parse($_GET['url']);
$controller_name = Router::getController();
$controller_path = "controllers/" . Router::getController() . ".php";
$controller_method = Router::getMethod();
$params = Router::getParams();
if (file_exists($controller_path)) {
    require_once $controller_path;
    if (class_exists($controller_name)) {
        $controller = new $controller_name();
        if (method_exists($controller, $controller_method)) {
            $controller->{$controller_method}();
        } else {
            //у нас однозначно должен быть определен метод index
            $controller->index();
        }
    } else {
        die("Файл найден, но класс неопределен");
    }
示例#20
0
 /**
  * Sets the controller and view properties and executes the controller, sending the output buffer.
  *
  * @param string $controller Dispatches a specific controller, or use URL to determine the controller
  */
 public static function dispatch($controller = null)
 {
     try {
         $domain = Domains::getInstance();
         $destination = $domain->getRedirect();
         if (!empty($destination)) {
             header('HTTP/1.0 301 Moved Permanently');
             header("Location: " . $destination, true, 301);
             exit;
         }
         $auth_data = $domain->getAuthData();
         if (!empty($auth_data) && FilterCookie::getInstance()->getString('domain_auth') != $auth_data['hash']) {
             $filter_server = FilterServer::getInstance();
             if ($filter_server->isEmpty('PHP_AUTH_USER') || $filter_server->isEmpty('PHP_AUTH_PW') || $filter_server->getString('PHP_AUTH_USER') != $auth_data['user'] || $filter_server->getString('PHP_AUTH_PW') != $auth_data['password']) {
                 header('WWW-Authenticate: Basic realm="Protected page"');
                 throw new Exception_401('You should enter a valid credentials.');
             }
             // If the user is authorized, we save a session cookie to prevent multiple auth under subdomains in the same session.
             setcookie('domain_auth', $auth_data['hash'], 0, '/', $domain->getDomain());
         }
         self::$language = $domain->getLanguage();
         $php_inis = $domain->getPHPInis();
         if ($php_inis) {
             self::_overWritePHPini($php_inis);
         }
         $url = Urls::getInstance(self::$instance);
         $path_parts = $url->getPathParts();
         if (!$domain->valid_domain) {
             throw new Exception_404('Unknown language in domain');
         } else {
             if (null === $controller) {
                 $router = new Router($path_parts[0], self::$instance, $domain->getSubdomain(), self::$language, $domain->www_mode);
                 $controller = $router->getController();
             }
         }
         // This is the controller to use:
         $ctrl = self::invokeController($controller);
         // Save in params for future references:
         $ctrl->addParams(array('controller_route' => $controller));
         // Active/deactive auto-rebuild option:
         if ($domain->getDevMode()) {
             $ctrl->getClass('Cookie');
             if (FilterGet::getInstance()->getInteger('rebuild_all')) {
                 Cookie::set('rebuild_all', 1);
             }
             if (FilterGet::getInstance()->getInteger('rebuild_nothing') && FilterCookie::getInstance()->getInteger('rebuild_all')) {
                 Cookie::delete('rebuild_all');
             }
             if (1 === FilterGet::getInstance()->getInteger('debug')) {
                 Cookie::set('debug', 1);
             }
             if (0 === FilterGet::getInstance()->getInteger('debug')) {
                 Cookie::set('debug', 0);
             }
             if (false !== ($debug = FilterCookie::getInstance()->getInteger('debug'))) {
                 Domains::getInstance()->setDebugMode((bool) $debug);
             }
         }
         $ctrl->dispatch();
         if (false === $ctrl->is_json && Domains::getInstance()->getDebugMode()) {
             self::invokeController('debug/index')->dispatch();
         }
     } catch (\Exception $e) {
         self::_dispatchErrorController($e);
     }
 }
$app = new Application();
// Exception Handler
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
use Symfony\Component\HttpKernel\Debug\ExceptionHandler;
error_reporting(-1);
ErrorHandler::register();
ExceptionHandler::register();
// Environment
define('APPROOT', __DIR__);
$app['version'] = '0.0.0';
$app['env'] = getenv('APP_ENV') ?: 'development';
$app['debug'] = $app['env'] === 'development' ? true : false;
// Configuration
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . '/app/Config/' . $app['env'] . '.php'));
// Connect to MongoDB and apply MinifySchema
$app->register(new MongoMinify\Silex\ServiceProvider());
// Register Twig
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/app/View', 'twig.options' => array('cache' => __DIR__ . '/cache')));
// Logging
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.name' => 'SilexMongoSkeleton', 'monolog.level' => Monolog\Logger::WARNING, 'monolog.logfile' => __DIR__ . '/logs/' . date('Y-m-d') . '-' . $app['env'] . '.log'));
// Custom Error Handler
$app->error(function ($exception, $code) use($app) {
    if ($code === 404) {
        return 'Error 404: Not Found';
    }
});
// App Routes
$app->get('/', Router::getController('Index'));
$app->get('/example-json', Router::getController('JsonExample'));
// Return Instance
return $app;