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
 private function processMultiFile(TransientProperty $transient_property, $file)
 {
     // Expecting an array of files.
     if (!is_array($file['error'])) {
         $transient_property->setError(new Exceptions\TypeException('Expecting multiple files; only one received.'));
         return;
     }
     $value = $transient_property->getValue();
     // Array of files needs a second loop.
     foreach ($file['error'] as $i => $error) {
         if (UPLOAD_ERR_OK === $error) {
             try {
                 $perm_name = UploadController::move($file['tmp_name'][$i], $file['name'][$i]);
             } catch (\RuntimeException $e) {
                 $transient_property->setError($e);
             }
             if ($perm_name) {
                 $value[] = array($perm_name, $file['name'][$i]);
             }
         } else {
             if (UPLOAD_ERR_NO_FILE !== $error or $transient_property->getSchema()->getOption('required')) {
                 $transient_property->setError(new Exceptions\UploadException($error));
             }
         }
     }
     $transient_property->setValue($value);
 }