<?php namespace { use xTend\Workbench\Workbench; require_once __DIR__ . '/../CLI/Core/Workbench.php'; Workbench::configure(); //first match all global $matched_application; $matched_application = false; foreach (Workbench::get('applications') as $name => $restrictions) { if (Workbench::match($restrictions)) { $matched_application = $name; } } if ($matched_application !== false) { require_once __DIR__ . '/../' . $matched_application . '/Core/App.php'; $matched_application = Workbench::namespace($matched_application); } } namespace Application { global $matched_application; if (__NAMESPACE__ == $matched_application) { Core\App::start(__DIR__); Core\FileHandler::system('Config.App.App.php')->include(); Core\App::run(); } }
$dir = strtolower(implode('/', $parts)); require_once __DIR__ . '/' . $dir . '/' . $file; }); ################################################################################ $app = new Core\App(); $app->services['db'] = new \Core\DB('mysql:host=localhost;dbname=capp;charset=utf8', 'root', 'root'); $app->services['movies'] = new \Repository\Movies($app->services['db']); $app->services['theaters'] = new \Repository\Theaters($app->services['db']); $app->services['showtimes'] = new \Repository\Showtimes($app->services['db']); ################################################################################ $app->getError('404', function ($request, $response) { $response->setStatus(Core\Response::HTTP_NOT_FOUND)->setContent(array('code' => $response::HTTP_NOT_FOUND, 'error' => $response::$statusTexts[$response::HTTP_NOT_FOUND])); }); ################################################################################ $app->get('/api/v1/{type}', function ($type, $request, $response) use($app) { $date = $request->query->date; $included = explode(',', $request->query->include); $model = $app->services[$type]->findAllByDate($date); $resp = new Core\JsonApiResponse($model, $included); $response->setContent($resp->format()); }); $app->get('/api/v1/{type}/{id}', function ($type, $id, $request, $response) use($app) { $date = $request->query->date; $included = explode(',', $request->query->include); $model = $app->services[$type]->findOneByIdAndDate($id, $date); $resp = new Core\JsonApiResponse($model, $included); $response->setContent($resp->format()); }); ################################################################################ $app->start();