/** * 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 = ''; } }
/** * 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; }
/** * alias method for the router server object. */ public function resolver() { return \Wukka\ShortCircuit::resolver(); }
<?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();