PHP Route, 0 Examples

PHP Route - 30 examples found. These are the top rated real world PHP examples of Route extracted from open source projects. You can rate examples to help us improve the quality of examples.
User: florianauderset Date: 09.12.15 Time: 13:47
Example #1
0
 /**
  * Register a new route
  * 
  * @param string $routePattern Route pattern
  * @param \Closure $closure closure
  * 
  * @return \Chochan\Routing\Route
  */
 public function register($routePattern, \Closure $closure)
 {
     $route = new Route($this->getBaseDir() . $routePattern);
     $route->setClosure($closure);
     $this->routes[] = $route;
     return $this->routes[count($this->routes) - 1];
 }
 /**
  * Get the uri.
  *
  * @return mixed
  */
 public function uri()
 {
     if (!is_null($this->route)) {
         return $this->route->uri();
     }
     return null;
 }
Example #3
0
 public function __construct()
 {
     $index = new Route('diensten', 'index');
     $service = new Route('%s', 'service');
     $index->add_route($service);
     $this->add_route($index);
 }
Example #4
0
 public function testRegex2()
 {
     $expected = ['baby' => 'geza'];
     $route = new Route('/:baby', $this->matcher);
     $actual = $route->parameters('/geza');
     $this->assertEquals($expected['baby'], $actual['baby']);
 }
Example #5
0
 /**
  * Create the application document registry
  *
  * @param array $aData
  * @return string
  *
  */
 public function create($aData)
 {
     $oConnection = Propel::getConnection(RoutePeer::DATABASE_NAME);
     try {
         $sRouteUID = G::generateUniqueID();
         $aData['ROU_UID'] = $sRouteUID;
         $oRoute = new Route();
         // validating default values
         $aData['ROU_TO_LAST_USER'] = $this->validateValue(isset($aData['ROU_TO_LAST_USER']) ? $aData['ROU_TO_LAST_USER'] : '', array('TRUE', 'FALSE'), 'FALSE');
         $aData['ROU_OPTIONAL'] = $this->validateValue(isset($aData['ROU_OPTIONAL']) ? $aData['ROU_OPTIONAL'] : '', array('TRUE', 'FALSE'), 'FALSE');
         $aData['ROU_SEND_EMAIL'] = $this->validateValue(isset($aData['ROU_SEND_EMAIL']) ? $aData['ROU_SEND_EMAIL'] : '', array('TRUE', 'FALSE'), 'TRUE');
         $oRoute->fromArray($aData, BasePeer::TYPE_FIELDNAME);
         if ($oRoute->validate()) {
             $oConnection->begin();
             $iResult = $oRoute->save();
             $oConnection->commit();
             return $sRouteUID;
         } else {
             $sMessage = '';
             $aValidationFailures = $oRoute->getValidationFailures();
             foreach ($aValidationFailures as $oValidationFailure) {
                 $sMessage .= $oValidationFailure->getMessage() . '<br />';
             }
             throw new Exception('The registry cannot be created!<br />' . $sMessage);
         }
     } catch (Exception $oError) {
         $oConnection->rollback();
         throw $oError;
     }
 }
 private function find_routes($org, $dest, &$flights)
 {
     $result = array();
     $queue = new SplPriorityQueue();
     foreach ($flights as $flight) {
         if ($flight['org_id'] == $org) {
             $route = new Route($this->route_opts);
             $num_seats = Flight::get_open_seats_on_flight($flight['flight_id'], $this->user);
             $route->add_flight($flight, $num_seats);
             $queue->insert($route, $route->get_joy());
         }
     }
     //BFS to find all routes that take < 10 hours
     $count = 0;
     while ($queue->count() > 0 && $count < $this->opts['max_results']) {
         $cur_route = $queue->extract();
         if ($cur_route->get_dest() == $dest) {
             $result[] = $cur_route;
             $count++;
             continue;
         }
         foreach ($flights as $flight) {
             if (!array_key_exists($flight['dest_id'], $cur_route->visited) && $flight['org_id'] == $cur_route->get_dest() && $flight['e_depart_time'] > 30 * 60 + $cur_route->get_arrival_time()) {
                 $new_route = $cur_route->copy();
                 $num_seats = Flight::get_open_seats_on_flight($flight['flight_id'], $this->user);
                 $new_route->add_flight($flight, $num_seats);
                 if ($new_route->get_trip_time() < 24 * 60 * 60 && $new_route->seats >= $this->opts['passengers']) {
                     $queue->insert($new_route, $new_route->get_joy());
                 }
             }
         }
     }
     return $result;
 }
