Skip to content
This repository

add ResultLimit feature, implements ideas from #29 #57

Merged
merged 8 commits into from about 2 years ago

3 participants

benib Roland Schilter Fabian Vogler
benib
benib commented

this implements some things discussed in issue #29.
default is to return all fields. if fields parameter is set, only the defined fields are returned as long as there is a check in the code, where the field is added to the result. this can be done like:

if (ResultLimit::includeField('from')) {
    // add from stuff to result
}

these checks are implemented in Transport\Entity\Schedule\Connection for the fields "from", "to" and "journey" to show how this works.

Tree like fields are also possible, eg:

http://sbb.local/v1/connections?from=008501120&to=008501008&fields[]=to&fields[]=from/geo

in that case, ResultLimit::includeField('from') returnes true, as there is a more specific field set.

any comments are appreciated.

Roland Schilter
Collaborator

Quick feedback:

  • Why not make everything static in ResultLimit, get rid of the Singleton, and add a private ctor? Although I would prefer seeing it as an instance passed around or even better pass the $request somehow. Haven't yet thought it through, though.
  • You should put open parentheses of classes and methods on their own line (see rest of codebase)
  • Tests? ;)
benib
benib commented
  • i agree about making everything static.
  • also agree about coding styles
  • personally i like the approach with the static function includeField(), that way, we can just add this call where some data is added to the request and don't have to worry about passing instances around. the information which fields to include is static and only set once with the request sent to the API.
lib/Transport/ResultLimit.php
((1 lines not shown))
  1 +<?php
  2 +
  3 +namespace Transport;
  4 +
  5 +/**
  6 + * ResultLimit
  7 + */
  8 +class ResultLimit
  9 +{
  10 + private static $fields = null;
  11 +
  12 + private function __construct()
  13 + {
  14 + }
  15 +
  16 + public static function setFields($fields)
1
Roland Schilter Collaborator
rndstr added a note

I suggest doing type hinting here array $fields instead of the is_array() check below

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Transport/ResultLimit.php
((11 lines not shown))
  11 +
  12 + private function __construct()
  13 + {
  14 + }
  15 +
  16 + public static function setFields($fields)
  17 + {
  18 + if (is_array($fields)) {
  19 + self::$fields = array();
  20 + foreach ($fields as $field) {
  21 + self::$fields = array_merge(self::$fields,self::getFieldTree($field));
  22 + }
  23 + }
  24 + }
  25 +
  26 + public static function includeField($field, $searchBase = null)
1
Roland Schilter Collaborator
rndstr added a note

phpdoc would be nice :)

