コード例 #1
0
ファイル: Regex.php プロジェクト: jaeger-app/regex
 /**
  * Returns an instance of the library
  * 
  * @return \RegexGuard\RegexGuard
  */
 private function getInstance()
 {
     if (is_null($this->instance)) {
         $this->instance = \RegexGuard\Factory::getGuard();
     }
     return $this->instance;
 }
コード例 #2
0
ファイル: Epilog.php プロジェクト: ovr/epilog
 public function __construct(Response $args)
 {
     $this->args = $args;
     $args['--sleep-interval'] = (double) $args['--sleep-interval'];
     $this->ticker = new Ticker();
     $this->printer = $this->loadPrinter();
     $this->regexGuard = RegexGuard::getGuard();
     $this->commands[''] = function () {
     };
     $this->commands['q'] = $this->commands[false] = [$this, 'quit'];
     $this->commands['r'] = [$this, 'loadRandomTheme'];
     $this->commands['c'] = [$this, 'clear'];
     $this->commands['i'] = [$this, 'invertTheme'];
     $this->commands['-'] = [$this, 'clearFilter'];
     $this->commands['default'] = function ($command) {
         if ($this->regexGuard->isRegexValid($command)) {
             $this->args['--filter'] = $command;
         } elseif (isset(self::$themes[$command])) {
             $this->args['--theme'] = self::$themes[$command];
             $this->printer = $this->loadPrinter();
         } else {
             $this->output(" Invalid option \"{$command}\" given.\n");
         }
     };
 }
コード例 #3
0
 public function containsRegExp($regExp)
 {
     Assertion::string($regExp);
     Assertion::minLength($regExp, 1);
     $guard = RegexGuardFactory::getGuard();
     return !!$guard->match($regExp, $this->logMessage);
 }
コード例 #4
0
ファイル: RegularExpressions.php プロジェクト: ovr/phpsa
 /**
  * @param FuncCall $funcCall
  * @param Context $context
  * @return mixed
  */
 public function pass(FuncCall $funcCall, Context $context)
 {
     $functionName = $this->resolveFunctionName($funcCall, $context);
     if ($functionName && isset(self::$map[$functionName])) {
         $pattern = $context->getExpressionCompiler()->compile($funcCall->args[0]);
         if ($pattern->isString() && $pattern->isCorrectValue()) {
             $guard = \RegexGuard\Factory::getGuard();
             if (!$guard->isRegexValid($pattern->getValue())) {
                 $context->notice('regex.invalid', sprintf('Regular expression %s is not valid', $pattern->getValue()), $funcCall->args[0], Check::CHECK_ALPHA);
             }
         }
     }
 }
コード例 #5
0
 public function handle(Request $request)
 {
     foreach ($this->handlers as $handler) {
         if ($this->isAdminCommand() && !$request->isAdmin()) {
             continue;
         }
         $type = $handler['type'];
         if ($type === 'responds' && !$request->isBotMention()) {
             continue;
         }
         $pattern = $handler['pattern'];
         $callback = $handler['callback'];
         $content = $request->getContent($type === 'responds');
         $regex = Factory::getGuard();
         $matched = $regex->match($pattern, $content, $matches);
         if (!$matched) {
             continue;
         }
         if ($callback($request, $matches) !== false) {
             return true;
         }
     }
     return false;
 }
コード例 #6
0
 private function validate()
 {
     Assertion::nullOrString($this->logMessageRegExp);
     Assertion::nullOrString($this->logMessageInString);
     Assertion::nullOrString($this->logContextFuzzy);
     Assertion::nullOrIsInstanceOf($this->logTimeLowerBounds, DateTimeInterface::class);
     Assertion::nullOrIsInstanceOf($this->logTimeUpperBounds, DateTimeInterface::class);
     Assertion::nullOrIsArray($this->logLevelList);
     if (!is_null($this->logLevelList)) {
         Assertion::notEmpty($this->logLevelList);
         Assertion::allInArray($this->logLevelList, array_values((new ReflectionClass(LogLevel::class))->getConstants()));
     }
     if (!is_null($this->logMessageRegExp)) {
         Assertion::true(RegexGuardFactory::getGuard()->isRegexValid($this->logMessageRegExp));
     }
     if (!is_null($this->logTimeLowerBounds) && !is_null($this->logTimeUpperBounds)) {
         Assertion::false($this->logTimeLowerBounds->diff($this->logTimeUpperBounds)->invert);
     }
 }
コード例 #7
0
 /**
  * @param string                $pattern
  * @param RegexRuntimeInterface $regexGuard
  */
 public function __construct($pattern, RegexRuntimeInterface $regexGuard = null)
 {
     $this->pattern = $pattern;
     $this->regexGuard = $regexGuard ?: Factory::getGuard();
     $this->validateRegex($this->pattern);
 }