Exemple #1
0
 static function dispatch( $cgi = null, $session_options = -1, $output = '' )
 {
     if( $session_options == -1 )
         $session_options = cgi_request::$DEFAULT_SESSION_OPTIONS;
     $n = new dispatcher( $output );
     return $n->dispatch_cgi( $cgi, $session_options );
 }
Exemple #2
0
 /**
  * Route the passed request
  * 
  * @param request
  */
 public function Run()
 {
     $this->request->Process();
     // pre-dispatcher
     $predisp = new preDispatcher();
     $predisp->Process($this->request);
     // dispatcher
     $disp = new dispatcher();
     $disp->Process($this->request);
     // post-dispatcher
     $postdisp = new postDispatcher();
     $postdisp->Process($this->request);
 }
Exemple #3
0
 public static function getInitial()
 {
     if (self::$Initial === true) {
         return self::$Initial = new dispatcher();
     }
     return self::$Initial;
 }
 function contact()
 {
     global $__in, $__out;
     $page = new page($__in['id']);
     if ($page->send_contact_email($__in['contact']['name'], $__in['contact']['email'], $__in['contact']['subject'], $__in['contact']['message'])) {
         $__out['contact'] = $__in['contact'];
         return dispatcher::redirect(array("action" => "contact_thankyou"));
     } else {
         $__out['contact'] = $__in['contact'];
         return dispatcher::redirect(array("action" => "showonepage", "id" => $__in['id']));
     }
 }
Exemple #5
0
function HandleException($e)
{
    try {
        if ($e instanceof ErrorNotFound) {
            dispatcher::executeControllerAction("error", "notfound", array($e->getMessage(), $e->getTraceAsString()));
        } elseif ($e instanceof ErrorNotAllowed) {
            dispatcher::executeControllerAction("error", "notallowed", array($e->getMessage(), $e->getTraceAsString()));
        } else {
            #die("Unhandled error: ".$e->getMessage()."\n".
            #	$e->getTraceAsString());
            dispatcher::executeControllerAction("error", "unkownexception", array($e->getMessage(), $e->getTraceAsString()));
        }
    } catch (Exception $e) {
        die("DOUBLEFAULT: " . $e->getMessage() . "\n" . $e->getTraceAsString());
    }
}
Exemple #6
0
 function __construct($name, $opts = 0)
 {
     parent::__construct($name, $opts);
     global $server_dir, $web_dir;
     if (($opts & controller::NOTEMPLATE) == 0) {
         $this->template = new Template($name);
         $this->template->assign("dir", array('server' => $server_dir, 'web' => $web_dir, 'controller' => $server_dir . "/web/" . $name . "/template/"));
     }
     if (($opts & self::NOMODULE) == 0) {
         $path = $server_dir . "/web/" . $name . "/module.php";
         if (file_exists($path)) {
             $this->ownmodule = dispatcher::loadModule($name);
         }
         $this->module = new modulehelper();
     }
     #TODO: check if this is alright...
     #TODO: maybe think for a better name...
     $this->postData = new post($name);
 }
 /**
 Redirects to the given request and Adds an information message to the global array of information $__info.
 @param arg_arr_request the array that contains the request parameteres (Controller, action ...).
 @param arg_str_info_msg [Optional] the message that is shown to the user.
 @param arg_arr_info_params [Optional] any extra parameters added to the info message if the message text has placeholders (Like %s or %d).
 @param arg_type [Optional] The type of the message that can be ("info" or "warning") which decides the style of the information shown.
 @return the output of the new request.
 */
 public static function redirect($arg_arr_request, $arg_str_info_msg = "", array $arg_arr_info_params = array(), $arg_type = "info")
 {
     global $__in;
     if (!is_array($arg_arr_request)) {
         $arr_req = split("/", $arg_arr_request);
         $arg_arr_request = array();
         if (count($arr_req) == 1) {
             $arg_arr_request['action'] = $arr_req[0];
         } else {
             if (count($arr_req) == 2) {
                 $arg_arr_request['controller'] = $arr_req[0];
                 $arg_arr_request['action'] = $arr_req[1];
             }
         }
     }
     if ($arg_str_info_msg) {
         add_info($arg_str_info_msg, $arg_arr_info_params, $arg_type);
     }
     if (!$arg_arr_request['controller']) {
         $arg_arr_request['controller'] = $__in['controller'];
     }
     $_SESSION['__GET_REPITITION_STOPPER_OLD'] = $__in;
     $_SESSION['__GET_REPITITION_STOPPER_NEW'] = $arg_arr_request;
     $__in = $arg_arr_request;
     return dispatcher::request();
 }
