Transport\Web\LocationQueryParser::create PHP Méthode

create() public static méthode

public static create ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public static function create(Request $request)
    {
        $from = $request->get('from');
        $to = $request->get('to');
        $via = $request->get('via');
        if (!is_array($via)) {
            if ($via) {
                $via = [$via];
            } else {
                $via = [];
            }
        }
        $query = new LocationQuery(['from' => $from, 'to' => $to, 'via' => $via]);
        return $query;
    }

Usage Example

Exemple #1
0
    if ($x && $y) {
        $query = new NearbyQuery($x, $y);
        $stations = $app['api']->findNearbyLocations($query);
    }
    $query = $request->get('query');
    if ($query) {
        $query = new LocationQuery($query, $request->get('type'));
        $stations = $app['api']->findLocations($query);
    }
    $result = array('stations' => $stations);
    $json = $app['serializer']->serialize((object) $result, 'json');
    return new Response($json, 200, array('Content-Type' => 'application/json'));
});
// connections
$app->get('/v1/connections', function (Request $request) use($app) {
    $query = LocationQueryParser::create($request);
    // get stations
    $stations = $app['api']->findLocations($query);
    // get connections
    $connections = array();
    $from = reset($stations['from']) ?: null;
    $to = reset($stations['to']) ?: null;
    $via = array();
    foreach ($stations as $k => $v) {
        if (preg_match("/^via[0-9]+\$/", $k) && $v) {
            $via[] = reset($v);
        }
    }
    if ($from && $to) {
        $app['stats']->station($from);
        $app['stats']->station($to);
All Usage Examples Of Transport\Web\LocationQueryParser::create
LocationQueryParser