Set key pattern

@param  null|string $keyPattern
@throws Exception\InvalidArgumentException
@return AdapterOptions
1966
public function setKeyPattern($keyPattern)
    {
        $keyPattern = (string)$keyPattern;
        if ($this->keyPattern !== $keyPattern) {
            // validate pattern
            if ($keyPattern !== '') {
                ErrorHandler::start(E_WARNING);
                $result = preg_match($keyPattern, '');
                $error  = ErrorHandler::stop();
                if ($result === false) {
                    throw new Exception\InvalidArgumentException(
                        sprintf(
                            'Invalid pattern "%s"%s',
                            $keyPattern,
                            ($error ? ': ' . $error->getMessage() : '')
                        ),
                        0,
                        $error
                    );
                }
            }

            $this->keyPattern = $keyPattern;
        }

        return $this;
    }
1277652
public function setPattern($pattern)
    {
        if (gettype($pattern) === 'string') {
            $this->pattern = $pattern;
        } else {
            $msg = "The pattern argument must be a string or a variable reference, '" . $pattern . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
295198
public function set($key, $value)
    {
        if (! is_scalar($key)) {
            throw InvalidArgumentException('Invalid key type');
        }
        $this->items[$this->normalizeKey($key)] = $value;
    }
428829
public function setPattern(
        $prefix    = FilesystemContract::PATTERN_PREFIX,
        $date      = FilesystemContract::PATTERN_DATE,
        $extension = FilesystemContract::PATTERN_EXTENSION
    ) {
        $this->filesystem->setPattern($prefix, $date, $extension);

        return $this;
    }
904657
private function createRegex($eventPattern)
    {
        $replacements = self::getReplacements();

        return sprintf('/^%s$/', preg_replace(
            array_keys($replacements),
            array_values($replacements),
            preg_quote($eventPattern, '/')
        ));
    }
1018146
protected static function transform(Pattern $pattern) {
        $result = [];
        $groups = [[$pattern]];

        while ($groups) {
            $children = array_shift($groups);
            $hasBranchPattern = false;
            foreach ($children as $c) {
                if ($c instanceof BranchPattern) {
                    $hasBranchPattern = true;
                    break;
                }
            }
            if ($hasBranchPattern) {
                /** @var BranchPattern $child */
                $child = null;
                foreach ($children as $key => $currentChild) {
                    if ($currentChild instanceof BranchPattern) {
                        $child = $currentChild;
                        unset($children[$key]);
                        break;
                    }
                }
                if ($child instanceof Either) {
                    foreach ($child->children as $c) {
                        $groups[] = array_merge([$c], $children);
                    }
                }
                else if ($child instanceof OneOrMore) {
                    $groups[] = array_merge($child->children, $child->children, $children);
                }
                else {
                    $groups[] = array_merge($child->children, $children);
                }
            }
            else {
                $result[] = $children;
            }
        }

        $rs = [];
        foreach ($result as $e) {
            $rs[] = new Required($e);
        }
        return new Either($rs);
    }
562256
public function regex($key, $pattern, $message = null)
    {
        if (is_array($key)) {
            foreach ($key as $k => $name) {
                $this->regex($name, is_array($pattern) ? $pattern[$k] : $pattern, $message);
            }
        } else {
            if (isset($this->scope[$key]) && ! (bool)preg_match($pattern, $this->scope[$key])) {
                $this->errors[$key] = sprintf($message !== null ? $message : self::$regexMessage, $key);
            }
        }

        return $this;
    }
159022
public function setPatterns(array $patterns)
    {
        $patternValues = implode("", $patterns);
        if (mb_strlen($patternValues) < strlen($patternValues)) {
            $this->options['multibytePattern'] = true;
        }
        $this->options = array_merge($this->options, $patterns);

        return $this;
    }
75129
public function visitPatternConstraint(StringValue\PatternConstraint $constraint)
    {
        $value = $this->currentValue();
        if (
            !$value instanceof Value\StringValue ||
            preg_match(
                $this->wrapPattern($constraint->pattern()),
                $value->value()
            )
        ) {
            return $this->createResult();
        }

        return $this->createSingleIssueResult($constraint);
    }
597424
public function set($key, $value)
    {
        switch ($key) {
            case 'validator':
                $this->validators[] = $value;
                break;

            case 'normalizer':
                $this->normalizers[] = $value;
                break;

            default:
                if (!property_exists($this, $key)) {
                    throw new \InvalidArgumentException("Unrecognized config key: $key");
                }
                $this->$key = $value;
        }

        return $this;
    }
73993
public function setPatterns($patterns)
    {
        foreach ($patterns as $name => $pattern) {
            $this->setPattern($name, $pattern);
        }

        return $this;
    }
1016988
public function pattern($pattern, $attr = null)
    {
        if (is_array($pattern)) {
            foreach ($pattern as $key => $value) {
                if (! in_array('{' . $key . '}', array_keys($this->patterns))) {
                    $this->patterns['{' . $key . '}'] = '(' . $value . ')';
                } else {
                    return $this->exception($key . ' pattern cannot be changed.');
                }
            }
        } else {
            if (! in_array('{' . $pattern . '}', array_keys($this->patterns))) {
                $this->patterns['{' . $pattern . '}'] = '(' . $attr . ')';
            } else {
                return $this->exception($pattern . ' pattern cannot be changed.');
            }
        }

        return true;
    }
752278
public function setAdapter($adapter)
    {
        if (!is_string($adapter) && !$adapter instanceof ConversionAlgorithmInterface) {
            throw new Exception\InvalidArgumentException(sprintf(
                '"%s" expects a string or an instance of ConversionAlgorithmInterface; received "%s"',
                __METHOD__,
                is_object($adapter) ? get_class($adapter) : gettype($adapter)
            ));
        }
        if (is_string($adapter)) {
            if (!class_exists($adapter)) {
                throw new Exception\RuntimeException(sprintf(
                    '"%s" unable to load adapter; class "%s" not found',
                    __METHOD__,
                    $adapter
                ));
            }
            $adapter = new $adapter();
            if (!$adapter instanceof ConversionAlgorithmInterface) {
                throw new Exception\InvalidArgumentException(sprintf(
                    '"%s" expects a string representing an instance of ConversionAlgorithmInterface; received "%s"',
                    __METHOD__,
                    is_object($adapter) ? get_class($adapter) : gettype($adapter)
                ));
            }
        }
        $this->adapter = $adapter;

        return $this;
    }
519865
public function setPattern($pattern)
    {
        $pattern = $this->validator->validate($pattern);

        $this->parts = $this->parsePattern($pattern);
        $this->pattern = $pattern;
    }
54205
protected function withPattern($patternName) {
        if(!isset($this->patterns[$patternName])) {
            throw (new \Exception('Could not set pattern '.$patternName.': pattern not found'));
        }
        $this->activePattern = $patternName;
        return $this;
    }
870302
private function addListenerServicePattern($eventPattern, $callback, $priority = 0)
    {
        if (!is_array($callback) || 2 !== count($callback)) {
            throw new \InvalidArgumentException('Expected an array("service", "method") argument');
        }

        $container = $this->container;
        $listenerProvider = function() use ($container, $callback) {
            return array($container->get($callback[0]), $callback[1]);
        };

        $this->addListenerPattern(new LazyListenerPattern($eventPattern, $listenerProvider, $priority));
    }
985914
public function aliasPattern($pattern, $translation = null)
	{
		if ( ! is_array($pattern))
		{
			$pattern = [$pattern => $translation];
		}

		foreach ($pattern as $patternKey => $resolver)
		{
			if ( ! $resolver instanceof Resolver)
			{
				$resolver = new Resolver($patternKey, $resolver);
			}

			$this->patterns[$patternKey] = $resolver;
		}
	}