<?php

/**
 * orchid bootstrap file. used internally to process request and dispatch
 * with the help of router and dispatcher.
 * 
 * @author 		Hasin Hayder [http://hasin.wordpress.com]
 * @copyright 	New BSD License
 * @version 	0.1	
 */
include "core/ini.php";
initializer::initialize();
$router = loader::load("router");
dispatcher::dispatch($router);
                ?>
                <?php 
                break;
        }
    }
    ?>
    </tr>
	</tbody>
<?php 
}
?>
</table>

<div class="toe_coupons">
    <?php 
echo dispatcher::applyFilters('afterCartPrint', '');
?>
</div>

<?php 
if ($this->canEdit) {
    ?>
    <div class="cart_footer">
        <div id="toeCartTotalBox"><?php 
    echo $this->totalBox;
    ?>
</div>
        <div class="clr"></div>       
    </div>
<?php 
}
Exemple #10
0
 function _load_test()
 {
     $this->_foreign_test = dispatcher::loadModel("ab", "b")->objects()->idEQ($this->test)->get();
     return $this->_foreign_test;
 }
 function index()
 {
     return dispatcher::redirect(array("action" => "getall"));
 }
Exemple #12
0
    }
    //定义cache server
    $cacheConf = config::get('cache');
    //读取配置文件,注意配置文件中的格式
    foreach ($cacheConf as $alias => $conf) {
        cache::addServer($alias, $conf);
    }
    //============================ 开始路由和执行controller 层中 ============================
    //检测并获取到uri,当然也可以自己指定
    $uri = dispatcher::detectUri();
    //$uri = '/';
    /*
         * 可以自己随意接受一些参数然后设置 uri 进行转发
          $controller = request::get('c');
          $action = request::get('a');
          $uri = '/'.$action.'/'.$action;
    */
    // 开始路由和执行
    dispatcher::instance()->setPathDeep(dispatcher::path_deep2)->setDefaultModule('index')->setDefaultController('index')->setDefaultAction('index')->setUri($uri)->dispatch()->run();
    //开始执行上一步路由后的 controller 和 action
    //dispatcher::instance()->setControllerName('index')->setActionName('index')->run();
    //============================ 几种常见的异常 ============================
    //} catch (TException_404 $e) {               //当 controller 和 action 不存在时,捕获到的 404 错误。daemon 状态下应该没有
    //    tools_exceptionhandler::topDeal404($e);
} catch (ReflectionException $e) {
    //一般来说,这种情况不太可能发生
    tools_exceptionhandler::topDeal404($e);
} catch (Exception $e) {
    //做个最后的兼容
    tools_exceptionhandler::topDeal($e);
}
 public static function dispatch($status = 200, $body = '', $content_type = 'text/html')
 {
     $status_header = sprintf('HTTP/1.1 %s %s', $status, dispatcher::get_status_code_message($status));
     header($status_header);
     header('Content-type: ' . $content_type);
     if ($body == '') {
         // create some body messages
         $message = '';
         // this is purely optional, but makes the pages a little nicer to read
         // for your users.  Since you won't likely send a lot of different status codes,
         // this also shouldn't be too ponderous to maintain
         switch ($status) {
             case 401:
                 $message = 'You must be authorized to view this page.';
                 break;
             case 404:
                 $message = sprintf('The requested URL %s was not found.', $_SERVER['REQUEST_URI']);
                 break;
             case 500:
                 $message = 'The server encountered an error processing your request.';
                 break;
             case 501:
                 $message = 'The requested method is not implemented.';
                 break;
             default:
         }
         // servers don't always have a signature turned on (this is an apache directive "ServerSignature On")
         $signature = '';
         if ($_SERVER['SERVER_SIGNATURE'] == '') {
             $signature = sprintf('%s Server at %s Port %s', $_SERVER['SERVER_SOFTWARE'], $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
         } else {
             $signature = $_SERVER['SERVER_SIGNATURE'];
         }
         $body = sprintf('<h1>%s</h1><p>%s</p>', dispatcher::get_status_code_message($status), $message);
         echo $body;
         exit;
     } else {
         // send the body
         echo $body;
         exit;
     }
 }
Exemple #14
0
<?php

if (defined('START')) {
    if (START == true) {
        include_once BASEPATH . 'config/config' . EXT;
        include_once BASEPATH . 'config/autoload' . EXT;
        include_once BASEPATH . 'config/routes' . EXT;
        include_once BASEPATH . 'config/database' . EXT;
        include_once BASEPATH . 'core/class.dispatcher' . EXT;
        include_once BASEPATH . 'core/class.globvar' . EXT;
        include_once BASEPATH . 'core/class.controller' . EXT;
        include_once BASEPATH . 'core/class.autoload' . EXT;
        include_once BASEPATH . 'core/core' . EXT;
        dispatcher::getInitial(new autoload(), new core());
    } else {
        include_once $conf['pathmodule']['errors'] . '/503' . EXT;
    }
} else {
    include_once $conf['pathmodule']['errors'] . '/503' . EXT;
}
<?php

/**
 * never change this file!
 *
 * @package kata_internal
 * @author mnt@codeninja.de
 */
/**
 * setup always needed paths
 */
require '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'defines.php';
/**
 * include needed files
 */
require LIB . "boot.php";
/**
 * call dispatcher to handle the rest
 */
$dispatcher = new dispatcher();
echo $dispatcher->dispatch(isset($_GET['kata']) ? $_GET['kata'] : '', isset($routes) ? $routes : null);
Exemple #16
0
 protected static function dispatcher()
 {
     dispatcher::run();
     // 获取分组 模块和操作名称
     define('MODULE_NAME', strtolower($_GET['m']));
     define('CONTROLLER_NAME', strtolower($_GET['c']));
     define('ACTION_NAME', strtolower($_GET['a']));
     define('__SELF__', strip_tags($_SERVER['REQUEST_URI']));
     define('__APP__', rtrim($_SERVER['SCRIPT_NAME'], '/'));
     // 当前模块和分组地址
     define('__MODULE__', __APP__ . '?s=' . MODULE_NAME);
     define('__URL__', __MODULE__ . '/' . CONTROLLER_NAME);
     // 当前操作地址
     define('__ACTION__', __URL__ . '/' . ACTION_NAME);
 }
 public static function process()
 {
     if (array_key_exists('c', $_GET)) {
         $controller_name = $_GET['c'];
     }
     if (array_key_exists('a', $_GET)) {
         $action_name = $_GET['a'];
     }
     if (array_key_exists('v', $_GET)) {
         $value = $_GET['v'];
     }
     if (array_key_exists('sv', $_GET)) {
         $sub_value = $_GET['sv'];
     }
     // set default values
     if (!isset($controller_name)) {
         $controller_name = 'home';
     }
     if (!isset($action_name)) {
         $action_name = 'index';
     }
     if (!isset($value)) {
         $value = '';
     }
     if (!isset($sub_value)) {
         $sub_value = '';
     }
     $verb = strtoupper($_SERVER['REQUEST_METHOD']);
     $query_string_array = array();
     if (array_key_exists('QUERY_STRING', $_SERVER)) {
         parse_str($_SERVER['QUERY_STRING'], $query_string_array);
     }
     $session_service = service_factory::get_session_service();
     $session_service->set();
     $session_service->extend();
     switch ($controller_name) {
         case 'home':
             global $model;
             $controller = controller_factory::get_home_controller();
             $model = $controller->index();
             break;
         case 'account':
             global $model;
             $controller = controller_factory::get_account_controller();
             switch ($action_name) {
                 case 'signup':
                     if ($verb === 'POST') {
                         $model = $controller->do_signup($_POST['first-name'], $_POST['last-name'], $_POST['username'], $_POST['password']);
                     } else {
                         $model = $controller->show_signup();
                     }
                     break;
                 case 'signin':
                     if ($verb === 'POST') {
                         $model = $controller->do_signin($_POST['account-username'], $_POST['account-password']);
                         if ($model->success) {
                             dispatcher::redirect('/');
                         }
                     } else {
                         $url = '';
                         if (array_key_exists('url', $query_string_array)) {
                             $url = $query_string_array['url'];
                         }
                         $model = $controller->show_signin($url);
                     }
                     break;
                 case 'signout':
                     $controller->signout();
                     dispatcher::redirect('/');
                     break;
             }
             break;
         case 'location':
             global $session;
             $controller = controller_factory::get_list_controller();
             switch ($action_name) {
                 case 'index':
                     if ($session) {
                         $data = $controller->get_locations($session->user_id);
                         dispatcher::dispatch(200, json_encode($data), 'application/json');
                     } else {
                         dispatcher::dispatch_error(401);
                     }
                     break;
                 case 'tracking':
                     if ($session) {
                         $data = $controller->get_trackings_by_location($value, $session->user_id);
                         dispatcher::dispatch(200, json_encode($data), 'application/json');
                     } else {
                         dispatcher::dispatch_error(401);
                     }
                     break;
                 case 'checkin':
                     $data = $controller->get_trackings_by_location($value, 0);
                     dispatcher::dispatch(200, count($data), 'application/json');
                     break;
                 case 'report':
                     if ($session) {
                         $data = $controller->get_location_report_by_date($value);
                         dispatcher::dispatch(200, json_encode($data), 'application/json');
                     } else {
                         dispatcher::dispatch_error(401);
                     }
                     break;
                 case 'status':
                     if ($session) {
                         $data = $controller->get_tracking_status($value, $session->user_id);
                         dispatcher::dispatch(200, json_encode($data), 'application/json');
                     } else {
                         dispatcher::dispatch_error(401);
                     }
                     break;
                 case 'join':
                     if ($verb === 'POST') {
                         if ($session) {
                             $data = $controller->join_location($value, $session->user_id);
                             dispatcher::dispatch(200, json_encode($data), 'application/json');
                         } else {
                             dispatcher::dispatch_error(401);
                         }
                     }
                     break;
                 case 'approve':
                     if ($verb === 'POST') {
                         if ($session) {
                             $data = $controller->approve_user_at_location($value, $sub_value);
                             dispatcher::dispatch(200, json_encode($data), 'application/json');
                         } else {
                             dispatcher::dispatch_error(401);
                         }
                     }
                     break;
                 case 'deactivate':
                     if ($verb === 'POST') {
                         if ($session) {
                             $data = $controller->deactivate_user_at_location($value, $sub_value);
                             dispatcher::dispatch(200, json_encode($data), 'application/json');
                         } else {
                             dispatcher::dispatch_error(401);
                         }
                     }
                     break;
                 case 'reactivate':
                     if ($verb === 'POST') {
                         if ($session) {
                             $data = $controller->reactivate_user_at_location($value, $sub_value);
                             dispatcher::dispatch(200, json_encode($data), 'application/json');
                         } else {
                             dispatcher::dispatch_error(401);
                         }
                     }
                     break;
                 case 'show':
                     if ($session) {
                         $data = $controller->get_location($value, $session->user_id);
                         dispatcher::dispatch(200, json_encode($data), 'application/json');
                     } else {
                         dispatcher::dispatch_error(401);
                     }
                     break;
                 case 'member':
                     if ($session) {
                         $data = $controller->get_members($value);
                         dispatcher::dispatch(200, json_encode($data), 'application/json');
                     } else {
                         dispatcher::dispatch_error(401);
                     }
                     break;
                 default:
                     // do nothing
             }
             break;
         case 'list':
             global $model;
             global $session;
             if ($session) {
                 $controller = controller_factory::get_list_controller();
                 $model = $controller->index();
             } else {
                 dispatcher::dispatch_error(401);
             }
             break;
         case 'tracking':
             if ($verb === 'POST') {
                 global $session;
                 if ($session) {
                     $controller = controller_factory::get_list_controller();
                     $post_data = routing::parse_post_data();
                     if ($action_name === 'checkin') {
                         $data = $controller->check_in($post_data->location_id, $session->user_id);
                         dispatcher::dispatch(200, json_encode($data), 'application/json');
                     } else {
                         if ($action_name === 'checkout') {
                             $data = $controller->check_out($post_data->location_id, $session->user_id);
                             dispatcher::dispatch(200, json_encode($data), 'application/json');
                         }
                     }
                 } else {
                     dispatcher::dispatch_error(401);
                 }
             }
             break;
         default:
             // do nothing
     }
     // fallback
     if (dispatcher::load_view($controller_name, $action_name)) {
         exit;
     } else {
         // error
         dispatcher::dispatch_error(404);
     }
 }
<?php

/**
 * command line invoker for kata
 *
 * @author mnt
 * @author Raimar Lutsch
 * @package kata_internal
 */
/**
 * start
 */
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'defines.php';
require LIB . "boot.php";
set_time_limit(600);
if (posix_getuid() == 0) {
    echo "Warning: If this is your first call to the framework, kata\n" . "may create the tmp-folders with rights that may make them\n" . "inaccessible for apache-users (eg. www-data)\n";
}
if ($argc < 2) {
    die("Usage: cron.php controller action [param1] [param2] [...]\n");
}
$args = $argv;
array_shift($args);
$dispatcher = new dispatcher();
echo $dispatcher->dispatch(implode('/', $args), null);
	/**
	 * Puts it all together and runs it
	 * 
	 */
	public function execute ()
	{
		# Create a dispatcher and give it the database and page info
		$dp = new dispatcher($this->db, $this->qbPage);
		# Puts the dispatcher output into the template data
		$this->qbTemplateData = $dp->output();
		$this->qbTemplateData['errors'] = $this->qbErrors;
		# Create the template and give it the data
		$tpl = new template($this->qbTemplateData);
		# Output starts!
		$tpl->display();
	}
Exemple #20
0
<?php

//	Some constants that should be configured
define('DS', '\\');
define('BASE_PATH', 'D:' . DS . 'websites' . DS . 'azl' . DS . 'framework');
define('FRAMEWORK', BASE_PATH);
//	Get the dispatcher
require_once FRAMEWORK . DS . 'dispatcher.php';
//	And fire it up
try {
    $disp = new dispatcher();
} catch (Exception $e) {
    echo $e->getMessage();
    echo $e->getTrace();
}
$disp->run();
 /**
  * Impersonates a user
  * @global array $__in
  * @global array $__out
  * @return boolean
  */
 public function impersonate()
 {
     global $__in, $__out;
     try {
         $user = new user($__in['id']);
         $user->impersonate();
     } catch (ValidationException $ex) {
         $ex->publish_errors();
     } catch (Exception $ex) {
         throw $ex;
     }
     return dispatcher::redirect(array("controller" => "user", "action" => "home"));
 }
Exemple #22
0
require_once "config/translation/" . $__out['lang'] . ".php";
try {
    dispatcher::request();
    // handle request
} catch (PermissionDeniedException $ex) {
    if ($_SESSION['group_id'] == 0) {
        // visitor
        dispatcher::redirect(array("controller" => "user", "action" => "login"), "please_login_first");
    } else {
        dispatcher::redirect(array("controller" => "errors", "action" => "permission_denied"));
    }
} catch (PageNotFoundException $ex) {
    if (DEBUG) {
        exception_handler($ex);
    } else {
        dispatcher::redirect(array("controller" => "errors", "action" => "page_not_found"));
    }
} catch (Exception $ex) {
    exception_handler($ex);
}
$__out['user_id'] = $_SESSION['user_id'];
$__out['__errors'] = $__errors;
/**< Add the $__errors array to the array of output ($__out) to be shown on the template when displayed. */
$__out['__info'] = $__info;
/**< Add the $__info array to the array of output ($__out) to be shown on the template when displayed. */
//-------------------------------------------------------------
// view handling
require_once "lib/clssmarty.php";
$template = new clssmarty();
$template->display_index();
/**< assign the $__out variables to the template and display the main tpl of the current language and current theme and current group. */
Exemple #23
0
 public function forward($path)
 {
     dispatcher::instance()->setUri($path)->dispatch()->run();
 }
Exemple #24
0
<?php

// すべてのリクエストがこのファイルに集中し、ここでリクエスト振り分けクラスのインスタンス化を行います
$sysRoot = dirname(dirname(__FILE__));
require_once $sysRoot . '/config.php';
require_once $sysRoot . '/Controller/dispatcher.php';
$dispatcher = new dispatcher($sysRoot);
$dispatcher->run();
 function testSetResponseVersion()
 {
     $_SERVER[ODataConstants::HTTPREQUEST_HEADER_METHOD] = ODataConstants::HTTP_METHOD_GET;
     $_SERVER[ODataConstants::HTTPREQUEST_HEADER_PROTOCOL] = ODataConstants::HTTPREQUEST_HEADER_PROTOCOL_HTTP;
     $_SERVER[ODataConstants::HTTPREQUEST_HEADER_HOST] = "localhost:8086";
     $_SERVER[ODataConstants::HTTPREQUEST_HEADER_URI] = "/NorthWind.svc/Customers";
     try {
         $exceptionThrown = false;
         $dispatcher = new dispatcher();
         //Service dispatched
         //$dispatcher->dispatch();
         $contents = ob_get_contents();
         ob_end_clean();
         $dispatcher->getHost()->setResponseVersion("2.0");
         $headers =& $dispatcher->getHost()->getWebOperationContext()->OutgoingResponse()->getHeaders();
         $this->assertEquals('2.0', $headers[ODataConstants::ODATAVERSIONHEADER]);
     } catch (\Exception $exception) {
         if (ob_get_length()) {
             ob_end_clean();
         }
         $exceptionThrown = true;
         $this->fail("Some unexpected exception has been thrown:", $exception->getMessage());
     }
     if (!$exceptionThrown) {
         $this->assertTrue(TRUE);
     }
     $dispatcher->getHost()->getWebOperationContext()->resetWebContextInternal();
 }
 function index()
 {
     return dispatcher::redirect(array("action" => "page_not_found"));
 }
 /**
 Sets the permissions for a group.
 */
 function set_permissions()
 {
     global $__in, $__out;
     try {
         $group = new group($__in['id']);
         $__out['group'] = $group->this_to_array();
         $permission = new permission();
         $__out['arr_permissions'] = $permission->assoc_array_from_result_array($permission->getall(), "id", "description");
         $__out['selected_permission_ids'] = $group->get_selected_permission_ids();
         if ($__in['__is_form_submitted']) {
             // if form is submitted
             $group->set_permissions($__in['group']['permissions']);
             return dispatcher::redirect(array("action" => "getall"), "updated_successfully");
         }
     } catch (ValidationException $ex) {
         $ex->publish_errors();
     } catch (Exception $ex) {
         throw $ex;
     }
     return true;
 }
Exemple #28
0
 public function setActionName($action = 'default')
 {
     self::$_currentAction = strtolower($action);
     return self::$_instance;
 }
Exemple #29
0
<?php

session_start();
ini_set('display_errors', 1);
error_Reporting(E_ALL);
$server_dir = realpath(dirname(__FILE__)) . '/';
$web_dir = dirname($_SERVER['PHP_SELF']) . '/';
#include_once($server_dir."config.php");
include_once $server_dir . "core/exception.php";
include_once $server_dir . "core/template.php";
include_once $server_dir . "core/common.php";
include_once $server_dir . "core/controller.php";
#include_once($server_dir."core/spyc.php");
include_once $server_dir . "core/dispatch.php";
include_once $server_dir . "core/sql.php";
include_once $server_dir . "core/config.php";
include_once $server_dir . "core/post.php";
include_once $server_dir . "lib/HTMLPurifier/HTMLPurifier.auto.php";
spl_autoload_register('dispatcher::loadController');
try {
    dispatcher::dispatchRequest();
} catch (Exception $e) {
    handleException($e);
}