Exemplo n.º 1
0
 public function __construct(Neo4j\Client $client, Slim\Slim $app, Theme $theme = null, array $options = null)
 {
     $this->setOptions($options);
     $this->app = $app;
     $this->client = $client;
     $this->schema = new Schema($client);
     if ($theme) {
         $this->setTheme($theme);
     }
     if ($this->hasOption('upload.directory')) {
         $this->setUploadDirectory($this->getOption('upload.directory'));
     }
     // Set up the home route.
     $app->get('/', Closure::bind(function () {
         $controller = new Controllers\HomeController($this->app, $this->schema, $this->client);
         $controller->read();
     }, $this));
     // Set up the uploads route.
     $app->get($this->getOption('path.format.uploads'), Closure::bind(function ($file_name) {
         $controller = new Controllers\UploadController($this->app);
         $controller->read($file_name);
     }, $this));
     // Set up the search controller.
     $app->get($this->getOption('path.format.search'), Closure::bind(function () {
         $controller = new Controllers\SearchController($this->app, $this->schema, $this->client);
         $controller->run();
     }, $this))->name('search');
     // Set up the resources controller.
     $this->app->get($this->getOption('path.format.resources'), Closure::bind(function (array $resource_path) {
         $theme = $this->getTheme();
         // Pass if not an instance or child of the default theme, as Theme#renderResource won't be present.
         // In non-standard use cases, this allows the user to use a regular Slim\View as the view.
         if (!$theme) {
             $this->getApp()->pass();
         }
         $controller = new Controllers\FileController($this->app);
         if ($theme->hasResource($resource_path)) {
             $controller->read($theme->getResourcePath($resource_path));
         } else {
             $this->getApp()->notFound(new Exceptions\Exception('Unknown resource "' . implode('/', $resource_path) . '".'));
         }
     }, $this))->name('resources');
     // Set up a default handler for 404 errors.
     // Only Penelope application-generated exceptions are permitted.
     $app->notFound(function (Exceptions\Exception $e = null) {
         if (!$e) {
             $e = new Exceptions\NotFoundException('The requested page cannot be found.');
         }
         $controller = new Controllers\Controller($this->app);
         $this->app->render('error', array('title' => $controller->_m('error_404_title'), 'error' => $e), 404);
     });
 }
Exemplo n.º 2
0
 public function read($file_name)
 {
     $system_path = File::getSystemPath($file_name);
     // Null is returned if the given file name is invalid.
     // TODO: `File::getSystemPath` should throw an exception and it should be handled here.
     if (!$system_path) {
         $this->app->notFound();
         return;
     }
     parent::read($system_path);
 }