Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public static function ensureArray($data, $name)
 {
     if (!\Jitsu\Util::hasProp($data, $name)) {
         $data->{$name} = array();
     }
 }