public function trigger($data) { $callback = $this->callback; if (is_string($callback)) { $namespace = \Jitsu\Util::getProp($data, 'app_namespace'); if ($namespace !== null) { $callback = Util::normalizeNamespace($namespace) . $callback; } } return call_user_func($callback, $data); }
public function handle($data) { /* Match the mount point to the beginning of the route. */ $saved_route = Util::requireProp($data, 'route'); list($regex, $mapping) = Util::patternToStartRegex($this->mount_point); if (!preg_match($regex, $saved_route, $matches)) { return false; } /* Temporarily modify the route so that it is relative to the * sub-router's mount point. */ $data->route = substr($saved_route, strlen($matches[0])); /* Push the matched URL parameters. */ $parameters = Util::namedMatches($matches, $mapping); $had_params = \Jitsu\Util::hasProp($data, 'parameters'); if ($had_params) { $saved_parameters = $data->parameters; foreach ($parameters as $key => $value) { $data->parameters[$key] = $value; } } else { $data->parameters = $parameters; } /* Run the sub-router. */ try { $r = $this->router->run($data); } catch (\Exception $e) { } /* Restore the full route. */ $data->route = $saved_route; /* Didn't match? Pop the parameters matched in the router's * mount point. */ if (isset($e) || !$r) { if ($had_params) { $data->parameters = $saved_parameters; } else { unset($data->parameters); } } /* Re-throw any exception thrown by the sub-router. */ if (isset($e)) { throw $e; } /* Stop iff the sub-router matched the route. */ return $r; }
public static function ensureArray($data, $name) { if (!\Jitsu\Util::hasProp($data, $name)) { $data->{$name} = array(); } }
Inject configuration settings into a PHP template. TXT; }; $fail = function () use($show_usage) { $show_usage(); exit(1); }; $config = new \Jitsu\App\SiteConfig(); $php_file = null; while (($arg = array_shift($argv)) !== null) { if ($arg === '-h' || $arg === '--help') { $show_usage(); exit(0); } elseif ($arg === '-c' || $arg === '--config') { if (!$argv) { $fail(); } $config->read(array_shift($argv)); } elseif ($php_file === null) { $php_file = $arg; } else { $fail(); } } if ($php_file === null) { $fail(); } \Jitsu\Util::template($php_file, array('config' => $config)); });