Example #7
0
 public function __construct()
 {
     $index = new Route('(te-koop|te-huur)', 'index');
     $detail = new Route('%s/%d', 'detail');
     $index->add_route($detail);
     $this->add_route($index);
 }
 private function find_routes($org, $dest, &$flights)
 {
     $result = array();
     $queue = new SplPriorityQueue();
     foreach ($flights as $flight) {
         if ($flight['org_id'] == $org) {
             $route = new Route($this->route_opts);
             $route->add_flight($flight);
             array_push($this->id, $flight['flight_id']);
             $queue->insert($route, $route->get_joy());
         }
     }
     //BFS to find all routes that take < 10 hours
     $count = 0;
     while ($queue->count() > 0 && $count < $this->opts['max_results']) {
         $cur_route = $queue->extract();
         if ($cur_route->get_dest() == $dest) {
             $result[] = $cur_route;
             $count++;
             continue;
         }
         foreach ($flights as $flight) {
             if ($flight['org_id'] == $cur_route->get_dest() && $flight['e_depart_time'] > 30 * 60 + $cur_route->get_arrival_time()) {
                 $new_route = $cur_route->copy();
                 $new_route->add_flight($flight);
                 array_push($this->id, $flight['flight_id']);
                 if ($new_route->get_trip_time() < 24 * 60 * 60) {
                     $queue->insert($new_route, $new_route->get_joy());
                 }
             }
         }
     }
     return $result;
 }
Example #9
0
 public function __construct($modulo)
 {
     # criar uma instância do objeto de rotas
     $route = new Route();
     # carregar as rotas
     $this->setRoute($modulo, $route->initRoute());
 }
Example #10
0
/**
 * include and run given route 
 *
 * @param Route   $route   the route to be loaded
 * @param Request $request the request datas
 *
 * @return string the produced HTML to render
 *
 * @access public
 */
function load(Route $route, Request $request)
{
    $location = explode('::', $route->getLocation());
    include_once $location[0] . '/init.php';
    $request->addParams($route->getOptions());
    return call_user_func($location[1], $request);
}
 public static function getDirections(Route $route, $version = 0)
 {
     /**
      * @var DB
      */
     $dbObj = DBPool::getInstance();
     $version = $version == 0 ? TableUpdate::getVersion() : $version;
     $dbObj->bindParams(array($route->getId(), $version));
     $directions = $dbObj->get_results("SELECT * FROM direction WHERE route_id=?\n            AND version = ?");
     if ($dbObj->num_rows > 0) {
         $directionArray = array();
         foreach ($directions as $d) {
             $dirObj = new Direction();
             $dirObj->setId($d->id);
             $dirObj->setName($d->name);
             $dirObj->setPrettyName($d->pretty_name);
             $dirObj->setRoute($route);
             $dirObj->setTag($d->tag);
             $dirObj->setTitle($d->title);
             $dirObj->setPrettyTitle($d->pretty_title);
             $dirObj->setUseForUi($d->use_for_ui);
             $dirObj->setShow($d->show);
             $directionArray[$d->tag] = $dirObj;
         }
         return $directionArray;
     } else {
         //TODO: Don't use a generic exception
         throw new Exception("No data available - Direction::getDirections");
     }
 }
Example #12
0
 protected function getContent(Router $router, Context $context, Route $route)
 {
     $callback = $route->getAction();
     $values = $router->extract($context, $route);
     $bindings = $router->bind($values, $route->getBindings());
     $arguments = $router->buildArguments($callback, $bindings);
     return $callback(...$arguments);
 }
Example #13
0
 /**
  * constructor
  *
  * @param \Naquadria\Components\Routing\Route $route
  * @param array $routeData
  * @param array $replacer
  */
 public function __construct(Route $route, array $routeData, array $replacer)
 {
     $this->name = $route->getName();
     $this->abstraction = $route->getAbstraction();
     $this->data = $routeData;
     $this->replacer = $replacer;
     $this->route = $route;
 }
 public function dispatch(Route $route, Request $request, Response $response)
 {
     $controller = __NAMESPACE__ . '\\Controllers\\' . $route->getController();
     $action = $route->getAction();
     $foo = new $controller($request, $response);
     $foo->{$action}();
     $response->send();
 }
 public function copy()
 {
     $copy = new Route($this->opts);
     foreach ($this->flights as $flight) {
         $copy->add_flight($flight);
     }
     return $copy;
 }
