/** * 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; }
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"); } }; }
public function containsRegExp($regExp) { Assertion::string($regExp); Assertion::minLength($regExp, 1); $guard = RegexGuardFactory::getGuard(); return !!$guard->match($regExp, $this->logMessage); }
/** * @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); } } } }
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; }
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); } }
/** * @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); }