Edit: And I think isFieldIncluded() would be a better name since includeField() sounds like an operation while it is a query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Transport/ResultLimit.php
((6 lines not shown))
  6 + * ResultLimit
  7 + */
  8 +class ResultLimit
  9 +{
  10 + private static $fields = null;
  11 +
  12 + private function __construct()
  13 + {
  14 + }
  15 +
  16 + public static function setFields($fields)
  17 + {
  18 + if (is_array($fields)) {
  19 + self::$fields = array();
  20 + foreach ($fields as $field) {
  21 + self::$fields = array_merge(self::$fields,self::getFieldTree($field));
1
Roland Schilter Collaborator
rndstr added a note

not to be too pedantic but could you add a whitespace after the comma? (same for the occurences below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Transport/ResultLimit.php
((40 lines not shown))
  40 + } else {
  41 + foreach ($searchBase as $newSearchBase) {
  42 + if (is_array($newSearchBase)) {
  43 + $result = self::includeField($field,$newSearchBase);
  44 + }
  45 + //if the field is found, return this information to stop crawling at this point
  46 + if ($result) {
  47 + return $result;
  48 + }
  49 + }
  50 + //the field doesn't seem to be set
  51 + return false;
  52 + }
  53 + }
  54 +
  55 + private static function getFieldTree($field)
1
Roland Schilter Collaborator
rndstr added a note

This method can be rewritten as:

private static function getFieldTree($field) 
{
    return array_reduce(
        array_reverse(explode('/', $field)),
        function ($result, $value) { return array($value => $result); },
        true
    );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
benib
benib commented

@rndstr: i sticked to isFieldSet as isFieldIncluded seems to be confusing to me, as the field is not yet included, we want to know if it should be or not.

Roland Schilter
Collaborator

Thanks for the changes! I'm okay with ResultLimit being static for now I guess.

But looking at the code, I see you are only checking for the from, to and journey parts in the Connection resource. What is your idea about the other resources and their fields?

benib
benib commented
  • checks are now implemented for /connections and /stationboard
  • if no fields are set, everything is returned
  • if any field is set, only the specified fields are returned
  • fields are specified in a path like model
  • if eg. connections/from is set, only the from element and everything below is returned
  • if eg. connections/from/station is set, only the from element containing only the station is returned
  • this can be combined to something like fields[]=connections/from/station&fields[]=connections/to/arrival
Fabian Vogler fabian merged commit 43e97eb into from
Fabian Vogler fabian closed this
Fabian Vogler
Collaborator
fabian commented

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
15 lib/Transport/API.php
@@ -58,7 +58,7 @@ public function sendQuery(Query $query)
58 58 /**
59 59 * @return array
60 60 */
61   - public function findConnections(ConnectionQuery $query)
  61 + public function findConnections(ConnectionQuery $query, $field)
62 62 {
63 63 // send request
64 64 $response = $this->sendQuery($query);
@@ -67,10 +67,11 @@ public function findConnections(ConnectionQuery $query)
67 67 $result = simplexml_load_string($response->getContent());
68 68
69 69 $connections = array();
70   - if ($result->ConRes->ConnectionList->Connection) {
71   - foreach ($result->ConRes->ConnectionList->Connection as $connection) {
72   -
73   - $connections[] = Entity\Schedule\Connection::createFromXml($connection);
  70 + if (ResultLimit::isFieldSet($field)) {
  71 + if ($result->ConRes->ConnectionList->Connection) {
  72 + foreach ($result->ConRes->ConnectionList->Connection as $connection) {
  73 + $connections[] = Entity\Schedule\Connection::createFromXml($connection, null, $field);
  74 + }
74 75 }
75 76 }
76 77
@@ -151,7 +152,7 @@ public function findNearbyLocations(NearbyQuery $query)
151 152 * @param string $dateTime
152 153 * @param array $transportationTypes
153 154 */
154   - public function getStationBoard(StationBoardQuery $query)
  155 + public function getStationBoard(StationBoardQuery $query, $field = '')
155 156 {
156 157 // send request
157 158 $response = $this->sendQuery($query);
@@ -175,7 +176,7 @@ public function getStationBoard(StationBoardQuery $query)
175 176 if ($prevTime > $curTime) { // we passed midnight
176 177 $date->add(new \DateInterval('P1D'));
177 178 }
178   - $journeys[] = Entity\Schedule\StationBoardJourney::createFromXml($journey, $date);
  179 + $journeys[] = Entity\Schedule\StationBoardJourney::createFromXml($journey, $date, null, $field);
179 180 $prevTime = $curTime;
180 181 }
181 182 }
62 lib/Transport/Entity/Schedule/Connection.php
@@ -3,6 +3,7 @@
3 3 namespace Transport\Entity\Schedule;
4 4
5 5 use Transport\Entity;
  6 +use Transport\ResultLimit;
6 7
7 8 /**
8 9 * Connection
@@ -24,7 +25,7 @@ class Connection
24 25 */
25 26 public $sections;
26 27
27   - static public function createFromXml(\SimpleXMLElement $xml, Connection $obj = null)
  28 + static public function createFromXml(\SimpleXMLElement $xml, Connection $obj = null, $parentField = '')
28 29 {
29 30 if (!$obj) {
30 31 $obj = new Connection();
@@ -32,28 +33,47 @@ static public function createFromXml(\SimpleXMLElement $xml, Connection $obj = n
32 33 $date = \DateTime::createFromFormat('Ymd', (string) $xml->Overview->Date, new \DateTimeZone('Europe/Zurich'));
33 34 $date->setTimezone(new \DateTimeZone('Europe/Zurich'));
34 35 $date->setTime(0, 0, 0);
  36 +
  37 + $field = $parentField.'/from';
  38 + if (ResultLimit::isFieldSet($field)) {
  39 + $obj->from = Entity\Schedule\Stop::createFromXml($xml->Overview->Departure->BasicStop, $date, null, $field);
  40 + }
  41 + $field = $parentField.'/to';
  42 + if (ResultLimit::isFieldSet($field)) {
  43 + $obj->to = Entity\Schedule\Stop::createFromXml($xml->Overview->Arrival->BasicStop, $date, null, $field);
  44 + }
35 45
36   - $obj->from = Entity\Schedule\Stop::createFromXml($xml->Overview->Departure->BasicStop, $date);
37   - $obj->to = Entity\Schedule\Stop::createFromXml($xml->Overview->Arrival->BasicStop, $date);
38   -
39   - foreach ($xml->ConSectionList->ConSection as $section) {
40   -
41   - $parts = array();
42   -
43   - if ($section->Journey) {
44   - $parts['journey'] = Entity\Schedule\Journey::createFromXml($section->Journey, $date);
45   - }
  46 + $field = $parentField.'/sections';
  47 + if (ResultLimit::isFieldSet($field)) {
  48 + $parentField = $field;
  49 + foreach ($xml->ConSectionList->ConSection as $section) {
  50 +
  51 + $parts = array();
  52 +
  53 + $field = $parentField.'/journey';
  54 + if (ResultLimit::isFieldSet($field)) {
  55 + if ($section->Journey) {
  56 + $parts['journey'] = Entity\Schedule\Journey::createFromXml($section->Journey, $date, null, $field);
  57 + }
  58 + }
  59 + $field = $parentField.'/walk';
  60 + if (ResultLimit::isFieldSet($field)) {
  61 + if ($section->Walk) {
  62 + $parts['walk'] = Entity\Schedule\Walk::createFromXml($section->Walk, $date);
  63 + }
  64 + }
  65 + $field = $parentField.'/departure';
  66 + if (ResultLimit::isFieldSet($field)) {
  67 + $parts['departure'] = Entity\Schedule\Stop::createFromXml($section->Departure->BasicStop, $date, null, $field);
  68 + }
  69 + $field = $parentField.'/departure';
  70 + if (ResultLimit::isFieldSet($field)) {
  71 + $parts['arrival'] = Entity\Schedule\Stop::createFromXml($section->Arrival->BasicStop, $date, null, $field);
  72 + }
46 73
47   - if ($section->Walk) {
48   - $parts['walk'] = Entity\Schedule\Walk::createFromXml($section->Walk, $date);
  74 + $obj->sections[] = $parts;
49 75 }
50   -
51   - $parts['departure'] = Entity\Schedule\Stop::createFromXml($section->Departure->BasicStop, $date);
52   - $parts['arrival'] = Entity\Schedule\Stop::createFromXml($section->Arrival->BasicStop, $date);
53   -
54   - $obj->sections[] = $parts;
55   - }
56   -
  76 + }
57 77 return $obj;
58 78 }
59   -}
  79 +}
16 lib/Transport/Entity/Schedule/Journey.php
@@ -2,6 +2,8 @@
2 2
3 3 namespace Transport\Entity\Schedule;
4 4
  5 +use Transport\ResultLimit;
  6 +
5 7 class Journey
6 8 {
7 9
@@ -29,13 +31,13 @@ class Journey
29 31 * @var string
30 32 */
31 33 public $to;
32   -
  34 +
33 35 /**
34 36 * @var array
35 37 */
36 38 public $passList = array();
37 39
38   - static public function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Journey $obj = null)
  40 + static public function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Journey $obj = null, $parentField = '')
39 41 {
40 42 if (!$obj) {
41 43 $obj = new Journey();
@@ -67,10 +69,12 @@ static public function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Jo
67 69 }
68 70 }
69 71 }
70   -
71   - if($xml->PassList->BasicStop) {
72   - foreach ($xml->PassList->BasicStop AS $basicStop) {
73   - $obj->passList[] = Stop::createFromXml($basicStop, $date);
  72 + $field = $parentField.'/passList';
  73 + if (ResultLimit::isFieldSet($field)) {
  74 + if($xml->PassList->BasicStop) {
  75 + foreach ($xml->PassList->BasicStop AS $basicStop) {
  76 + $obj->passList[] = Stop::createFromXml($basicStop, $date, null, $field);
  77 + }
74 78 }
75 79 }
76 80
9 lib/Transport/Entity/Schedule/StationBoardJourney.php
@@ -2,6 +2,8 @@
2 2
3 3 namespace Transport\Entity\Schedule;
4 4
  5 +use Transport\ResultLimit;
  6 +
5 7 /**
6 8 * Request for a station board journey
7 9 */
@@ -18,7 +20,7 @@ class StationBoardJourney extends Journey
18 20 * @param Journey $obj An optional existing journey to overwrite
19 21 * @return Journey
20 22 */
21   - static public function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Journey $obj = null)
  23 + static public function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Journey $obj = null, $parentField = '')
22 24 {
23 25 if (!$obj) {
24 26 $obj = new StationBoardJourney();
@@ -26,7 +28,10 @@ static public function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Jo
26 28
27 29 $obj = Journey::createFromXml($xml, $date, $obj);
28 30
29   - $obj->stop = Stop::createFromXml($xml->MainStop->BasicStop, $date);
  31 + $field = $parentField.'/stop';
  32 + if (ResultLimit::isFieldSet($field)) {
  33 + $obj->stop = Stop::createFromXml($xml->MainStop->BasicStop, $date, null, $field);
  34 + }
30 35
31 36 return $obj;
32 37 }
37 lib/Transport/Entity/Schedule/Stop.php
@@ -3,6 +3,7 @@
3 3 namespace Transport\Entity\Schedule;
4 4
5 5 use Transport\Entity;
  6 +use Transport\ResultLimit;
6 7
7 8 /**
8 9 * Basic Stop
@@ -49,7 +50,7 @@ static public function calculateDateTime($time, \DateTime $date)
49 50 return $date;
50 51 }
51 52
52   - static public function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Stop $obj = null)
  53 + static public function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Stop $obj = null, $parentField = '')
53 54 {
54 55 if (!$obj) {
55 56 $obj = new Stop();
@@ -57,19 +58,37 @@ static public function createFromXml(\SimpleXMLElement $xml, \DateTime $date, St
57 58
58 59 $dateTime = null;
59 60 $isArrival = false;
60   - $obj->station = Entity\Location\Station::createFromXml($xml->Station);
  61 + $field = $parentField.'/station';
  62 + if (ResultLimit::isFieldSet($field)) {
  63 + $obj->station = Entity\Location\Station::createFromXml($xml->Station);
  64 + }
61 65 if ($xml->Arr) {
62 66 $isArrival = true;
63   - $dateTime = self::calculateDateTime((string) $xml->Arr->Time, $date);
64   - $obj->arrival = $dateTime->format(\DateTime::ISO8601);
65   - $obj->platform = trim((string) $xml->Arr->Platform->Text);
  67 + $field = $parentField.'/arrival';
  68 + if (ResultLimit::isFieldSet($field)) {
  69 + $dateTime = self::calculateDateTime((string) $xml->Arr->Time, $date);
  70 + $obj->arrival = $dateTime->format(\DateTime::ISO8601);
  71 + }
  72 + $field = $parentField.'/platform';
  73 + if (ResultLimit::isFieldSet($field)) {
  74 + $obj->platform = trim((string) $xml->Arr->Platform->Text);
  75 + }
66 76 }
67 77 if ($xml->Dep) {
68   - $dateTime = self::calculateDateTime((string) $xml->Dep->Time, $date);
69   - $obj->departure = $dateTime->format(\DateTime::ISO8601);
70   - $obj->platform = trim((string) $xml->Dep->Platform->Text);
  78 + $field = $parentField.'/departure';
  79 + if (ResultLimit::isFieldSet($field)) {
  80 + $dateTime = self::calculateDateTime((string) $xml->Dep->Time, $date);
  81 + $obj->departure = $dateTime->format(\DateTime::ISO8601);
  82 + }
  83 + $field = $parentField.'/platform';
  84 + if (ResultLimit::isFieldSet($field)) {
  85 + $obj->platform = trim((string) $xml->Dep->Platform->Text);
  86 + }
  87 + }
  88 + $field = $parentField.'/prognosis';
  89 + if (ResultLimit::isFieldSet($field)) {
  90 + $obj->prognosis = Prognosis::createFromXml($xml->StopPrognosis, $dateTime, $isArrival);
71 91 }
72   - $obj->prognosis = Prognosis::createFromXml($xml->StopPrognosis, $dateTime, $isArrival, null);
73 92
74 93 return $obj;
75 94 }
76 lib/Transport/ResultLimit.php
... ... @@ -0,0 +1,76 @@
  1 +<?php
  2 +
  3 +namespace Transport;
  4 +
  5 +/**
  6 +* ResultLimit
  7 +*/
  8 +class ResultLimit
  9 +{
  10 + private static $fields = array();
  11 +
  12 + private function __construct()
  13 + {
  14 + }
  15 +
  16 + public static function setFields(array $fields)
  17 + {
  18 + foreach ($fields as $field) {
  19 + self::$fields = array_merge_recursive(self::$fields, self::getFieldTree($field));
  20 + }
  21 + }
  22 +
  23 + /**
  24 + * removes all set fields. Needed for tests.
  25 + *
  26 + */
  27 + public static function unsetFields() {
  28 + self::$fields = array();
  29 + }
  30 +
  31 + /**
  32 + * returns true if the given field should be included in the result.
  33 + *
  34 + * @param string $field the field (e.g from)
  35 + */
  36 + public static function isFieldSet($field)
  37 + {
  38 + //if no fields were set, return true, this is the default
  39 + if (count(self::$fields) == 0) {
  40 + return true;
  41 + }
  42 + $fieldParts = explode('/',$field);
  43 + $fieldFromTree = null;
  44 + $searchTree = self::$fields;
  45 + foreach($fieldParts as $fieldPart) {
  46 + if (array_key_exists($fieldPart, $searchTree)) {
  47 + $fieldFromTree = $searchTree[$fieldPart];
  48 + } else {
  49 + //if a part is not set, no child fields should be included
  50 + return false;
  51 + }
  52 + //if a part is set to true, all child fields should be included
  53 + if ($fieldFromTree === true) {
  54 + return true;
  55 + }
  56 + //continue the search
  57 + $searchTree = $fieldFromTree;
  58 + }
  59 + //if the found field is an array,
  60 + //there are more specific fields set,
  61 + //so their parent should be included
  62 + if (is_array($fieldFromTree)) {
  63 + return true;
  64 + }
  65 + return false;
  66 + }
  67 +
  68 + private static function getFieldTree($field)
  69 + {
  70 + return array_reduce(
  71 + array_reverse(explode('/', $field)),
  72 + function ($result, $value) { return array($value => $result); },
  73 + true
  74 + );
  75 + }
  76 +}
42 test/Transport/Test/Entity/Schedule/ConnectionResultLimitTest.php
... ... @@ -0,0 +1,42 @@
  1 +<?php
  2 +
  3 +namespace Transport\Test\Entity\Schedule;
  4 +
  5 +use Transport\Entity;
  6 +use Transport\Entity\Schedule\Connection;
  7 +
  8 +use Transport\ResultLimit;
  9 +
  10 +class ConnectionResultLimitTest extends \PHPUnit_Framework_TestCase
  11 +{
  12 + protected function getConnection()
  13 + {
  14 + $from = new Entity\Schedule\Stop();
  15 + $station = new Entity\Location\Station();
  16 + $station->name = "Zürich HB";
  17 + $station->id = "008503000";
  18 + $coordinates = new Entity\Coordinate();
  19 + $coordinates->x = 8.540192;
  20 + $coordinates->y = 47.378177;
  21 + $coordinates->type = "WGS84";
  22 + $station->coordinate = $coordinates;
  23 + $from->station = $station;
  24 +
  25 + $to = new Entity\Schedule\Stop();
  26 + $to->arrival = '2012-01-31T19:42:00+0100';
  27 + $connection = new Entity\Schedule\Connection();
  28 + $connection->from = $from;
  29 + $connection->to = $to;
  30 + $connection->sections = null;
  31 +
  32 + return $connection;
  33 + }
  34 +
  35 + public function testCreateFromXml()
  36 + {
  37 + $xml = simplexml_load_file(__DIR__ . '/../../../../fixtures/connection.xml');
  38 + ResultLimit::setFields(array('connections/from/station','connections/to/arrival'));
  39 + $this->assertEquals($this->getConnection(), Connection::createFromXml($xml->ConRes->ConnectionList->Connection, null, 'connections'));
  40 + }
  41 +}
  42 +
4 test/Transport/Test/Entity/Schedule/ConnectionTest.php
@@ -5,6 +5,8 @@
5 5 use Transport\Entity;
6 6 use Transport\Entity\Schedule\Connection;
7 7
  8 +use Transport\ResultLimit;
  9 +
8 10 class ConnectionTest extends \PHPUnit_Framework_TestCase
9 11 {
10 12 protected function getConnection()
@@ -66,7 +68,7 @@ protected function getConnection()
66 68 public function testCreateFromXml()
67 69 {
68 70 $xml = simplexml_load_file(__DIR__ . '/../../../../fixtures/connection.xml');
69   -
  71 + ResultLimit::unsetFields();
70 72 $this->assertEquals($this->getConnection(), Connection::createFromXml($xml->ConRes->ConnectionList->Connection));
71 73 }
72 74 }
3  test/Transport/Test/Entity/Schedule/StationBoardJourneyTest.php
@@ -5,6 +5,8 @@
5 5 use Transport\Entity;
6 6 use Transport\Entity\Schedule\StationBoardJourney;
7 7
  8 +use Transport\ResultLimit;
  9 +
8 10 class StationBoardJourneyTest extends \PHPUnit_Framework_TestCase
9 11 {
10 12 protected function getJourney()
@@ -44,6 +46,7 @@ public function testCreateFromXml()
44 46 $date = \DateTime::createFromFormat('Y-m-d', '2012-03-31', new \DateTimeZone('Europe/Zurich'));
45 47 $date->setTimezone(new \DateTimeZone('Europe/Zurich'));
46 48 $date->setTime(0, 0, 0);
  49 + ResultLimit::unsetFields();
47 50 $this->assertEquals($this->getJourney(), StationBoardJourney::createFromXml($xml->STBRes->JourneyList->STBJourney[0], $date));
48 51 }
49 52 }
25 web/api.php
@@ -11,6 +11,8 @@
11 11 use Transport\Entity\Schedule\ConnectionQuery;
12 12 use Transport\Entity\Schedule\StationBoardQuery;
13 13
  14 +use Transport\ResultLimit;
  15 +
14 16 date_default_timezone_set('Europe/Zurich');
15 17
16 18 // init
@@ -94,7 +96,6 @@
94 96
95 97 // connections
96 98 $app->get('/v1/connections', function(Request $request) use ($app) {
97   -
98 99 // validate
99 100 $from = $request->get('from');
100 101 $to = $request->get('to');
@@ -117,6 +118,8 @@
117 118 $couchette = $request->get('chouchette');
118 119 $bike = $request->get('bike');
119 120
  121 + ResultLimit::setFields($request->get('fields') ?: array());
  122 +
120 123 if ($limit > 6) {
121 124 return new Response('Maximal value of argument `limit` is 6.', 400);
122 125 }
@@ -158,10 +161,19 @@
158 161 if ($bike) {
159 162 $query->bike = $bike;
160 163 }
161   - $connections = $app['api']->findConnections($query);
  164 + $connections = $app['api']->findConnections($query, 'connections');
162 165 }
163   -
164   - return $app->json(array('connections' => $connections, 'from' => $from, 'to' => $to, 'stations' => $stations));
  166 + $result = array('connections' => $connections);
  167 + if (ResultLimit::isFieldSet('from')) {
  168 + $result = array_merge($result,array('from' => $from));
  169 + }
  170 + if (ResultLimit::isFieldSet('to')) {
  171 + $result = array_merge($result,array('to' => $to));
  172 + }
  173 + if (ResultLimit::isFieldSet('stations')) {
  174 + $result = array_merge($result,array('stations' => $stations));
  175 + }
  176 + return $app->json($result);
165 177 });
166 178
167 179
@@ -187,6 +199,8 @@
187 199 }
188 200
189 201 $transportations = $request->get('transportations');
  202 +
  203 + ResultLimit::setFields($request->get('fields') ?: array());
190 204
191 205 if (!$station) {
192 206
@@ -203,9 +217,8 @@
203 217 $query->transportations = $transportations;
204 218 }
205 219 $query->maxJourneys = $limit;
206   - $stationboard = $app['api']->getStationBoard($query);
  220 + $stationboard = $app['api']->getStationBoard($query, 'stationboard');
207 221 }
208   -
209 222 return $app->json(array('stationboard' => $stationboard));
210 223 });
211 224

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.