Beispiel #1
0
 public function reference2()
 {
     // Берем файл
     $text = Core::getFile('data2.txt');
     // Массив ключей
     $request = array('get', 'post', 'url');
     //Массив на выходе
     $array = Preg::generateArray($request, $text);
     //Вывод массива
     Core::preArray($array);
 }
Beispiel #2
0
 /**
  * Required eine Variable, schlägt aber einen Default für die Config-Variable vor
  * 
  */
 public static function reqDefault($keys, $defaultValue)
 {
     try {
         $value = self::req($keys);
     } catch (MissingConfigVariableException $e) {
         if (is_string($defaultValue) && !Preg::match($defaultValue, '/^(\'|")/') && !self::NEW_ARRAY) {
             $defaultValue = "'" . $defaultValue . "'";
         }
         $e->setDefault($defaultValue);
         throw $e;
     }
     return $value;
 }
Beispiel #3
0
 /**
  * Gibt den (lcfirst) LowerCase Name für einen Klassennamen zurück
  *
  * OID => oid
  * OIDMeta => oidMeta
  * SomeClassName => someClassName
  * 
  * @param $className ohne Namespace
  */
 public function propertyName($className)
 {
     if (!is_string($className) || mb_strpos($className, '\\') !== FALSE) {
         throw new \InvalidArgumentException(sprintf("ClassName %s kann nicht zu propertyName umgewandelt werden. Er muss ein String sein und darf nur der ClassName sein", \Psc\Code\Code::varInfo($className)));
     }
     // 1. Fall: Klasse ist CamelCase. wichtig ist hierbei dass das erste a klein ist
     if (Preg::match($className, '/^[A-Z]{1}[a-z]{1}/') > 0) {
         return lcfirst($className);
     }
     // 2. Fall: Klassename ist eine Abkürzung. Z. B. OID (aka: der ganze String sind Großbuchstaben)
     if (Preg::match($className, '/^[A-Z]+$/')) {
         return mb_strtolower($className);
     }
     // 3. Fall: KlassenName ist mixed sowas wie OIDMeta
     // teile auf in m[1] = 'OID' m[2] = 'Meta'
     $m = array();
     if (Preg::match($className, '/^([A-Z]+)([A-Z]{1}[a-z]{1}.*)$/', $m) > 0) {
         return mb_strtolower($m[1]) . $m[2];
     }
     throw new \RuntimeException(sprintf("Kein matching Case für ClassName '%s'", $className));
 }
Beispiel #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.');
 }