Exemplo n.º 1
0
<?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);
Exemplo n.º 2
0
 function testSetResponseStatusCodeInvalidCodeRange()
 {
     $_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()->setResponseStatusCode(601);
         $headers =& $dispatcher->getHost()->getWebOperationContext()->OutgoingResponse()->getHeaders();
         $this->assertStringStartsWith('601', $headers[ODataConstants::HTTPRESPONSE_HEADER_STATUS_CODE]);
     } catch (\Exception $exception) {
         if (ob_get_length()) {
             ob_end_clean();
         }
         $exceptionThrown = true;
         $this->assertTrue(TRUE);
     }
     if (!$exceptionThrown) {
         $this->fail('Invalid range of HTTP status code : Some expected exception has not been thrown');
     }
     $dispatcher->getHost()->getWebOperationContext()->resetWebContextInternal();
 }
Exemplo n.º 3
0
<?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);
Exemplo n.º 4
0
 function testSetResponseStatusCodeInvalidCodeRange()
 {
     $_SERVER[ODataConstants::HTTPREQUEST_METHOD] = ODataConstants::HTTP_METHOD_GET;
     $_SERVER[ODataConstants::HTTPREQUEST_PROTOCOL] = ODataConstants::HTTPREQUEST_PROTOCOL_HTTP;
     $_SERVER[HttpProcessUtility::headerToServerKey(ODataConstants::HTTPREQUEST_HEADER_HOST)] = "localhost:8086";
     $_SERVER[ODataConstants::HTTPREQUEST_URI] = "/NorthWind.svc/Customers";
     try {
         $exceptionThrown = false;
         $dispatcher = new dispatcher();
         //Service dispatched
         $dispatcher->dispatch();
         $contents = ob_get_contents();
         ob_end_clean();
         $dispatcher->getHost()->setResponseStatusCode(601);
         $headers =& $dispatcher->getHost()->getWebOperationContext()->OutgoingResponse()->getHeaders();
         $this->assertStringStartsWith('601', $headers[ODataConstants::HTTPRESPONSE_HEADER_STATUS_CODE]);
     } catch (\Exception $exception) {
         if (ob_get_length()) {
             ob_end_clean();
         }
         $exceptionThrown = true;
         $this->assertTrue(TRUE);
     }
 }
Exemplo n.º 5
0
 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);
     }
 }
Exemplo n.º 6
0
<?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);