Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * @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;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }
Ejemplo n.º 7
0
 /**
  * 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();
 }
Ejemplo n.º 8
0
 /**
  * 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 = [];
 }
Ejemplo n.º 9
0
 /** {@inheritDoc} */
 public function delete($identifier)
 {
     Assert::isString($identifier);
     if (array_key_exists($identifier, $this->cacheValues)) {
         unset($this->cacheValues[$identifier]);
     }
     return $this;
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 12
0
 /**
  * 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;
 }
Ejemplo n.º 13
0
 /**
  * @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;
 }
Ejemplo n.º 14
0
 /**
  * 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;
 }
Ejemplo n.º 15
0
 /**
  * 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;
 }
Ejemplo n.º 18
0
 /**
  * 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;
 }
Ejemplo n.º 20
0
 /**
  * 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);
 }
Ejemplo n.º 21
0
 /** {@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;
 }
Ejemplo n.º 22
0
 /**
  * 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;
 }
Ejemplo n.º 23
0
 /** {@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);
 }
Ejemplo n.º 25
0
 /**
  * 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;
 }
Ejemplo n.º 26
0
 /**
  * @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);
 }
Ejemplo n.º 27
0
 /** {@inheritDoc} */
 public function matches($value)
 {
     Assert::isString($value);
     $valueLength = strlen($value);
     return $valueLength >= $this->minLength && ($this->maxLength === null || $valueLength <= $this->maxLength);
 }
Ejemplo n.º 28
0
 /**
  * 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];
 }
Ejemplo n.º 29
0
 /**
  * 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);
 }
Ejemplo n.º 30
0
 /**
  * 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]);
 }