Esempio n. 1
0
 /**
  * @controller-api
  */
 public function get(array $tplName)
 {
     $__variablesDefinitions = array();
     try {
         $tpl = new Template($tplName);
         $tpl->setLanguage(Config::req('i18n.language'));
         $tpl->setVars($__variablesDefinitions);
         if (!$tpl->validate()) {
             throw new \Psc\TPL\MissingFileException('Template ist nicht valid!');
         }
         if (!$tpl->getFile()->exists()) {
             throw new \Psc\TPL\MissingFileException('Template-File: ' . $tpl->getFile() . ' existiert nicht');
         }
         return $tpl->get();
     } catch (\Psc\TPL\MissingFileException $e) {
         throw HTTPException::NotFound('Das Template: ' . Code::varInfo($tplName) . ' ist nicht vorhanden', $e);
     }
 }
Esempio n. 2
0
 /**
  * FEHLER: Eine Resource die zum ausführen des Requests benötigt wird, wurde niicht gefunden
  *
  * z. B. Ein PUT Request wird für ein Entity gemacht welches nicht mehr vorhanden ist
  * für ein Entity soll ein Formular geladen werden, und der Identifier ergibt kein ergebnis in der Datenbank
  */
 public function resourceNotFound($method, $resourceType, $argumentValues, \Exception $e = NULL)
 {
     return HTTPException::NotFound(sprintf("Die Resource '%s' konnte nicht mit den Parametern %s gefunden werden. Der Request konnte nicht vollständig ausgeführt werden. Möglicherweise ist die Resource nicht mehr vorhanden.", $resourceType, Code::varInfo($argumentValues)), $e);
 }
Esempio n. 3
0
 public static function provideServiceExceptions()
 {
     return array(array(\Psc\Net\HTTP\HTTPException::NotFound()), array(\Psc\Net\HTTP\HTTPException::BadRequest()), array(new \Exception('Manno')), array(new \Psc\Exception('I am faling')));
 }
Esempio n. 4
0
 public function routeController(ServiceRequest $request)
 {
     $r = $this->initRequestMatcher($request);
     $controller = $r->qmatchiRx('/^(tpl|excel|images|uploads|persona)$/i');
     if ($controller === 'tpl') {
         $x = 0;
         $tpl = array();
         while (!$r->isEmpty() && $x <= 10) {
             $tpl[] = $r->qmatchRx('/^([-a-zA-Z0-9_.]+)$/');
             $x++;
         }
         $controller = new TPLController($this->project);
         return array($controller, 'get', array($tpl));
     } elseif ($controller === 'excel') {
         $controller = new ExcelController($this->project);
         if ($request->getType() === Service::POST) {
             $body = $request->getBody();
             if ($r->part() === 'convert') {
                 // importieren
                 // im body können dann options stehen oder sowas
                 // der controller holt sich die excelFile selbst
                 return array($controller, 'convert', array(is_object($body) ? $body : new \stdClass()));
             } else {
                 // exportieren
                 return array($controller, 'create', array($body, $r->part()));
                 // nächste ist filename ohne endung
             }
         }
     } elseif ($controller === 'images') {
         $controller = new ImageController(ImageManager::createForProject($this->project, $this->getDoctrinePackage()->getEntityManager(), $this->getDoctrinePackage()->getModule()->getEntityName('Image')));
         if ($r->isEmpty() && $request->getType() === Service::POST && $request->hasFiles()) {
             // nimmt nur eine file, weil moep
             return array($controller, 'insertImageFile', array(current($request->getFiles()), $request->getBody()));
         } else {
             $method = 'getImage';
             $cacheAdapters = array('thumbnail');
             $params = array($r->qmatchiRX('/([a-z0-9]+)/'));
             // id or hash
             // filename immer am ende und optional
             $filename = NULL;
             if (\Psc\Preg::match($r->getLastPart(), '/[a-z0-9]+\\.[a-z0-9]+/i')) {
                 $filename = $r->pop();
             }
             /* gucken ob es eine Version des Images werden soll */
             if (in_array($r->part(), $cacheAdapters)) {
                 $method = 'getImageVersion';
                 $params[] = $r->matchNES();
                 // type
                 $params[] = $r->getLeftParts();
                 // parameter für den cache adapter
             }
             if ($filename) {
                 $params[] = $filename;
             }
             return array($controller, $method, $params);
         }
     } elseif ($controller === 'uploads') {
         $controller = new FileUploadController(UploadManager::createForProject($this->project, $this->dc));
         $this->log('upload-request method: ' . $request->getType());
         $this->log('  has files: ' . ($request->hasFiles() ? 'true' : 'false'), 1);
         if ($r->isEmpty() && $request->getType() === Service::POST && $request->hasFiles()) {
             // nimmt nur eine file, weil moep
             return array($controller, 'insertFile', array(current($request->getFiles()), $request->getBody()));
         } elseif ($r->isEmpty() && $request->getType() === Service::GET) {
             $params = array();
             // criterias
             $params[] = array();
             $params[] = $r->matchOrderBy($r->qVar('orderby'), array('name' => 'originalName'));
             return array($controller, 'getFiles', $params);
         } else {
             $method = 'getFile';
             $params = array($r->qmatchiRX('/([a-z0-9]+)/'));
             // id or hash
             // filename immer am ende und optional
             $filename = NULL;
             try {
                 if (\Psc\Preg::match($r->getLastPart(), '/^(.+)\\.(.+)$/')) {
                     $filename = $r->pop();
                 }
             } catch (\Webforge\Common\Exception $e) {
                 if (mb_strpos('.', $r->getLastPart()) !== FALSE) {
                     $filename = \Webforge\Common\System\File::safeName($r->pop());
                     $filename = Preg::replace($filename, '/_+/', '_');
                 }
             }
             if ($filename) {
                 $params[] = $filename;
             }
             return array($controller, $method, $params);
         }
     } elseif ($controller === 'persona') {
         $controller = new \Webforge\Persona\Controller();
         return array($controller, 'verify', array($r->bvar('assertion')));
     }
     throw HTTPException::NotFound('Die Resource für cms ' . $request . ' existiert nicht.');
 }
Esempio n. 5
0
 public function validateController($controller, $method, array $params)
 {
     if (!is_object($controller) || !method_exists($controller, $method)) {
         throw HTTPException::NotFound('Methode ' . Code::getClass($controller) . '::' . $method . ' ist nicht definiert');
     }
 }