本文整理汇总了PHP中Route类的典型用法代码示例。如果您正苦于以下问题:PHP Route类的具体用法?PHP Route怎么用?PHP Route使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Route类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* 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];
}
示例2: __construct
public function __construct()
{
$index = new Route('diensten', 'index');
$service = new Route('%s', 'service');
$index->add_route($service);
$this->add_route($index);
}
示例3: testRegex2
public function testRegex2()
{
$expected = ['baby' => 'geza'];
$route = new Route('/:baby', $this->matcher);
$actual = $route->parameters('/geza');
$this->assertEquals($expected['baby'], $actual['baby']);
}
示例4: create
/**
* 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;
}
}
示例5: find_routes
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;
}
示例6: __construct
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);
}
示例7: find_routes
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;
}
示例8: __construct
public function __construct($modulo)
{
# criar uma instância do objeto de rotas
$route = new Route();
# carregar as rotas
$this->setRoute($modulo, $route->initRoute());
}
示例9: load
/**
* 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);
}
示例10: getDirections
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");
}
}
示例11: getContent
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);
}
示例12: __construct
/**
* 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;
}
示例13: dispatch
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();
}
示例14: copy
public function copy()
{
$copy = new Route($this->opts);
foreach ($this->flights as $flight) {
$copy->add_flight($flight);
}
return $copy;
}
示例15: testMorePath
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"]));
}