$app = new \Slim\App(['settings' => ['displayErrorDetails' => 'true']]); $container = $app->getContainer(); $container['view'] = function ($container) { return new \Slim\Views\PhpRenderer('views/'); }; $container['flash'] = function () { return new \Slim\Flash\Messages(); }; $controller = new MeaningController($app); $app->get('/', function ($request, $response, $args) use($controller) { return $controller->index(); }); $app->get('/search/{keyword}', function ($request, $response, $args) use($controller) { return call_user_func_array(array($controller, 'search'), $args); }); $app->get('/view/{id}', function ($request, $response, $args) use($controller) { return call_user_func_array(array($controller, 'view'), $args); }); $app->map(['GET', 'POST'], '/edit/{id}', function ($request, $response, $args) use($controller) { return call_user_func_array(array($controller, 'edit'), $args); }); $app->get('/delete/{id}', function ($request, $response, $args) use($controller) { return call_user_func_array(array($controller, 'delete'), $args); }); $app->map(['GET', 'POST'], '/api', function ($request, $response, $args) use($controller) { return call_user_func_array(array($controller, 'api'), $args); }); $app->get('/import', function ($request, $response, $args) use($controller) { return call_user_func_array(array($controller, 'import'), $args); }); $app->run();
$container = $app->getContainer(); $container['view'] = function ($container) { $view = new \Slim\Views\Twig('./templates'); $view->addExtension(new \Slim\Views\TwigExtension($container['router'], $container['request']->getUri())); return $view; }; $app->get('/', function ($request, $response, $args) { return $this->view->render($response, 'index.phtml'); })->setName('index'); $app->get('/util', "jra\\HomeController:dispatch"); $app->map(['GET', 'POST'], '/util/photodata', function ($request, $response, $args) { $path = './assets/images/photodata/'; $filename = $_FILES['file']['name']; $fileManager = new FileManager(); $fileManager->uploadFile($path . $filename); $imageFactory = new ImageFactory(); //Don't see why I need to call this again even though it's //called in the constructor? $imageFactory->populateImages(); return $this->view->render($response, 'photodata.phtml', ['title' => 'Exif Data Viewer', 'images' => $imageFactory->images, 'stylesheet' => '/assets/css/components/cards/card-1/card-1.css', 'sweetalertcss' => '/libraries/sweetalert/dist/sweetalert.css', 'sweetalertjs' => '/libraries/sweetalert/dist/sweetalert.min.js', 'script' => '/assets/js/photodata.js']); }); $app->map(['GET', 'POST'], '/util/rawtext', function ($request, $response, $args) { return $this->view->render($response, 'rawtext.phtml', ['title' => 'Raw Text', 'input' => json_encode($_POST['input'])]); }); $app->get('/util/webgrep', function ($request, $response, $args) { return $this->view->render($response, 'webgrep.phtml', ['title' => 'Grep The Web!']); }); $app->get('/util/imagemaker', function ($request, $response, $args) { return $this->view->render($response, 'imagemaker.phtml', ['title' => 'Imagemaker']); }); $app->post('/util/imagemaker', function ($request, $response, $args) {
$this->view->render($response, 'show_video.html.twig', array('videoProxy' => $videoProxy)); return $response; })->setName('show_video'); $app->get('/admin/', function ($request, $response, $args) { $channels = $this->get('tvlistings.channel.repository')->findAll(); $this->view->render($response, 'admin/list.html.twig', array('channels' => $channels, 'flash' => $this->flash)); return $response; })->setName('admin_homepage'); $app->map(['GET', 'POST'], '/admin/channels/new', function ($request, $response, $args) { if ($request->isPost()) { $parsedBody = $request->getParsedBody(); $channel = new Channel($parsedBody['name'], $parsedBody['logoPath']); $channelRepository = $this->get('tvlistings.channel.repository'); $uri = $this->router->pathFor('admin_homepage', array()); if (null !== $channelRepository->findOneBySlug($channel->getSlug())) { $this->flash->addMessage('error', sprintf('Энэ суваг (%s) аль хэдийн бүртгэгдсэн байна.', $channel->getName())); return $response->withRedirect((string) $uri, 301); } $channelRepository->persist($channel); return $response->withRedirect((string) $uri, 301); } $this->view->render($response, 'admin/new.html.twig', array()); return $response; })->setName('admin_channel_new'); $app->post('/admin/channels/{slug}', function ($request, $response, $args) { $channel = $this->get('tvlistings.channel.repository')->findOneBySlug($args['slug']); if (null === $channel) { $uri = $this->router->pathFor('homepage', array()); return $response->withRedirect((string) $uri, 301); } $this->get('tvlistings.channel.repository')->delete($channel); $uri = $this->router->pathFor('admin_homepage', array());
return $generator->generateString(8, $generator::CHAR_LOWER); }; $container['cache'] = function () { return new \Slim\HttpCache\CacheProvider(); }; $app->add(new \Slim\HttpCache\Cache('public', 0)); $container['view'] = function ($c) { $view = new \Slim\Views\Twig('templates'); $view->addExtension(new Slim\Views\TwigExtension($c['router'], $c['request']->getUri())); return $view; }; $app->map(['GET', 'POST'], '/', function (\Slim\Http\Request $req, \Slim\Http\Response $res, $args) { if ($req->isPost()) { $board = new \Sprintboard\Model\Sprint(); $board->name = $req->getParam('name'); $board->hash = $this->generateHash; $board->save(); return $res->withRedirect($this->router->pathFor('boardView', ['boardHash' => $board->hash])); } return $this->view->render($res, 'boardAdd.twig'); }); $app->get('/team/{teamHash}', function (\Slim\Http\Request $req, \Slim\Http\Response $res, $args) { try { $team = \Sprintboard\Model\Team::where('hash', $args['teamHash'])->firstOrFail(); $this->view->offsetSet('team', $team); return $this->view->render($res, 'teamView.twig'); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { return $this->notFoundHandler($req, $res); } })->setName('teamView'); $app->get('/team/{teamHash}/{sprintId}', function (\Slim\Http\Request $req, \Slim\Http\Response $res, $args) { try {
$app = new \Slim\App(); $container = $app->getContainer(); $container['renderer'] = new PhpRenderer('./templates/'); $container['notFoundHandler'] = function ($container) { return function ($request, $response) use($container, $dati) { $container->renderer->render($response, 'shared/404.php', array('dati' => $dati)); return $response; }; }; $app->get('/', function ($request, $response, $args) use($dati) { $response = $this->renderer->render($response, 'index.php', array('dati' => $dati)); return $response; })->setName('index'); $app->map(['GET', 'POST'], '/contattaci', function ($request, $response, $args) use($dati) { $response = $this->renderer->render($response, 'email.php', array('dati' => $dati)); if (fatto()) { $response = $response->withStatus(301)->withHeader('Location', $this->router->pathFor('index')); } }); $app->map(['GET', 'POST'], '/templates[/{name+}]', function ($request, $response, $args) use($dati) { $response = $this->renderer->render($response, 'shared/404.php', array('dati' => $dati)); return $response; }); $app->get('/guida/:id', function ($request, $response, $args) use($dati) { $response = $this->renderer->render($response, 'index.php', array('dati' => $dati, 'guida' => $args['id'])); return $response; }); if (!$dati['debug']) { $app->map(['GET', 'POST'], '/login', function ($request, $response, $args) use($dati) { $response = $this->renderer->render($response, 'login/index.php', array('dati' => $dati)); if (isUserAutenticate()) { $response = $response->withStatus(301)->withHeader('Location', $this->router->pathFor('index'));
$response->getBody()->write($actn_res); } elseif ($actn_res instanceof \Psr\Http\Message\ResponseInterface) { $response = $actn_res; //the action returned a Response object } return $response; }; //////////////////////////////////////////////////////////////////////////////// // Start: Load app specific routes //////////////////////////////////////////////////////////////////////////////// require_once "{$s3mvc_root_dir}config" . DIRECTORY_SEPARATOR . 'routes.php'; //////////////////////////////////////////////////////////////////////////////// // End: Load app specific routes //////////////////////////////////////////////////////////////////////////////// ///////////////////////////// // Start: mvc routes ///////////////////////////// if (S3MVC_APP_USE_MVC_ROUTES) { //default route $app->map(['GET', 'POST'], '/', $s3mvc_default_route_handler); //controller with no action and params route handler $app->map(['GET', 'POST'], '/{controller}[/]', $s3mvc_controller_only_route_handler); //controller with action and optional params route handler $app->map(['GET', 'POST'], '/{controller}/{action}[/{parameters:.+}]', $s3mvc_route_handler); $app->map(['GET', 'POST'], '/{controller}/{action}/', $s3mvc_route_handler); //handle trailing slash } ///////////////////////////// // End: mvc routes ///////////////////////////// $app->run();
* User: Administrator * Date: 2016/1/17 * Time: 23:58 */ require '../../slim/vendor/autoload.php'; use Psr\Http\Message\RequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; use Hilly\Http\Dispatcher; $c = new \Slim\Container(); //Create Your container //Override the default Not Found Handler $c['notFoundHandler'] = function ($c) { return function (Request $request, Response $response) use($c) { return $c['response']->withStatus(200)->withHeader('Content-Type', 'application/json;charset=utf8')->write(json_encode(['info' => 'not found', 'status' => 404, 'data' => []])); }; }; // $app = new Slim\App($c); $app->map(['GET', 'POST'], '/a/{name}', function ($request, $response, $args) { // $response->write("Welcome to Slim!"); // // return $response; $this['dispatcher'] = new Dispatcher\Controller($request, $response, $args); return $response; })->add(function (Request $request, Response $response, $next) { $response->getBody()->write('BEFORE'); $response = $next($request, $response); $response->getBody()->write('AFTER'); return $response; }); $app->run();
return new \Slim\HttpCache\CacheProvider(); }; $container['auth'] = function () use($auth) { return $auth; }; $container['library'] = function () { return new \Clearcode\EHLibrary\Application(); }; $app = new \Slim\App($container); $app->add(new \Slim\HttpCache\Cache('public', 86400)); $authenticationMiddleware = new AuthenticationMiddleware($auth); /** * example working route */ $app->map(['GET'], '/test', function (ServerRequestInterface $request, ResponseInterface $response, $args = []) { $response->getBody()->write('It works!' . '</br>' . 'you can see that these properties were injected using dependency injection container' . '</br>' . 'which you can use to add your own services if needed to the task' . '</br>' . 'auth property is of class ' . get_class($this->auth) . '</br>' . 'library property is of class ' . get_class($this->library) . '</br>'); return $response; }); ////Login user (login by email only - no password) //$app->map(['<method>'], '<url>', function(ServerRequestInterface $request, ResponseInterface $response, $args = []) { // // /* your code here */ // // $user = $this->auth->getUser(/* arguments */); // // if (!$user instanceof User) { // /* your code here */ // } // // $token = $this->auth->generateToken(/* arguments */); // // /* your code here */
$app->map(['GET', 'POST'], '/tests/{id}', function ($request, $response, $args) { $testId = $args['id']; if ($request->isGet()) { switch ($testId) { case 1: $testProvider = new Chabanenko\SimpleQuiz\DataProvider\StringFunctionsTestProvider(); $question = $testProvider->getRandomQuestionByTerm(); $templatePath = 'views/render_question.php'; break; case 2: $testProvider = new Chabanenko\SimpleQuiz\DataProvider\StringFunctionsTestProvider(); $question = $testProvider->getRandomQuestionByDescription(); $templatePath = 'views/render_question_description.php'; break; case 3: $testProvider = new Chabanenko\SimpleQuiz\DataProvider\ArrayFunctionsTestProvider(); $question = $testProvider->getRandomQuestionByTerm(); $templatePath = 'views/render_question.php'; break; case 4: $testProvider = new Chabanenko\SimpleQuiz\DataProvider\ArrayFunctionsTestProvider(); $question = $testProvider->getRandomQuestionByDescription(); $templatePath = 'views/render_question_description.php'; break; default: $templatePath = 'views/tests_list.php'; break; } $_SESSION['question'] = $question; require_once $templatePath; } else { $chosenAnswer = $request->getParam('answer'); $generatedQuestion = $_SESSION['question']; $statistics = $_SESSION['statistics']; if (isset($statistics[$generatedQuestion['term']])) { $termStatistics = $statistics[$generatedQuestion['term']]; } else { $termStatistics = ['total_answers' => 0, 'correct_answers' => 0]; } $termStatistics['total_answers']++; if ($chosenAnswer == $generatedQuestion['correctItemNumber']) { $termStatistics['correct_answers']++; $correct = true; } $statistics[$generatedQuestion['term']] = $termStatistics; $_SESSION['statistics'] = $statistics; require_once 'views/render_statistics.php'; } })->setName('tests');