/** * Class constructor. * @param string $hostname * @param integer $portNumber */ public function __construct($hostname, $portNumber = 80) { Assert::isString($hostname); Assert::isInteger($portNumber); $this->hostname = $hostname; $this->portNumber = $portNumber; }
/** * Class constructor. * Initializes the error handler. * @param \Brickoo\Component\Messaging\MessageDispatcher $messageDispatcher * @param boolean $convertToException flag to convert errors to exceptions */ public function __construct(MessageDispatcher $messageDispatcher, $convertToException = true) { Assert::isBoolean($convertToException); $this->messageDispatcher = $messageDispatcher; $this->convertToException = $convertToException; $this->isRegistered = false; }
/** * @param string $messageName * @param integer $priority * @param callable $callback */ public function __construct($messageName, $priority, callable $callback) { Assert::isString($messageName); Assert::isInteger($priority); $this->messageName = $messageName; $this->priority = $priority; $this->callback = $callback; }
/** * Class constructor. * @param string $version the http version * @throws \InvalidArgumentException * @throws \Brickoo\Component\Http\Exception\InvalidHttpVersionException */ public function __construct($version) { Assert::isString($version); if (!$this->isValid($version)) { throw new InvalidHttpVersionException($version); } $this->version = $version; }
/** * Class constructor * @param string $method the http method * @throws \Brickoo\Component\Http\Exception\InvalidHttpMethodException */ public function __construct($method) { Assert::isString($method); if (!$this->isValid($method)) { throw new InvalidHttpMethodException($method); } $this->method = $method; }
/** * Class constructor. * @param integer $status the http status * @throws \InvalidArgumentException * @throws \Brickoo\Component\Http\Exception\InvalidHttpStatusException */ public function __construct($status) { Assert::isInteger($status); if (!$this->isValid($status)) { throw new InvalidHttpStatusException($status); } $this->status = $status; }
/** * Class constructor. * @param mixed $dependency * @param integer $scope * @param null|\Brickoo\Component\IoC\Definition\Container\ArgumentDefinitionContainer $argumentsContainer * @param null|\Brickoo\Component\IoC\Definition\Container\InjectionDefinitionContainer $injectionsContainer */ public function __construct($dependency, $scope = self::SCOPE_PROTOTYPE, ArgumentDefinitionContainer $argumentsContainer = null, InjectionDefinitionContainer $injectionsContainer = null) { Assert::isInteger($scope); $this->scope = $scope; $this->setDependency($dependency); $this->argumentsContainer = $argumentsContainer ?: new ArgumentDefinitionContainer(); $this->injectionsContainer = $injectionsContainer ?: new InjectionDefinitionContainer(); }
/** * Class constructor * @param string $matchingPath * @param \Brickoo\Component\Routing\Route\RoutePathRegexGenerator $regexGenerator */ public function __construct($matchingPath, RoutePathRegexGenerator $regexGenerator) { Assert::isString($matchingPath); $this->matchingPath = $matchingPath; $this->regexGenerator = $regexGenerator; $this->routeParameters = []; $this->pathParameters = []; }
/** {@inheritDoc} */ public function delete($identifier) { Assert::isString($identifier); if (array_key_exists($identifier, $this->cacheValues)) { unset($this->cacheValues[$identifier]); } return $this; }
/** * Return the read bytes from the stream. * @param integer $bytes * @throws \InvalidArgumentException * @throws \Brickoo\Component\IO\Stream\Exception\InvalidResourceHandleException * @return string the read content */ public function read($bytes = 1024) { Assert::isInteger($bytes); if (!is_resource($this->streamResource)) { throw new InvalidResourceHandleException(); } return (string) fread($this->streamResource, $bytes); }
/** * Class constructor. * @param string $name * @param string $type * @param boolean $required * @throws \InvalidArgumentException */ public function __construct($name, $type, $required = true) { Assert::isString($name); Assert::isString($type); Assert::isBoolean($required); $this->name = $name; $this->type = $type; $this->required = $required; }
/** * Class constructor. * @param integer $target * @param string $targetLocation * @param string $name the annotation name * @param array $values the annotation values */ public function __construct($target, $targetLocation, $name, array $values = []) { Assert::isInteger($target); Assert::isString($targetLocation); Assert::isString($name); $this->target = $target; $this->targetLocation = $targetLocation; $this->name = $name; $this->values = $values; }
/** * @param string $filename * @param integer $mode * @param boolean $useIncludePath * @param array $context * @throws \InvalidArgumentException */ public function __construct($filename, $mode, $useIncludePath = false, array $context = array()) { Assert::isString($filename); Assert::isInteger($mode); Assert::isBoolean($useIncludePath); $this->filename = $filename; $this->mode = $mode; $this->useIncludePath = $useIncludePath; $this->context = $context; }
/** * Class constructor. * @param string $address * @param integer $port * @param integer $timeout * @param integer $connectionType * @param array $context */ public function __construct($address, $port, $timeout = 30, $connectionType = STREAM_CLIENT_CONNECT, array $context = array()) { Assert::isString($address); Assert::isInteger($timeout); Assert::isInteger($connectionType); $this->serverAddress = $address; $this->serverPort = $port; $this->connectionTimeout = $timeout; $this->connectionType = $connectionType; $this->context = $context; }
/** * Class constructor. * @param string $scheme the uri protocol scheme * @param \Brickoo\Component\Http\UriAuthority $authority * @param string $path the uri path * @param \Brickoo\Component\Http\UriQuery $query * @param string $fragment */ public function __construct($scheme, UriAuthority $authority, $path, UriQuery $query, $fragment) { Assert::isString($scheme); Assert::isString($path); Assert::isString($fragment); $this->scheme = $scheme; $this->authority = $authority; $this->path = $path; $this->query = $query; $this->fragment = $fragment; }
/** * Returns the annotations definitions matching the target * as an iterable array object. * @param integer $target * @return \ArrayIterator */ public function filter($target) { Assert::isInteger($target); $annotationsDefinitions = []; foreach ($this->definitionsCollection as $annotationDefinition) { if ($annotationDefinition->isTarget($target)) { $annotationsDefinitions[] = $annotationDefinition; } } return new ArrayIterator($annotationsDefinitions); }
/** * Returns the injection definition matching a target. * @param string $target * @return array the target matching injection definitions. */ public function getByTarget($target) { Assert::isString($target); $injections = []; foreach ($this->getAll() as $injection) { if ($injection->isTarget($target)) { $injections[] = $injection; } } return $injections; }
/** * Imports the query parameters from the extracted key/value pairs. * @param string $query the query to extract the pairs from * @throws \InvalidArgumentException if the argument is not valid * @return \Brickoo\Component\Http\UriQuery */ public function fromString($query) { Assert::isString($query); if (($position = strpos($query, "?")) !== false) { $query = substr($query, $position + 1); } parse_str(rawurldecode($query), $importedQueryParameters); if (is_array($importedQueryParameters)) { $this->fromArray($importedQueryParameters); } return $this; }
/** * {@inheritDoc} * @param array|\Traversable $traversable */ public function matches($traversable) { Assert::isTraversable($traversable); $result = true; foreach ($traversable as $value) { if (!$value instanceof $this->expectedInstanceOf) { $result = false; break; } } return $result; }
/** * Builds an uri string based on the parameters provided. * @param string $routeName the route to use for the build * @param array $pathParameters the path parameters as key/value pairs * @param string $queryString * @throws \Brickoo\Component\Routing\Route\Exception\PathNotValidException * @internal param string $queryParameters the query parameters * @return string the built uri */ public function build($routeName, array $pathParameters = [], $queryString = "") { Assert::isString($routeName); Assert::isString($queryString); $route = $this->router->getRoute($routeName); $expectedPath = $this->getExpectedRoutePath($route, $pathParameters); $matches = []; if (preg_match_all($this->regexGenerator->generate($route), $expectedPath, $matches) === 0) { throw new PathNotValidException($routeName, $expectedPath); } return $this->createUriString($expectedPath, $queryString); }
/** {@inheritDoc} */ public function log($messages, $severity) { Assert::isInteger($severity); if (!is_array($messages)) { $messages = [$messages]; } $logMessage = $this->convertToLogMessage($messages, $severity); $location = $this->logsDirectory . date("Y-m-d") . ".log"; $file = fopen($location, "a"); fwrite($file, $logMessage); fclose($file); return $this; }
/** * Class constructor. * @param string $routingPath the routing directory path * @param string $routingFilename the route filename to look for * @param boolean $searchRecursively flag to search recursively * @throws \InvalidArgumentException if an argument is not valid */ public function __construct($routingPath, $routingFilename, $searchRecursively = false) { Assert::isString($routingPath); Assert::isString($routingFilename); Assert::isBoolean($searchRecursively); if (empty($routingPath)) { throw new InvalidArgumentException("The routing path cannot be empty."); } if (empty($routingFilename)) { throw new InvalidArgumentException("The routing filename cannot be empty."); } $this->routingPath = $routingPath; $this->routingFilename = $routingFilename; $this->searchRecursively = $searchRecursively; }
/** {@inheritDoc} */ public function has($adapterIdentifier) { Assert::isStringOrInteger($adapterIdentifier); return in_array($adapterIdentifier, $this->mappingKeys, false); }
/** * Class constructor. * @param string $expectedType the values expected type * @throws \InvalidArgumentException if an argument is not valid. */ public function __construct($expectedType) { Assert::isString($expectedType); parent::__construct("ctype_" . $expectedType); }
/** * Deletes the stored content which is hold by the identifier. * Removes the local stored content. * @param string $identifier the identifier which holds the content * @throws \InvalidArgumentException if an argument is not valid * @return \Brickoo\Component\Storage\StorageProxy */ public function delete($identifier) { Assert::isString($identifier); $this->executeIterationCallback(function (Adapter $readyAdapter) use($identifier) { $readyAdapter->delete($identifier); return null; }); return $this; }
/** * @param \Brickoo\Component\IO\Stream\Stream $stream * @param integer $bufferLength default buffer length 255 bytes * @throws \InvalidArgumentException */ public function __construct(Stream $stream, $bufferLength = 255) { Assert::isInteger($bufferLength); $this->stream = $stream; $this->initializeBuffer($bufferLength); }
/** {@inheritDoc} */ public function matches($value) { Assert::isString($value); $valueLength = strlen($value); return $valueLength >= $this->minLength && ($this->maxLength === null || $valueLength <= $this->maxLength); }
/** * Returns the phrase for the status code. * @param integer $statusCode * @throws \Brickoo\Component\Http\Exception\StatusCodeUnknownException * @return string the status code phrase */ public function getPhrase($statusCode) { Assert::isInteger($statusCode); if (!$this->hasPhrase($statusCode)) { throw new StatusCodeUnknownException($statusCode); } return $this->statusPhrases[$statusCode]; }
/** * Moves the stream pointer from the end * position forward to the offset. * @param integer $offset * @throws \Brickoo\Component\IO\Stream\Exception\InvalidResourceHandleException * @return boolean success of movement */ public function seekEnd($offset) { Assert::isInteger($offset); return $this->processSeek($offset, SEEK_END); }
/** * Check if the header field has a mapping class. * @param string $headerFieldName * @return boolean */ public function hasClass($headerFieldName) { Assert::isStringOrInteger($headerFieldName); return isset($this->map[$headerFieldName]); }