Example #1
0
 /**
  * @return IPresenter
  */
 public function factory()
 {
     $modulePath = [];
     foreach ($this->request->getModulePath() as $module) {
         $modulePath[] = StringUtils::camelize($module) . 'Module';
     }
     return $this->context->create(sprintf('%s\\%sPresenter', implode('\\', $modulePath), StringUtils::camelize($this->request->getPresenter())));
 }
Example #2
0
 /**
  * @return string
  */
 public function getArgument()
 {
     if (!$this->text) {
         return null;
     }
     $text = StringUtils::split($this->text, '~\\s~');
     return reset($text);
 }
 /**
  * @param string $source
  *
  * @return IAnnotationReflection
  */
 public static function build($source)
 {
     $annotationReflection = new self($source);
     foreach (StringUtils::split($source, '~\\n~s') as $line) {
         if (($annotation = StringUtils::match($line, '~@(?<annotation>[a-zA-Z0-9_-]+)(\\s+(?<text>.*))?~')) === null) {
             continue;
         }
         $annotationReflection->addAnnotation(new Annotation($annotation['annotation'], isset($annotation['text']) ? $annotation['text'] : null));
     }
     return $annotationReflection;
 }
 protected function build()
 {
     if ($this->built === true) {
         return;
     }
     $this->built = true;
     $reflectionClass = new \ReflectionClass($this);
     foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
         if (strpos($methodName = $reflectionMethod->getName(), self::HANDLER_PICCO) !== false && strlen($methodName) > strlen(self::HANDLER_PICCO)) {
             $this->piccoList[StringUtils::recamel(ltrim($methodName, self::HANDLER_PICCO))] = [$this, $methodName];
         }
         if (strpos($methodName = $reflectionMethod->getName(), self::HANDLER_RENDERER) !== false && strlen($methodName) > strlen(self::HANDLER_RENDERER)) {
             $this->rendererList[StringUtils::recamel(ltrim($methodName, self::HANDLER_RENDERER))] = [$this, $methodName];
         }
     }
 }
 public function run()
 {
     $reflectionClass = new \ReflectionClass($this);
     if ($reflectionClass->hasMethod($method = 'action' . StringUtils::camelize($this->request->getAction()))) {
         $parameterList = $this->request->getParameterList();
         $methodReflection = $reflectionClass->getMethod($method);
         $argumentList = [];
         foreach ($methodReflection->getParameters() as $parameterRefleciton) {
             if (!isset($parameterList[$parameterRefleciton->getName()])) {
                 if ($parameterRefleciton->isOptional()) {
                     continue;
                 }
                 throw new \Exception('not implemented yet: define invalid request exception');
             }
             $argumentList[] = $parameterList[$parameterRefleciton->getName()];
         }
         $methodReflection->invokeArgs($this, $argumentList);
     }
 }
 public function input($value)
 {
     return StringUtils::webalize($value, $this->getOption('charlist'), (bool) $this->getOption('lower', true));
 }
 public function isValid($value)
 {
     return StringUtils::match($value, '/(?=^.{1,254}$)(^(?:(?!\\d+\\.|-)[a-zA-Z0-9_\\-]{1,63}(?<!-)\\.)+(?:[a-zA-Z]{2,})$)/') !== null;
 }
 public function isValid($value)
 {
     return StringUtils::match($value, '~^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\\.[a-zA-Z]{2,3})$~') !== null;
 }
Example #9
0
 public function getIterator()
 {
     return StringUtils::createIterator($this->get());
 }
Example #10
0
 public function read(IResource $resource, $handler)
 {
     $value = null;
     $this->eventBus = new EventBus();
     $this->eventBus->register($handler);
     foreach ($resource as $chunk) {
         foreach ($iterator = StringUtils::createIterator($chunk) as $char) {
             switch ($char) {
                 case '<':
                     if ($value !== null) {
                         $this->eventBus->emit(new TextEvent($value));
                     }
                     $this->parseTag($iterator->setContinue());
                     $value = null;
                     break;
                 default:
                     $value .= $char;
             }
         }
     }
     return $this;
 }