Example #16
0
 public function testMorePath()
 {
     $route = new Route("/users/login");
     $url = parse_url("http://example.com/users/login?foo=bar");
     $this->assertInternalType("array", $route->match($url["path"], "GET", $url["host"], $url["scheme"]));
     $url = parse_url("http://example.com/users/login.php");
     $this->assertFalse($route->match($url["path"], "GET", $url["host"], $url["scheme"]));
 }
 /**
  * @dataProvider dataProviderForMatch
  */
 public function testMatch($method, $pattern, $givenMethod, $givenUri, $expectedReturn, $expectedArguments = array())
 {
     $route = new Route($method, $pattern, function () {
     });
     $this->assertEquals($expectedReturn, $route->match($givenMethod, $givenUri));
     $this->assertCount(count($expectedArguments), $route->getArguments());
     $this->assertEquals($expectedArguments, $route->getArguments());
 }
Example #18
0
 public static function build($name = null, $pattern, array $parameters = null)
 {
     $route = new Route();
     $route->setName($name);
     $route->setPattern($pattern);
     $route->setParameters($parameters);
     return $route;
 }
 public function testInvoke_Failing()
 {
     $route = new Route();
     $route->setAction('sample');
     $controller = $this->createController();
     $this->setExpectedException('NotFoundHttpException');
     $this->object->invoke($controller, $route);
 }
Example #20
0
 public function hydrate(array $data = [])
 {
     foreach ($data as $value) {
         $intervention = new Route();
         $intervention->hydrate($value);
         $this[] = $intervention;
     }
 }
Example #21
0
 public function testClearGetParams()
 {
     $this->markTestSkipped("Check if is router test");
     $uri = '/?hello=world';
     $this->object->explode($uri);
     $this->assertEquals("Index", $this->object->getControllerName());
     $this->assertEquals("index", $this->object->getActionName());
 }
Example #22
0
 /**
  * Adds a new route context to the routing table.
  *
  * @param Route $route
  *
  * @throws RouteIdentifierException
  */
 public function add(Route $route)
 {
     $identifier = $route->identifier();
     if (isset($this->routes[$identifier])) {
         throw new RouteIdentifierException("Cannot redeclare route identified by: {$identifier}");
     }
     $this->routes[$identifier] = $route;
 }
Example #23
0
 /**
  * @param $path string
  * @param $action callable|string
  */
 public static function post($path, $action)
 {
     $route = new Route();
     $route->setMethod("GET");
     $route->setPath($path);
     $route->setAction($action);
     self::addRoute($route);
 }
Example #24
0
 public function registerRoute($method, $pattern)
 {
     $this->namesResolved = false;
     $route = new Route();
     $route->method($method)->pattern($this->fixPrefix($pattern));
     $this->routes[] = $route;
     return $route;
 }
Example #25
0
 public function add($httpMethod, $uri, $handler, $middlewares = [])
 {
     $route = new Route($httpMethod, $uri, $handler, $this->strategy);
     $route->setMiddlewares($middlewares);
     $route->setGroup($this);
     $this->routes[] = $route;
     return $route;
 }
Example #26
0
 function __construct(Sessions $sessions, Route $route)
 {
     $branchLevelId = $route->branchLevelId();
     if ($branchLevelId) {
         $this->session = $sessions[$branchLevelId];
     } else {
         $this->session = $sessions[0];
     }
 }
Example #27
0
 /**
  * RouteLink constructor.
  *
  * @param $params
  * @param \HBM\DatagridBundle\Model\Route $route
  */
 public function __construct($params, Route $route)
 {
     parent::__construct();
     $this->params = $params;
     if ($route !== NULL) {
         $this->name = $route->getName();
         $this->defaults = $route->getDefaults();
     }
 }
Example #28
0
 /**
  * get an instance of Route class
  * load all routes
  * @return instance $route Routes()
  */
 protected function get_routes()
 {
     static $routes = null;
     if (null === $routes) {
         $routes = new Route();
         $routes->load_routes();
     }
     return $routes;
 }
Example #29
0
 /**
  * @param Route $route
  * @return bool
  */
 public function includes(Route $route)
 {
     foreach ($this->routes as $match_route) {
         if ($route->getUrl() == $match_route->getUrl()) {
             return true;
         }
     }
     return false;
 }
Example #30
0
 public function handle(Route $route)
 {
     $factory = $this->factory($route->controller());
     $controller = $factory->invoke();
     $controller->context = $this->httpContext;
     $view = $this->view($controller, $this->action($route->action()), $route->parameters());
     $view->context = $this->httpContext;
     $this->header($view);
     $this->render($view);
 }