Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * 
  * @see \compact\IAppContext::routes()
  */
 public function routes(Router $router)
 {
     /**
      * Show the upload form (with optionally uploaded image)
      */
     $router->add("^/upload\$", function () {
         return UploadController::create()->form();
     }, 'GET');
     /**
      * Handle the upload via POST
      */
     $router->add("^/upload\$", function () {
         return UploadController::create()->upload();
     }, 'POST');
     /**
      * Returns the requested image with thumb applied
      *
      * Url: /img/thumb/center/width=500;height=500/img.png
      * Options: rate:5|opacity:10
      */
     $router->add('^/img/thumb/([a-z]+)/?(.*)?/(.*\\.[a-z]+)', function ($filter, $optionsString, $image) {
         ini_set('max_execution_time', 180);
         $image = Context::get()->basePath('/img/original/' . $image);
         $controller = new \controllers\ThumbnailController();
         $method = str_replace(['-', '_'], [''], $filter);
         $options = $this->parseOptions($optionsString);
         if (method_exists($controller, $method)) {
             // apply filters
             $builder = $controller->{$method}($image, $options);
             // cache image
             $this->cacheImage($builder, 'thumb' . DIRECTORY_SEPARATOR . $filter, $optionsString, $image);
             return $builder;
         }
         throw new \Exception("Method " . $method . " not found on " . get_class($controller));
     });
     /**
      * Returns the requested image with filter applied
      * 
      * Url: /img/[filter]/[option=value;option=value]/img.png
      * Options: rate:5|opacity:10
      */
     $router->add('^/img/([a-z]+)/?(.*)?/(.*\\.[a-z]+)', function ($filter, $optionsString, $image) {
         ini_set('max_execution_time', 180);
         $image = Context::get()->basePath('/img/original/' . $image);
         $controller = new \controllers\FilterController();
         $method = str_replace(['-', '_'], [''], $filter);
         $options = $this->parseOptions($optionsString);
         if (method_exists($controller, $method)) {
             // apply filters
             $builder = $controller->{$method}($image, $options);
             // cache image
             $this->cacheImage($builder, $filter, $optionsString, $image);
             return $builder;
         }
         throw new \Exception("Method " . $method . " not found on " . get_class($controller));
     });
 }
Ejemplo n.º 2
0
 /**
  * (non-PHPdoc)
  *
  * @see \compact\IAppContext::routes()
  */
 public function routes(Router $router)
 {
     // Enable CORS preflight request
     $router->add('.*', function () {
         // allow CORS
         Context::get()->http()->getResponse()->setCORSHeaders();
         return " ";
     }, 'OPTIONS');
     /*
      * Get an existing gulpfile
      * 
      * url /gulpfile/2191B876-84A0-DB62-FBBD-8BD9D0584887
      */
     $router->add("^/gulpfile/(" . self::GUID_REGEX . ")\$", function ($guid) {
         return \gulp\GulpfileController::instance()->get($guid);
     }, 'GET');
     /*
      * Add a new gulpfile
      */
     $router->add("^/gulpfile\$", function () {
         return \gulp\GulpfileController::instance()->post();
     }, 'POST');
     /*
      * Generate the gulp task
      * 
      * url /generate/2191B876-84A0-DB62-FBBD-8BD9D0584887
      */
     $router->add("^/generate/(" . self::GUID_REGEX . ")\$", function ($guid) {
         return \gulp\GulpfileController::instance()->download($guid);
     }, 'GET');
     /*
      * Returns all predefined tasks
      */
     $router->add("^/predefinedtasks\$", function () {
         return \gulp\GulpfileController::instance()->getPredefinedTasks();
     }, 'GET');
     /*
      * Add a task to an existing gulp file
      * 
      * url: /tasks/25A5E4D5-B7B2-BF8B-28FE-854E8E56C4C4
      */
     $router->add("^/tasks/(" . self::GUID_REGEX . ")\$", function ($guid) {
         return \gulp\GulpfileController::instance()->addtask($guid);
     }, 'PUT');
     /**
      * Errors
      */
     $router->add(404, function () {
         return new ViewModel('404.html');
     });
     $router->add(500, function () {
         return new ViewModel('500.html');
     });
 }