Example #11
0
 public function index()
 {
     /**
      * because we can run withou caching, this flag is needed
      */
     if ($this->built === true) {
         return $this;
     }
     /**
      * intentionally first line - built is done even if failature occures
      */
     $this->built = true;
     if ($this->cache->load('index') === true) {
         return $this;
     }
     $exclude = '~(' . implode(')|(', $this->excludeList) . ')~';
     $this->storage->truncate($schema = $this->createScannerFile()->schema());
     $this->storage->createSchema($schema);
     $this->storage->startTransaction(self::class);
     try {
         foreach ($this->pathList as $directory) {
             foreach ($this->createIterator($directory) as $path => $item) {
                 /**
                  * nice line, isn't it ;)?
                  */
                 if (!empty($this->excludeList) && StringUtils::match(($tmp = realpath($path)) ? $path = $tmp : $path, $exclude)) {
                     continue;
                 }
                 $finfo = new \finfo(FILEINFO_MIME);
                 $scannerFile = $this->createScannerFile();
                 $scannerFile->restore(['file' => FileUtils::normalize($item->getRealPath()), 'extension' => ($extension = $item->getExtension()) ? $extension : null, 'mime' => $finfo->file($path), 'size' => (int) $item->getSize(), 'stamp' => DateTimeUtils::create(), 'changed' => DateTimeUtils::from($item->getMTime())]);
                 $this->storage->save($scannerFile);
             }
         }
         $this->storage->commitTransaction(self::class);
         $this->cache->save('index', true);
     } catch (\Exception $e) {
         $this->storage->rollbackTransaction(self::class);
         throw $e;
     }
     return $this;
 }
 /**
  * vrátí true/false, pokud je hodnota validní/nevalidní; slouží pro "měkké" ověření hodnoty
  *
  * @param mixed $value
  *
  * @return bool
  */
 public function isValid($value)
 {
     return StringUtils::match($value, $this->getOption('regexp')) !== null;
 }
 public function validate($value)
 {
     if ($value === null && !$this->isRequired()) {
         return;
     }
     if (!$this->isValid($value)) {
         $exception = $this->getException();
         throw new $exception(str_replace(['{rule}', '{value}'], [$this->getRuleName(), StringUtils::toString($value)], $this->getMessage()));
     }
 }
Example #14
0
 public static function getCurrent()
 {
     $url = new Url();
     $url->setScheme(!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https' : 'http');
     $url->setUser(isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null);
     $url->setPassword(isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null);
     if ((isset($_SERVER[$hostname = 'HTTP_HOST']) || isset($_SERVER[$hostname = 'SERVER_NAME'])) && preg_match('#^([a-z0-9_.-]+|\\[[a-f0-9:]+\\])(:\\d+)?\\z#i', $_SERVER[$hostname], $pair)) {
         $url->setHost(strtolower($pair[1]));
         if (isset($pair[2])) {
             $url->setPort(substr($pair[2], 1));
         } else {
             if (isset($_SERVER['SERVER_PORT'])) {
                 $url->setPort($_SERVER['SERVER_PORT']);
             }
         }
     }
     $requestUrl = StringUtils::replace(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/', ['~[.,)]\\z~' => '']);
     $tmp = explode('?', $requestUrl, 2);
     $path = Url::unescape($tmp[0], '%/?#');
     $url->setPath($path);
     $url->setQuery(isset($tmp[1]) ? $tmp[1] : null);
     $lpath = strtolower($path);
     $script = isset($_SERVER['SCRIPT_NAME']) ? strtolower($_SERVER['SCRIPT_NAME']) : null;
     if ($lpath !== $script) {
         $max = min(strlen($lpath), strlen($script));
         for ($i = 0; $i < $max && $lpath[$i] === $script[$i]; $i++) {
             /** no-op */
         }
         $path = $i ? substr($path, 0, strrpos($path, '/', $i - strlen($path) - 1) + 1) : '/';
     }
     $url->setScriptPath($path);
     $query = $url->getQueryParameters();
     $blacklist = '\\x09\\x0A\\x0D\\x20-\\x7E\\xA0-\\x{10FFFF}';
     $chars = '~^[' . $blacklist . ']*+\\z~u';
     $list = [&$query];
     while (list($key, $source) = each($list)) {
         foreach ($source as $k => $v) {
             if (is_string($k) && (!preg_match($chars, $k) || preg_last_error())) {
                 unset($list[$key][$k]);
             } else {
                 if (is_array($v)) {
                     $list[$key][$k] = $v;
                     $list[] =& $list[$key][$k];
                 } else {
                     $list[$key][$k] = (string) preg_replace('~[^' . $blacklist . ']+~u', '', $v);
                 }
             }
         }
     }
     unset($list, $key, $source, $k, $v);
     $url->setQuery($query);
     return $url;
 }