/** * @Route("/{id}.{format}") * @Route("/{id}") * @Method({"GET"}) */ public function menuIdAction($id, $format = 'json') { $id = intval($id); # Cache link $cacheLink = $this->get('kernel')->getRootDir() . '/../data'; # Create cache dir if not exists if (!is_dir($cacheLink)) { if (!mkdir($cacheLink)) { return new FormattedResponse(array('type' => 'error', 'message' => 'Impossible to create cache', 'code' => 500), 500, $format); } } # 6 Hours update $update = 6 * 60 * 60; # Formalize Data $formalizer = new Formalizer($cacheLink, $update); $json = $formalizer->serviceMenu($id); if (isset($json['type']) and $json['type'] === 'error') { return new FormattedResponse($json, $json['code'], $format); } # Show json return new FormattedResponse($json, 200, $format); }
* Gnkam Univ Savoie Menu 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 Univ Savoie Menu. If not, see <http://www.gnu.org/licenses/>. */ require_once __DIR__ . '/../vendor/autoload.php'; use Gnkam\Crous\Grenoble\Menu\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; } } # 6 Hours update $update = 6 * 60 * 60; # Formalize Data $formalizer = new Formalizer($cacheLink, $update); $json = $formalizer->serviceMenu('abc'); # Show json echo json_encode($json);