/** * {@inheritdoc} */ public static function create($body, TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, TypeContext $context = null) { Assert::stringNotEmpty($body); Assert::allNotNull([$typeResolver, $descriptionFactory]); $parts = preg_split('/(\\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); $type = null; $variableName = ''; $isVariadic = false; // if the first item that is encountered is not a variable; it is a type if (isset($parts[0]) && strlen($parts[0]) > 0 && $parts[0][0] !== '$') { $type = $typeResolver->resolve(array_shift($parts), $context); array_shift($parts); } // if the next item starts with a $ or ...$ it must be the variable name if (isset($parts[0]) && strlen($parts[0]) > 0 && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')) { $variableName = array_shift($parts); array_shift($parts); if (substr($variableName, 0, 3) === '...') { $isVariadic = true; $variableName = substr($variableName, 3); } if (substr($variableName, 0, 1) === '$') { $variableName = substr($variableName, 1); } } $description = $descriptionFactory->create(implode('', $parts), $context); return new static($variableName, $type, $isVariadic, $description); }
/** * {@inheritdoc} */ public static function create($body, TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, Context $context = null) { Assert::stringNotEmpty($body); Assert::allNotNull([$typeResolver, $descriptionFactory]); // 1. none or more whitespace // 2. optionally the keyword "static" followed by whitespace // 3. optionally a word with underscores followed by whitespace : as // type for the return value // 4. then optionally a word with underscores followed by () and // whitespace : as method name as used by phpDocumentor // 5. then a word with underscores, followed by ( and any character // until a ) and whitespace : as method name with signature // 6. any remaining text : as description if (!preg_match('/^ # Static keyword # Declares a static method ONLY if type is also present (?: (static) \\s+ )? # Return type (?: ([\\w\\|_\\\\]+) \\s+ )? # Legacy method name (not captured) (?: [\\w_]+\\(\\)\\s+ )? # Method name ([\\w\\|_\\\\]+) # Arguments \\(([^\\)]*)\\) \\s* # Description (.*) $/sux', $body, $matches)) { return null; } list(, $static, $returnType, $methodName, $arguments, $description) = $matches; $static = $static === 'static'; $returnType = $typeResolver->resolve($returnType, $context); $description = $descriptionFactory->create($description, $context); $arguments = explode(',', $arguments); foreach ($arguments as &$argument) { $argument = explode(' ', trim($argument)); if ($argument[0][0] === '$') { $argumentName = substr($argument[0], 1); $argumentType = new Void(); } else { $argumentType = $typeResolver->resolve($argument[0], $context); $argumentName = ''; if (isset($argument[1])) { $argumentName = substr($argument[1], 1); } } $argument = ['name' => $argumentName, 'type' => $argumentType]; } return new static($methodName, $arguments, $returnType, $static, $description); }
/** * {@inheritdoc} */ public function undefineType($typeName) { Assert::stringNotEmpty($typeName, 'The type name must be a non-empty string. Got: %s'); $this->removeBindingsByType($typeName); unset($this->types[$typeName]); unset($this->typeIndex[$typeName]); }
/** * Creates a new tag that represents any unknown tag type. * * @param string $body * @param string $name * @param DescriptionFactory $descriptionFactory * @param Context $context * * @return static */ public static function create($body, $name = '', DescriptionFactory $descriptionFactory = null, Context $context = null) { Assert::string($body); Assert::stringNotEmpty($name); $description = $descriptionFactory && $body ? $descriptionFactory->create($body, $context) : null; return new static($name, $description); }
/** * Creates a new version list. * * @param string $path The Puli path. * @param PuliResource[] $versions The versions of the resource, starting * with the first. */ public function __construct($path, array $versions) { Assert::stringNotEmpty($path, 'The Puli path must be a non-empty string. Got: %s'); Assert::allIsInstanceOf($versions, 'Puli\\Repository\\Api\\Resource\\PuliResource'); Assert::greaterThanEq(count($versions), 1, 'Expected at least one version.'); $this->path = $path; $this->versions = array_values($versions); }
/** * Creates a new binding. * * You can pass parameters that have been defined for the type. If you pass * unknown parameters, or if a required parameter is missing, an exception * is thrown. * * All parameters that you do not set here will receive the default values * set for the parameter. * * @param string $typeName The name of the type to bind against. * @param array $parameterValues The values of the parameters defined * for the type. * * @throws NoSuchParameterException If an invalid parameter was passed. * @throws MissingParameterException If a required parameter was not passed. */ public function __construct($typeName, array $parameterValues = array()) { Assert::stringNotEmpty($typeName, 'The type name must be a non-empty string. Got: %s'); ksort($parameterValues); $this->typeName = $typeName; $this->userParameterValues = $parameterValues; $this->parameterValues = $parameterValues; }
/** * Creates a new return value. * * @param string $value The value as source code. * @param string $type The type shown in the doc block. * @param string $description The doc block description. */ public function __construct($value, $type = 'mixed', $description = null) { Assert::stringNotEmpty($value, 'The return value must be a non-empty string. Got: %s'); Assert::stringNotEmpty($type, 'The return value type must be a non-empty string. Got: %s'); Assert::nullOrStringNotEmpty($description, 'The return value description must be a non-empty string or null. Got: %s'); $this->value = $value; $this->type = $type; $this->description = $description; }
/** * Return the path with the basePath prefix * if it has been set. * * @param string $path * * @return string */ protected function resolvePath($path) { Assert::stringNotEmpty($path, 'The path must be a non-empty string. Got: %s'); Assert::startsWith($path, '/', 'The path %s is not absolute.'); if ($this->basePath) { $path = $this->basePath . $path; } $path = Path::canonicalize($path); return $path; }
/** * Creates the violation. * * @param int $code The violation code. One of the constants * defined in this class. * @param mixed $invalidValue The value that caused this violation. * @param string $installerName The name of the validated installer. * @param string|null $parameterName The name of the validated installer * parameter or `null` if this is a generic * error. */ public function __construct($code, $invalidValue, $installerName, $parameterName = null) { Assert::oneOf($code, self::$codes, 'The violation code %s is not valid.'); Assert::stringNotEmpty($installerName, 'The installer name must be a non-empty string. Got: %s'); Assert::nullOrStringNotEmpty($parameterName, 'The parameter name must be a non-empty string or null. Got: %s'); $this->code = $code; $this->installerName = $installerName; $this->parameterName = $parameterName; $this->invalidValue = $invalidValue; }
/** * Creates a new package DTO. * * @param string $name The package name. * @param string $installerName The name of the installer. * @param string $installPath The absolute install path. * @param string $state One of the STATE_* constants in this class. */ public function __construct($name, $installerName, $installPath, $state) { Assert::stringNotEmpty($name, 'The package name must be a non-empty string. Got: %s'); Assert::string($installerName, 'The installer name must be a string. Got: %s'); Assert::stringNotEmpty($installPath, 'The install path must be a non-empty string. Got: %s'); Assert::oneOf($state, self::$states, 'The package state must be one of %2$s. Got: %s'); $this->name = $name; $this->installerName = $installerName; $this->installPath = $installPath; $this->state = $state; }
/** * @param Key $source * @param string $key * @param int $bits * @param int $type * @param array $details */ public function __construct(Key $source, $key, $bits, $type, array $details = []) { Assert::stringNotEmpty($key, __CLASS__ . '::$key expected a non empty string. Got: %s'); Assert::integer($bits, __CLASS__ . '::$bits expected an integer. Got: %s'); Assert::oneOf($type, [OPENSSL_KEYTYPE_RSA, OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH, OPENSSL_KEYTYPE_EC], __CLASS__ . '::$type expected one of: %2$s. Got: %s'); $this->source = $source; $this->key = $key; $this->bits = $bits; $this->type = $type; $this->details = $details; }
/** * Creates a new parameter. * * @param string $name The parameter name. * @param int $flags A bitwise combination of the flag constants * in this class. * @param mixed $defaultValue The parameter's default value. */ public function __construct($name, $flags = self::OPTIONAL, $defaultValue = null) { Assert::stringNotEmpty($name, 'The parameter name must be a non-empty string. Got: %s'); Assert::startsWithLetter($name, 'The parameter name must start with a letter. Got: %s'); Assert::nullOrInteger($flags, 'The parameter "$flags" must be an integer or null. Got: %s'); if ($flags & self::REQUIRED && null !== $defaultValue) { throw new RuntimeException('Required parameters must not have default values.'); } $this->name = $name; $this->flags = $flags; $this->defaultValue = $defaultValue; }
/** * Creates a new type. * * @param string $name The name of the type. * @param BindingParameter[] $parameters The parameters that can be set * during binding. */ public function __construct($name, array $parameters = array()) { Assert::stringNotEmpty($name, 'The type name must be a non-empty string. Got: %s'); Assert::startsWithLetter($name, 'The type name must start with a letter. Got: %s'); Assert::allIsInstanceOf($parameters, 'Puli\\Discovery\\Api\\Binding\\BindingParameter'); $this->name = $name; foreach ($parameters as $parameter) { $this->parameters[$parameter->getName()] = $parameter; } // Sort to facilitate comparison ksort($this->parameters); }
/** * @param string $domain * @param string $type * @param string $url * @param string $token * @param string $payload */ public function __construct($domain, $type, $url, $token, $payload) { Assert::stringNotEmpty($domain, 'Challenge::$domain expected a non-empty string. Got: %s'); Assert::stringNotEmpty($type, 'Challenge::$type expected a non-empty string. Got: %s'); Assert::stringNotEmpty($url, 'Challenge::$url expected a non-empty string. Got: %s'); Assert::stringNotEmpty($token, 'Challenge::$token expected a non-empty string. Got: %s'); Assert::stringNotEmpty($payload, 'Challenge::$payload expected a non-empty string. Got: %s'); $this->domain = $domain; $this->type = $type; $this->url = $url; $this->token = $token; $this->payload = $payload; }
/** * Creates a new type. * * @param string $name The name of the type. * @param string $bindingClass The class name of the accepted * bindings. * @param BindingParameter[] $parameters The parameters that can be set * for a binding. */ public function __construct($name, $bindingClass, array $parameters = array()) { Assert::stringNotEmpty($name, 'The type name must be a non-empty string. Got: %s'); Assert::allIsInstanceOf($parameters, 'Puli\\Discovery\\Api\\Type\\BindingParameter'); if (!class_exists($bindingClass) && !interface_exists($bindingClass)) { throw new InvalidArgumentException(sprintf('The binding class "%s" is neither a class nor an ' . 'interface name. Is there a typo?', $bindingClass)); } $this->name = $name; $this->acceptedBindingClass = $bindingClass; foreach ($parameters as $parameter) { $this->parameters[$parameter->getName()] = $parameter; } // Sort to facilitate comparison ksort($this->parameters); }
/** * Request and check a domain. * * @param string $domain * * @throws \Exception */ public function challengeDomain($domain) { Assert::stringNotEmpty($domain, 'challengeDomain::$domain expected a non-empty string. Got: %s'); $challenge = $this->client->requestChallenge($domain); $challengeEvent = new ChallengeEvent($challenge); $this->dispatcher->dispatch(AcmePhpBundleEvents::CHALLENGE_REQUESTED, $challengeEvent); try { $this->client->checkChallenge($challenge); $this->dispatcher->dispatch(AcmePhpBundleEvents::CHALLENGE_ACCEPTED, $challengeEvent); } catch (\Exception $e) { $this->dispatcher->dispatch(AcmePhpBundleEvents::CHALLENGE_REJECTED, $challengeEvent); throw $e; } finally { $this->dispatcher->dispatch(AcmePhpBundleEvents::CHALLENGE_CHECKED, $challengeEvent); } }
/** * @param Certificate $source * @param string $subject * @param string $issuer * @param bool $selfSigned * @param \DateTime $validFrom * @param \DateTime $validTo * @param string $serialNumber * @param array $subjectAlternativeNames */ public function __construct(Certificate $source, $subject, $issuer = null, $selfSigned = true, \DateTime $validFrom = null, \DateTime $validTo = null, $serialNumber = null, array $subjectAlternativeNames = []) { Assert::stringNotEmpty($subject, __CLASS__ . '::$subject expected a non empty string. Got: %s'); Assert::nullOrString($issuer, __CLASS__ . '::$issuer expected a string or null. Got: %s'); Assert::nullOrBoolean($selfSigned, __CLASS__ . '::$selfSigned expected a boolean or null. Got: %s'); Assert::nullOrString($serialNumber, __CLASS__ . '::$serialNumber expected a string or null. Got: %s'); Assert::allStringNotEmpty($subjectAlternativeNames, __CLASS__ . '::$subjectAlternativeNames expected a array of non empty string. Got: %s'); $this->source = $source; $this->subject = $subject; $this->issuer = $issuer; $this->selfSigned = $selfSigned; $this->validFrom = $validFrom; $this->validTo = $validTo; $this->serialNumber = $serialNumber; $this->subjectAlternativeNames = $subjectAlternativeNames; }
/** * @param object|string $docblock A string containing the DocBlock to parse or an object supporting the * getDocComment method (such as a ReflectionClass object). * @param Types\Context $context * @param Location $location * * @return DocBlock */ public function create($docblock, Types\Context $context = null, Location $location = null) { if (is_object($docblock)) { if (!method_exists($docblock, 'getDocComment')) { $exceptionMessage = 'Invalid object passed; the given object must support the getDocComment method'; throw new \InvalidArgumentException($exceptionMessage); } $docblock = $docblock->getDocComment(); } Assert::stringNotEmpty($docblock); if ($context === null) { $context = new Context(''); } $parts = $this->splitDocBlock($this->stripDocComment($docblock)); list($templateMarker, $summary, $description, $tags) = $parts; return new DocBlock($summary, $description ? $this->descriptionFactory->create($description, $context) : null, $this->parseTagBlock($tags), $context, $location, $templateMarker === '#@+', $templateMarker === '#@-'); }
/** * {@inheritdoc} */ public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null) { Assert::stringNotEmpty($body); Assert::notNull($descriptionFactory); $startingLine = 1; $lineCount = null; $description = null; // Starting line / Number of lines / Description if (preg_match('/^([1-9]\\d*)\\s*(?:((?1))\\s+)?(.*)$/sux', $body, $matches)) { $startingLine = (int) $matches[1]; if (isset($matches[2]) && $matches[2] !== '') { $lineCount = (int) $matches[2]; } $description = $matches[3]; } return new static($startingLine, $lineCount, $descriptionFactory->create($description, $context)); }
/** * @param string $commonName * @param string $countryName * @param string $stateOrProvinceName * @param string $localityName * @param string $organizationName * @param string $organizationalUnitName * @param string $emailAddress * @param array $subjectAlternativeNames */ public function __construct($commonName, $countryName = null, $stateOrProvinceName = null, $localityName = null, $organizationName = null, $organizationalUnitName = null, $emailAddress = null, array $subjectAlternativeNames = []) { Assert::stringNotEmpty($commonName, __CLASS__ . '::$commonName expected a non empty string. Got: %s'); Assert::nullOrString($countryName, __CLASS__ . '::$countryName expected a string. Got: %s'); Assert::nullOrString($stateOrProvinceName, __CLASS__ . '::$stateOrProvinceName expected a string. Got: %s'); Assert::nullOrString($localityName, __CLASS__ . '::$localityName expected a string. Got: %s'); Assert::nullOrString($organizationName, __CLASS__ . '::$organizationName expected a string. Got: %s'); Assert::nullOrString($organizationalUnitName, __CLASS__ . '::$organizationalUnitName expected a string. Got: %s'); Assert::nullOrString($emailAddress, __CLASS__ . '::$emailAddress expected a string. Got: %s'); Assert::allStringNotEmpty($subjectAlternativeNames, __CLASS__ . '::$subjectAlternativeNames expected an array of non empty string. Got: %s'); $this->commonName = $commonName; $this->countryName = $countryName; $this->stateOrProvinceName = $stateOrProvinceName; $this->localityName = $localityName; $this->organizationName = $organizationName; $this->organizationalUnitName = $organizationalUnitName; $this->emailAddress = $emailAddress; $this->subjectAlternativeNames = array_diff(array_unique($subjectAlternativeNames), [$commonName]); }
/** * Turns a relative path into an absolute path. * * Usually, the relative path is appended to the given base path. Dot * segments ("." and "..") are removed/collapsed and all slashes turned * into forward slashes. * * ```php * echo Path::makeAbsolute("../style.css", "/webmozart/puli/css"); * // => /webmozart/puli/style.css * ``` * * If an absolute path is passed, that path is returned unless its root * directory is different than the one of the base path. In that case, an * exception is thrown. * * ```php * Path::makeAbsolute("/style.css", "/webmozart/puli/css"); * // => /style.css * * Path::makeAbsolute("C:/style.css", "C:/webmozart/puli/css"); * // => C:/style.css * * Path::makeAbsolute("C:/style.css", "/webmozart/puli/css"); * // InvalidArgumentException * ``` * * If the base path is not an absolute path, an exception is thrown. * * The result is a canonical path. * * @param string $path A path to make absolute. * @param string $basePath An absolute base path. * * @return string An absolute path in canonical form. * * @throws InvalidArgumentException If the base path is not absolute or if * the given path is an absolute path with * a different root than the base path. * * @since 1.0 Added method. * @since 2.0 Method now fails if $path or $basePath is not a string. * @since 2.2.2 Method does not fail anymore of $path and $basePath are * absolute, but on different partitions. */ public static function makeAbsolute($path, $basePath) { Assert::stringNotEmpty($basePath, 'The base path must be a non-empty string. Got: %s'); if (!static::isAbsolute($basePath)) { throw new InvalidArgumentException(sprintf('The base path "%s" is not an absolute path.', $basePath)); } if (static::isAbsolute($path)) { return static::canonicalize($path); } if (false !== ($pos = strpos($basePath, '://'))) { $scheme = substr($basePath, 0, $pos + 3); $basePath = substr($basePath, $pos + 3); } else { $scheme = ''; } return $scheme . self::canonicalize(rtrim($basePath, '/\\') . '/' . $path); }
/** * Sets the default value of the argument. * * @param string $defaultValue The default value as source code. * * @return static The current instance. */ public function setDefaultValue($defaultValue) { Assert::stringNotEmpty($defaultValue, 'The argument default value must be a non-empty string. Got: %s'); $this->defaultValue = $defaultValue; return $this; }
/** * {@inheritdoc} */ public function requestCertificate($domain, CertificateRequest $csr, $timeout = 180) { Assert::stringNotEmpty($domain, 'requestCertificate::$domain expected a non-empty string. Got: %s'); Assert::integer($timeout, 'requestCertificate::$timeout expected an integer. Got: %s'); $humanText = ['-----BEGIN CERTIFICATE REQUEST-----', '-----END CERTIFICATE REQUEST-----']; $csrContent = $this->csrSigner->signCertificateRequest($csr); $csrContent = trim(str_replace($humanText, '', $csrContent)); $csrContent = trim($this->httpClient->getBase64Encoder()->encode(base64_decode($csrContent))); $response = $this->requestResource('POST', ResourcesDirectory::NEW_CERTIFICATE, ['resource' => ResourcesDirectory::NEW_CERTIFICATE, 'csr' => $csrContent], false); // If the CA has not yet issued the certificate, the body of this response will be empty if (strlen(trim($response)) < 10) { // 10 to avoid false results $location = $this->httpClient->getLastLocation(); // Waiting loop $endTime = time() + $timeout; while (time() <= $endTime) { $response = $this->httpClient->unsignedRequest('GET', $location, null, false); if (200 === $this->httpClient->getLastCode()) { break; } if (202 !== $this->httpClient->getLastCode()) { throw new CertificateRequestFailedException($response); } sleep(1); } if (202 === $this->httpClient->getLastCode()) { throw new CertificateRequestTimedOutException($response); } } // Find issuers certificate $links = $this->httpClient->getLastLinks(); $certificatesChain = null; foreach ($links as $link) { if (!isset($link['rel']) || 'up' !== $link['rel']) { continue; } $location = trim($link[0], '<>'); $certificate = $this->httpClient->unsignedRequest('GET', $location, null, false); if (strlen(trim($certificate)) > 10) { $pem = chunk_split(base64_encode($certificate), 64, "\n"); $pem = "-----BEGIN CERTIFICATE-----\n" . $pem . "-----END CERTIFICATE-----\n"; $certificatesChain = new Certificate($pem, $certificatesChain); } } // Domain certificate $pem = chunk_split(base64_encode($response), 64, "\n"); $pem = "-----BEGIN CERTIFICATE-----\n" . $pem . "-----END CERTIFICATE-----\n"; return new CertificateResponse($csr, new Certificate($pem, $certificatesChain)); }
/** * @param Connection $connection A doctrine connection instance * @param string $tableName The name of the database table */ public function __construct(Connection $connection, $tableName = 'store') { Assert::stringNotEmpty($tableName, 'The table must be a string. Got: %s'); $this->connection = $connection; $this->tableName = $tableName; }
/** * Turns a relative path into an absolute path. * * Usually, the relative path is appended to the given base path. Dot * segments ("." and "..") are removed/collapsed and all slashes turned * into forward slashes. * * ```php * echo Path::makeAbsolute("../style.css", "/webmozart/puli/css"); * // => /webmozart/puli/style.css * ``` * * If an absolute path is passed, that path is returned unless its root * directory is different than the one of the base path. In that case, an * exception is thrown. * * ```php * Path::makeAbsolute("/style.css", "/webmozart/puli/css"); * // => /style.css * * Path::makeAbsolute("C:/style.css", "C:/webmozart/puli/css"); * // => C:/style.css * * Path::makeAbsolute("C:/style.css", "/webmozart/puli/css"); * // InvalidArgumentException * ``` * * If the base path is not an absolute path, an exception is thrown. * * The result is a canonical path. * * @param string $path A path to make absolute. * @param string $basePath An absolute base path. * * @return string An absolute path in canonical form. * * @throws InvalidArgumentException If the base path is not absolute or if * the given path is an absolute path with * a different root than the base path. * * @since 1.0 Added method. * @since 2.0 Method now fails if $path or $basePath is not a string. */ public static function makeAbsolute($path, $basePath) { Assert::stringNotEmpty($basePath, 'The base path must be a non-empty string. Got: %s'); if (!static::isAbsolute($basePath)) { throw new InvalidArgumentException(sprintf('The base path "%s" is not an absolute path.', $basePath)); } if (static::isAbsolute($path)) { $root = static::getRoot($path); $baseRoot = static::getRoot($basePath); if ($root !== $baseRoot) { throw new InvalidArgumentException(sprintf('The path "%s" cannot be made absolute based on "%s", ' . 'because their roots are different ("%s" and "%s").', $path, $basePath, $root, $baseRoot)); } return static::canonicalize($path); } if (false !== ($pos = strpos($basePath, '://'))) { $scheme = substr($basePath, 0, $pos + 3); $basePath = substr($basePath, $pos + 3); } else { $scheme = ''; } return $scheme . self::canonicalize(rtrim($basePath, '/\\') . '/' . $path); }
/** * Adds source code to the method body. * * A newline is inserted between the current code and the added code. * * @param string $body The source code to add. * * @return static The current instance. */ public function addBody($body) { Assert::stringNotEmpty($body, 'The method body must be a non-empty string. Got: %s'); if ($this->body) { $this->body .= "\n" . $body; } else { $this->body = $body; } return $this; }
/** * {@inheritDoc} */ public function registerTagHandler($tagName, $handler) { Assert::stringNotEmpty($tagName); Assert::stringNotEmpty($handler); Assert::classExists($handler); Assert::implementsInterface($handler, StaticMethod::class); if (strpos($tagName, '\\') && $tagName[0] !== '\\') { throw new \InvalidArgumentException('A namespaced tag must have a leading backslash as it must be fully qualified'); } $this->tagHandlerMappings[$tagName] = $handler; }
/** * Splits a path into mount point and path. * * @param string $path The path to split. * * @return array An array with the mount point and the path. If no mount * point was found, both are `null`. */ private function splitPath($path) { Assert::stringNotEmpty($path, 'The path must be a non-empty string. Got: %s'); Assert::startsWith($path, '/', 'The path %s is not absolute.'); $path = Path::canonicalize($path); foreach ($this->repos as $mountPoint => $_) { if (Path::isBasePath($mountPoint, $path)) { // Special case "/": return the complete path if ('/' === $mountPoint) { return array($mountPoint, $path); } return array($mountPoint, substr($path, strlen($mountPoint))); } } return array(null, null); }
/** * {@inheritdoc} */ public function findBindings($typeName, Expression $expr = null) { Assert::stringNotEmpty($typeName, 'The type class must be a non-empty string. Got: %s'); if (!isset($this->keysByTypeName[$typeName])) { return array(); } $key = $this->keysByTypeName[$typeName]; if (!isset($this->bindingsByKey[$key])) { $this->loadBindingsForKey($key); } $bindings = $this->bindingsByKey[$key]; if (null !== $expr) { $bindings = $this->filterBindings($bindings, $expr); } return $bindings; }
/** * Creates a new iterator. * * The following constants can be used to configure what to filter by: * * * {@link FILTER_BY_PATH}: The pattern is matched against the paths; * * {@link FILTER_BY_NAME}: The pattern is matched against the names. * * The following constants can be used to configure how to match the * selected text: * * * {@link MATCH_PREFIX}: Tests whether the pattern is a prefix of the * matched text; * * {@link MATCH_SUFFIX}: Tests whether the pattern is a suffix of the * matched text; * * {@link MATCH_REGEX}: Treats the pattern as regular expression. * * By default, the mode `FILTER_BY_PATH | MATCH_REGEX` is used. * * @param ResourceIterator $iterator The filtered iterator. * @param string $pattern The pattern to match. * @param int|null $mode A bitwise combination of the mode * constants. */ public function __construct(ResourceIterator $iterator, $pattern, $mode = null) { Assert::stringNotEmpty($pattern, 'The pattern must be a non-empty string. Got: %s'); parent::__construct($iterator); if (!($mode & (self::FILTER_BY_PATH | self::FILTER_BY_NAME))) { $mode |= self::FILTER_BY_PATH; } if (!($mode & (self::MATCH_PREFIX | self::MATCH_SUFFIX | self::MATCH_REGEX))) { $mode |= self::MATCH_REGEX; } $this->pattern = $pattern; $this->patternLength = strlen($pattern); $this->mode = $mode; }