/**
  * Erstellt eine neue Rule durch eine Spezifikation (was so quasi alles sein kann)
  *
  * Die Parameter dieser Funktion sind sehr Variabel
  * Möglicherweise ist es einfacher generate[A-Za-z+]Rule zu benutzen
  */
 public static function generateRule($ruleSpecification)
 {
     $rs = $ruleSpecification;
     if (is_string($rs)) {
         if ($rs == 'nes') {
             return new NesValidatorRule();
         }
         if ($rs == 'id') {
             return new IdValidatorRule();
         }
         if ($rs == 'pi' || $rs == 'pint') {
             return new PositiveIntValidatorRule();
         }
         if ($rs == 'array') {
             return new ArrayValidatorRule();
         }
         if ($rs == 'pi0' || $rs == 'pint0') {
             $rule = new PositiveIntValidatorRule();
             $rule->setZeroAllowed(TRUE);
             return $rule;
         }
         if (S::startsWith($rs, '/') && S::endsWith($rs, '/')) {
             return self::generateRegexpRule($rs);
         }
         $c = '\\' . __NAMESPACE__ . '\\' . ucfirst($rs) . 'ValidatorRule';
         if (class_exists($c)) {
             return new $c();
         }
         throw new \Psc\Exception('Unbekannte Parameter für generateRule ' . Code::varInfo($rs));
     }
     if (is_array($rs)) {
         $num = count($rs);
     }
     throw new \Psc\Exception('Unbekannte Parameter für generateRule ' . Code::varInfo($rs));
 }
Beispiel #2
0
 protected function expandSourceAndDestination($source, $destination = NULL)
 {
     if (is_string($source)) {
         $sourceUrl = $source;
         if (S::endsWith($source, '/')) {
             $source = $this->sourceProject->getRootDirectory()->sub($source);
         } else {
             $source = File::createFromURL($source, $this->sourceProject->getRootDirectory());
         }
     }
     if (!isset($destination)) {
         if (!isset($sourceUrl)) {
             $sourceUrl = $source->getUrl($this->sourceProject->getRootDirectory());
             if ($source instanceof Dir) {
                 $sourceUrl .= '/';
             }
         }
         $destination = $sourceUrl;
     }
     if (is_string($destination)) {
         if (S::endsWith($destination, '/')) {
             $destination = $this->targetProject->getRootDirectory()->sub($destination);
         } else {
             $destination = File::createFromURL($destination, $this->targetProject->getRootDirectory());
         }
     }
     return array($source, $destination);
 }
Beispiel #3
0
 protected function expandDestination($destination)
 {
     if (is_string($destination)) {
         if (S::endsWith($destination, '/')) {
             $destination = $this->targetProject->getRoot()->sub($destination);
         } else {
             $destination = Dir::createFromURL($destination, $this->targetProject->getRoot());
         }
     }
     return $destination;
 }
Beispiel #4
0
 /**
  *
  * @param File $out die Datei in die das phar geschrieben werden soll
  * @param Dir $classPath das Verzeichnis für die Dateien von $namespace z. B. Umsetzung\base\src\SerienLoader\
  * @param string $namespace der Name des Namespaces dessen Klassen in $classPath liegen z. B. SerienLoader
  */
 public function __construct(File $out, Dir $classPath, $namespace, $logger = NULL)
 {
     $this->out = $out;
     $this->namespace = $namespace;
     $this->classPath = $classPath;
     $this->logger = $logger;
     $this->logLevel = 2;
     if (\Webforge\Common\String::endsWith($this->namespace, '_')) {
         $this->underscoreStyle = TRUE;
     }
 }
Beispiel #5
0
 public function createRule($class, array $constructorParams = array())
 {
     if ($class instanceof ValidatorRule) {
         return $class;
     }
     if (!\Webforge\Common\String::endsWith($class, 'ValidatorRule')) {
         $class .= 'ValidatorRule';
     }
     $class = ClassUtil::expandNamespace($class, 'Psc\\Form');
     if (count($constructorParams) === 0) {
         return new $class();
     } else {
         return ClassUtil::newClassInstance($class, $constructorParams);
     }
 }
