예제 #1
0
 /**
  * Class constructor.
  * pass in alternate to $_REQUEST
  */
 public function __construct($data = NULL)
 {
     if ($data === NULL) {
         $data = $_REQUEST;
     }
     parent::__construct($data);
     $trim_chars = "/\n\r\t\v ";
     $server = \Wukka\ShortCircuit::server();
     $this->uri = '/' . trim($server->REQUEST_URI, $trim_chars);
     if (isset($this->{'_'})) {
         $action = $this->{'_'};
     } elseif (isset($server->PATH_INFO)) {
         $action = $server->PATH_INFO;
     } else {
         $pos = strpos($this->uri, '?');
         $action = $pos === FALSE ? $this->uri : substr($this->uri, 0, $pos);
     }
     $script_name = $server->SCRIPT_NAME;
     $action = str_replace(array($script_name, $script_name . '?_='), '', $action);
     $action = trim($action, $trim_chars);
     $this->action = '/' . $action;
     if (strpos($this->uri, $script_name) === 0) {
         $this->base = $script_name;
     } else {
         $this->base = '';
     }
 }
예제 #2
0
 /**
  * call an action file.
  * this shouldn't produce any output.
  * by convention, it should return some sort of data, usually an array
  * that can be consumed by the view
  * this is mapped into the view container.
  * if strict, trigger errors if the path isn't found.
  */
 public function execute($name, $strict = TRUE)
 {
     $path = \Wukka\ShortCircuit::resolver()->get($name, 'action');
     if (!$path) {
         if ($strict) {
             trigger_error('invalid action: ' . $name, E_USER_WARNING);
         }
         return;
     }
     return include $path;
 }
예제 #3
0
 /**
  * alias method for the router server object.
  */
 public function resolver()
 {
     return \Wukka\ShortCircuit::resolver();
 }
예제 #4
0
<?php

include __DIR__ . '/../../autoload.php';
use Wukka\ShortCircuit;
use Wukka\ShortCircuit\Resolver;
use Wukka\ShortCircuit\PatternResolver;
$patterns = array('/go/(id)/' => 'nested/test', '/foo/bar/(a)/test/(b)' => 'nested/deep/test', '/idtest/(id)/' => 'id', '/lt/(a)/(b)/(c)' => 'linktest');
ShortCircuit::resolver(new Resolver(__DIR__ . '/../app/', $patterns));
ShortCircuit::run();