/** * @Route("/stac/schedule/{id}/{direction}.{format}") * @Route("/stac/schedule/{id}/{direction}") * @Route("/stac/schedule/{id}.{format}") * @Route("/stac/schedule/{id}") */ public function stacScheduleAction($id, $direction = 'normal', $date = null, $format = 'json') { # Initialize date to today if (!$date instanceof DateTime) { $date = new DateTime('now'); } $id = intval($id); $sens = $direction === 'normal' ? 1 : 2; # Cache link $cacheLink = $this->get('kernel')->getRootDir() . '/../data/stac'; # Create cache dir if not exists if (!is_dir($cacheLink)) { if (!mkdir($cacheLink, 0777, true)) { return new FormattedResponse(array('type' => 'error', 'message' => 'Impossible to create cache', 'code' => 500), 500, $format); } } # 12 Hours update $update = 12 * 60 * 60; # Formalize Data $formalizer = new Formalizer($cacheLink, $update); $json = $formalizer->serviceSchedules($id, $sens, $date); if (isset($json['type']) and $json['type'] === 'error') { return new FormattedResponse($json, $json['code'], $format); } # Show json return new FormattedResponse($json, 200, $format); }
* Gnkam Autobus is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Gnkam Autobus. If not, see <http://www.gnu.org/licenses/>. */ require_once __DIR__ . '/../vendor/autoload.php'; use Gnkam\Autobus\Stac\Formalizer; ################## # Example of use # ################## # Set headers header('Content-Type: application/json'); # Cache link $cacheLink = __DIR__ . '/cache'; # Create cache dir if not exists if (!is_dir($cacheLink)) { if (!mkdir($cacheLink)) { echo json_encode('error', 'Impossible to create cache'); return; } } # 12 Hours update $update = 12 * 60 * 60; # Formalize Data $formalizer = new Formalizer($cacheLink, $update); $json = $formalizer->serviceSchedules(26); # Show json echo json_encode($json);