Beispiel #6
0
 public static function escapeArgument($argument, $commandQuotes = String::DOUBLE_QUOTE)
 {
     $otherQuote = $commandQuotes == String::DOUBLE_QUOTE ? String::SINGLE_QUOTE : String::DOUBLE_QUOTE;
     /* wenn das letzte zeichen von argument ein backslash ist würde dies das quoting escapen.
           also escapen wird den backslash indem wir einen weiteren backslash anfügen
        */
     if (String::endsWith($argument, String::BACKSLASH) && !String::endsWith(mb_substr($argument, 0, -1), String::BACKSLASH)) {
         $argument = $argument . String::BACKSLASH;
     }
     $argument = $otherQuote . addcslashes($argument, $otherQuote) . $otherQuote;
     return $argument;
 }
Beispiel #7
0
 /**
  * Bestimmt ob für eine Klasse des Projektes ein Test erstellt werden soll, wenn diese automatisch erstellt wird
  *
  * z. B. Exceptions haben erstmal keinen Test
  */
 public function shouldAutomaticTestCreated(GClass $class)
 {
     if (\Webforge\Common\String::endsWith($class->getName(), 'Exception')) {
         return FALSE;
     }
     /* more exceptions to come */
     return TRUE;
 }
Beispiel #8
0
 /**
  * 
  * @param string $source der PHP Code als String
  */
 protected function scan($source)
 {
     $source = str_replace(array("\r\n", "\r"), "\n", $source);
     if ($this->eol != "\n") {
         $source = str_replace("\n", $this->eol, $source);
     }
     /* token get all ist php intern */
     $currentLine = 1;
     foreach (token_get_all($source) as $token) {
         if (is_string($token)) {
             switch ($token) {
                 default:
                     $type = self::LITERAL;
                     break;
                 case ',':
                     $type = self::T_COMMA;
                     break;
                 case '.':
                     $type = self::T_DOT;
                     break;
                 case '{':
                     $type = self::T_CBRACE_OPEN;
                     break;
                 case '}':
                     $type = self::T_CBRACE_CLOSE;
                     break;
                 case '(':
                     $type = self::T_BRACE_OPEN;
                     break;
                 case ')':
                     $type = self::T_BRACE_CLOSE;
                     break;
                 case '=':
                     $type = self::T_EQUAL;
                     break;
                 case '&':
                     $type = self::T_AMPERSAND;
                     break;
                 case ';':
                     $type = self::T_SEMICOLON;
                     break;
                 case '+':
                     $type = self::T_PLUS;
                     break;
                 case '-':
                     $type = self::T_MINUS;
                     break;
             }
             $t = array('value' => $token, 'type' => $type, 'line' => $currentLine);
         } else {
             $t = array('value' => $token[1], 'type' => token_name($token[0]), 'line' => $token[2]);
             /* fix */
             if ($t['type'] == 'T_DOUBLE_COLON') {
                 $t['type'] = 'T_PAAMAYIM_NEKUDOTAYIM';
             }
             $currentLine = $t['line'];
         }
         /* whitespace analyisieren */
         if ($t['type'] == 'T_WHITESPACE' && $this->parseWhitespace) {
             Preg::match($t['value'], '/([^\\n]+|\\n)/g', $matches);
             foreach ($matches as $m) {
                 // das geht kaputt mit $this->eol anders als "\n"
                 list($NULL, $white) = $m;
                 if ($white === "\n") {
                     $currentLine++;
                     $type = self::T_EOL;
                 } else {
                     $type = self::T_PLAIN_WHITESPACE;
                 }
                 $this->tokens[] = array('value' => $white, 'type' => $type, 'line' => $currentLine);
             }
         } elseif ($t['type'] == 'T_COMMENT' && $this->parseWhitespace) {
             // EOL abschneiden und als einzelnes T_EOL dahinter machen
             if (S::endsWith($t['value'], $this->eol)) {
                 $t['value'] = mb_substr($t['value'], 0, -1);
                 $this->tokens[] = $t;
                 // comment hinzufügen
                 $currentLine++;
                 $this->tokens[] = array('value' => "\n", 'type' => self::T_EOL, 'line' => $currentLine);
             } else {
                 $this->tokens[] = $t;
                 // comment hinzufügen, auch wenn er kein EOL hata
             }
         } else {
             if (trim($t['value']) == '' && mb_strpos($t['value'], $this->eol) !== FALSE) {
                 // leer und mit umbruch
                 $currentLine += mb_substr_count($t['value'], $this->eol);
             }
             $this->tokens[] = $t;
         }
     }
     return $this;
 }