/**
  * Creates a new reporitory to store the models in
  *
  * @param $guid The
  *            guid of the gulpfile
  * @param
  *            createIfNotExists boolean to denote if the file should be created when it doesn't exists yet
  *            
  * @throws FileNotFoundException when createIfNotExists = false (by default) and the file does not exist
  *        
  * @return \compact\repository\IModelRepository
  */
 private function createDb($guid, $createIfNotExists = false)
 {
     assert(strlen($guid) > 10);
     $filepath = Context::get()->basePath('app/db/' . $guid . '.json');
     if (!$createIfNotExists && !$filepath->isFile()) {
         throw new FileNotFoundException($filepath);
     }
     return new JsonRepository(new DefaultModelConfiguration(), $filepath);
 }
 /**
  * Returns all tasks as models or all tasks for a particular gulpfile
  * 
  * @return array with models
  */
 public static function getTasks($guid = null)
 {
     if ($guid === null) {
         $file = __DIR__ . "/tasks/tasks.json";
     } else {
         $file = Context::get()->basePath('app/db/' . $guid . '.json');
     }
     $json = file_get_contents($file);
     return self::convertToModel(json_decode($json)[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');
     });
 }
 /**
  * Upload the file and
  * 
  * @return \compact\mvvm\impl\ViewModel
  */
 public function upload()
 {
     $options = new UploadOptions();
     $options->setMimetypes(['image/jpg', 'image/jpeg', 'image/gif', 'image/png'])->setAllowOverwrite(false)->setMaxFiles(20)->setMaxSize(5000000)->setUploadDir(Context::get()->basePath('/img/original'), true);
     $upload = new UploadManager($options);
     $view = $this->form();
     try {
         $files = $upload->upload();
         if ($files->count() > 0) {
             $file = $files->offsetGet(0);
             $view->{'imagename'} = $file->getFilename();
         }
     } catch (UploadException $ex) {
         $view->{'error'} = $ex->getMessage();
     }
     return $view;
 }
Beispiel #5
0
 /**
  * Store the image in the static cache
  * 
  * @param ImageBuilder $builder
  * @param string $filter
  * @param string $options
  * @param \SplFileInfo $image
  */
 private function cacheImage(ImageBuilder $builder, $filter, $options, \SplFileInfo $image)
 {
     $cache = Context::get()->basePath('img');
     $filterDir = $cache . DIRECTORY_SEPARATOR . $filter;
     if (!is_dir($filterDir)) {
         mkdir($filterDir, 0777, true);
     }
     if ($options) {
         $filterOptionsDir = $filterDir . DIRECTORY_SEPARATOR . $options;
         if (!is_dir($filterOptionsDir)) {
             mkdir($filterOptionsDir, 0777);
         }
     } else {
         $filterOptionsDir = $filterDir;
     }
     $builder->save(new \SplFileInfo($filterOptionsDir . DIRECTORY_SEPARATOR . $image->getFilename()));
 }