min() public static method

Assert that a value is at least as big as a given limit
public static min ( mixed $value, mixed $minValue, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$minValue mixed
$message string | null
$propertyPath string | null
return boolean
Exemplo n.º 1
0
 /**
  * Create service with name
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @param string $name
  * @param string $requestedName
  * @throws \LogicException
  * @return mixed
  */
 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
 {
     /** @var $env Environment */
     $env = $serviceLocator->get(Definition::SERVICE_ENVIRONMENT);
     $nameParts = explode('.', $requestedName);
     Assertion::min(count($nameParts), 3, sprintf("Given service bus alias %s is invalid. Format should be processing.(command|event)_bus.[target]", $requestedName));
     $busType = $nameParts[1];
     unset($nameParts[0]);
     unset($nameParts[1]);
     $address = implode('.', $nameParts);
     $busConfig = $this->getChannelConfigFor($env, $address);
     $target = $this->getTargetFromAddress($address);
     $bus = $busType === "command_bus" ? new CommandBus() : new EventBus();
     $bus->utilize($this->getForwardToMessageDispatcher());
     $bus->utilize($this->getToMessageTranslator());
     $bus->utilize($this->getHandleWorkflowMessageStrategy());
     $bus->utilize($this->getInvokeProcessorStrategy());
     $bus->utilize(new ServiceLocatorProxy(Zf2ServiceManagerProxy::proxy($serviceLocator)));
     $messageHandler = $busConfig->stringValue('message_dispatcher', $target);
     if (!empty($messageHandler)) {
         $bus->utilize(new SingleTargetMessageRouter($messageHandler));
     } else {
         throw new \LogicException("Missing a message handler for the bus " . $requestedName);
     }
     foreach ($busConfig->arrayValue('utils') as $busUtil) {
         if (is_string($busUtil)) {
             $busUtil = $serviceLocator->get($busUtil);
         }
         $bus->utilize($busUtil);
     }
     return $bus;
 }
Exemplo n.º 2
0
 /**
  * @param string $aggregateType
  * @param string $aggregateId
  * @param int $version
  * @return TakeSnapshot
  */
 public static function withData($aggregateType, $aggregateId, $version)
 {
     Assertion::string($aggregateType);
     Assertion::string($aggregateId);
     Assertion::min($version, 1);
     return new self(['aggregate_type' => $aggregateType, 'aggregate_id' => $aggregateId, 'version' => $version]);
 }
Exemplo n.º 3
0
 /**
  * @param CommandBus $commandBus
  * @param int $versionStep
  * @param array $eventNames
  */
 public function __construct(CommandBus $commandBus, $versionStep, array $eventNames = [])
 {
     Assertion::min($versionStep, 1);
     $this->commandBus = $commandBus;
     $this->versionStep = $versionStep;
     $this->eventNames = $eventNames;
     $this->hasEventNames = !empty($eventNames);
 }
Exemplo n.º 4
0
 /**
  * Constructor
  *
  * @param AMQPQueue $queue
  * @param int $waitMicros
  * @param string|null $appId
  */
 public function __construct(AMQPQueue $queue, $waitMicros = 1000, $appId = null)
 {
     Assertion::min($waitMicros, 1);
     $this->queue = $queue;
     $this->waitMicros = $waitMicros;
     if (null !== $appId) {
         Assertion::minLength($appId, 1);
         $this->appId = $appId;
     }
 }
 public function __construct($value)
 {
     parent::__construct($value);
     try {
         Assertion::min($value, 1);
         $this->value = (int) $value;
     } catch (AssertionInvalidArgumentException $exception) {
         throw new InvalidArgumentException($value);
     }
 }
Exemplo n.º 6
0
 public function __construct(array $parameters, $offset, $limit)
 {
     Assertion::integer($offset);
     Assertion::min($offset, 0);
     Assertion::integer($limit);
     Assertion::min($limit, 1);
     $this->parameters = $parameters;
     $this->offset = $offset;
     $this->limit = $limit;
 }
Exemplo n.º 7
0
 /**
  * Constructor
  *
  * @param Queue $queue
  * @param Exchange[] $exchanges
  * @param int $waitMillis
  * @param string $appId
  */
 public function __construct(Queue $queue, array $exchanges, int $waitMillis = 100, string $appId = '')
 {
     Assertion::min($waitMillis, 1);
     Assertion::notEmpty($exchanges, 'No exchanges given');
     Assertion::allIsInstanceOf($exchanges, Exchange::class);
     $this->queue = $queue;
     $this->exchanges = $exchanges;
     $this->waitMillis = $waitMillis;
     $this->appId = $appId;
 }
Exemplo n.º 8
0
 /**
  * @param AggregateType $aggregateType
  * @param string $aggregateId
  * @param object $aggregateRoot
  * @param int $lastVersion
  * @param DateTimeImmutable $createdAt
  */
 public function __construct(AggregateType $aggregateType, $aggregateId, $aggregateRoot, $lastVersion, DateTimeImmutable $createdAt)
 {
     Assertion::minLength($aggregateId, 1);
     Assertion::isObject($aggregateRoot);
     Assertion::min($lastVersion, 1);
     $this->aggregateType = $aggregateType;
     $this->aggregateId = $aggregateId;
     $this->aggregateRoot = $aggregateRoot;
     $this->lastVersion = $lastVersion;
     $this->createdAt = $createdAt;
 }
Exemplo n.º 9
0
 /**
  * Creates dummy folders, like the project directory helper would do.
  *
  * @param int $amount Amount of folders to create
  *
  * @return null
  */
 private function createFolders($amount)
 {
     Assertion::integer($amount);
     Assertion::min($amount, 1);
     $fs = new Filesystem();
     $date = new \DateTime();
     $date->modify(sprintf('-%s days', $amount));
     for ($i = 0; $i < $amount; $i++) {
         $date->modify('+1 day');
         $fs->mkdir(sprintf('%s/demo-project/%s', $this->getWorkspace(), $date->format('YmdHis')));
     }
 }
Exemplo n.º 10
0
 /**
  * @param string $template
  * @param string $title
  * @param int $requiredCols
  * @param null|array|\Traversable $variables
  * @param null $newGroup
  * @return DashboardWidget
  */
 public static function initialize($template, $title, $requiredCols, $variables = null, $newGroup = null)
 {
     Assertion::string($template);
     Assertion::string($title);
     Assertion::integer($requiredCols);
     Assertion::min($requiredCols, 1);
     Assertion::max($requiredCols, 12);
     $options = ['required_cols' => $requiredCols, 'title' => $title, 'new_group' => $newGroup];
     $model = new self($variables, $options);
     $model->setTemplate($template);
     return $model;
 }
Exemplo n.º 11
0
 public function __construct(CriteriaList $search_criteria_list, CriteriaList $filter_criteria_list, CriteriaList $sort_criteria_list, $offset, $limit)
 {
     Assertion::integer($offset);
     Assertion::min($offset, 0);
     Assertion::integer($limit);
     Assertion::min($limit, 1);
     $this->search_criteria_list = $search_criteria_list;
     $this->filter_criteria_list = $filter_criteria_list;
     $this->sort_criteria_list = $sort_criteria_list;
     $this->offset = $offset;
     $this->limit = $limit;
 }
Exemplo n.º 12
0
 public function __construct($name, array $parameters, $offset, $limit)
 {
     Assertion::string($name);
     Assertion::notEmpty($name);
     Assertion::integer($offset);
     Assertion::min($offset, 0);
     Assertion::integer($limit);
     Assertion::min($limit, 1);
     $this->name = $name;
     $this->parameters = $parameters;
     $this->offset = $offset;
     $this->limit = $limit;
 }
Exemplo n.º 13
0
 /**
  * DownloadedJWKSet constructor.
  *
  * @param string                                 $url
  * @param \Psr\Cache\CacheItemPoolInterface|null $cache
  * @param int                                    $ttl
  * @param bool                                   $allow_unsecured_connection
  * @param bool                                   $allow_http_connection
  */
 public function __construct($url, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_unsecured_connection = false, $allow_http_connection = false)
 {
     Assertion::boolean($allow_unsecured_connection);
     Assertion::boolean($allow_http_connection);
     Assertion::integer($ttl);
     Assertion::min($ttl, 0);
     Assertion::false(false === filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED), 'Invalid URL.');
     $allowed_protocols = ['https'];
     if (true === $allow_http_connection) {
         $allowed_protocols[] = 'http';
     }
     Assertion::inArray(mb_substr($url, 0, mb_strpos($url, '://', 0, '8bit'), '8bit'), $allowed_protocols, sprintf('The provided sector identifier URI is not valid: scheme must be one of the following: %s.', json_encode($allowed_protocols)));
     $this->url = $url;
     $this->cache = $cache;
     $this->ttl = $ttl;
     $this->allow_unsecured_connection = $allow_unsecured_connection;
 }
Exemplo n.º 14
0
 /**
  * RpcClientRequest constructor.
  *
  * @param array|string|integer|float|bool $payload
  * @param string $server
  * @param string $requestId
  * @param string|null $routingKey
  * @param int $expiration
  * @param string|null $userId
  * @param string|null $messageId
  * @param string|null $timestamp
  * @param string|null $type
  */
 public function __construct($payload, $server, $requestId, $routingKey = null, $expiration = 0, $userId = null, $messageId = null, $timestamp = null, $type = null)
 {
     if (!is_array($payload) && !is_scalar($payload)) {
         throw new Exception\InvalidArgumentException('$payload must be of type array or scalar');
     }
     Assertion::minLength($server, 1);
     Assertion::minLength($requestId, 1);
     Assertion::nullOrString($routingKey);
     Assertion::min($expiration, 0);
     Assertion::nullOrString($userId);
     Assertion::nullOrString($messageId);
     Assertion::nullOrString($timestamp);
     Assertion::nullOrString($type);
     $this->payload = $payload;
     $this->server = $server;
     $this->requestId = $requestId;
     $this->routingKey = $routingKey;
     $this->expiration = $expiration;
     $this->userId = $userId;
     $this->messageId = $messageId;
     $this->timestamp = $timestamp;
     $this->type = $type;
 }
Exemplo n.º 15
0
 /**
  * Defines the amount of entities to be fetched from the information provider.
  *
  * @param integer $limit Positive integer defining the amount of records to be return in max. Zero (0) defines an unlimited amount.
  *
  * @throws \Assert\InvalidArgumentException in case the provided argument does not meet expectations.
  */
 public function setLimit($limit)
 {
     $message = 'Given limit must be a positive number.';
     Assertion::numeric($limit, $message);
     Assertion::min($limit, 0, $message);
     $this->limit = $limit;
 }
Exemplo n.º 16
0
 /**
  * @param int $retryCount
  */
 private function setRetryCount($retryCount)
 {
     Assertion::integer($retryCount);
     Assertion::min($retryCount, 0);
     Assertion::max($retryCount, $this->retryLimit);
     $this->retryCount = $retryCount;
 }
Exemplo n.º 17
0
 /**
  * @param Envelope $envelope
  * @return DeliveryResult
  */
 protected function handleInternalMessage(Envelope $envelope) : DeliveryResult
 {
     if ('shutdown' === $envelope->getType()) {
         $this->logger->info('Shutdown message received');
         $this->shutdown();
         $result = DeliveryResult::MSG_ACK();
     } elseif ('reconfigure' === $envelope->getType()) {
         $this->logger->info('Reconfigure message received');
         try {
             list($idleTimeout, $target, $prefetchSize, $prefetchCount) = json_decode($envelope->getBody());
             if (is_numeric($idleTimeout)) {
                 $idleTimeout = (double) $idleTimeout;
             }
             Assertion::float($idleTimeout);
             Assertion::min($target, 0);
             Assertion::min($prefetchSize, 0);
             Assertion::min($prefetchCount, 0);
         } catch (\Throwable $e) {
             $this->logger->error('Exception during reconfiguration: ' . $e->getMessage());
             return DeliveryResult::MSG_REJECT();
         }
         $this->idleTimeout = $idleTimeout;
         $this->target = $target;
         $this->queue->getChannel()->qos($prefetchSize, $prefetchCount);
         $this->blockSize = $prefetchCount;
         $result = DeliveryResult::MSG_ACK();
     } elseif ('ping' === $envelope->getType()) {
         $this->logger->info('Ping message received');
         $result = DeliveryResult::MSG_ACK();
     } else {
         $this->logger->error('Invalid internal message: ' . $envelope->getType());
         $result = DeliveryResult::MSG_REJECT();
     }
     return $result;
 }
Exemplo n.º 18
0
 /**
  * @param $version
  */
 public static function assertVersion($version)
 {
     Assertion::min($version, 0, 'version must be an unsigned integer');
 }
Exemplo n.º 19
0
 /**
  * @param integer $amount
  */
 private function __construct($amount)
 {
     Guard::min($amount, 1, 'Amount must be at least one');
     $this->amount = $amount;
 }
 /**
  * @param MessageFactory $messageFactory
  * @param MessageConverter $messageConverter
  * @param \MongoClient $mongoClient
  * @param string $dbName
  * @param array|null $writeConcern
  * @param string|null $streamCollectionName
  * @param int|null $transactionTimeout
  */
 public function __construct(MessageFactory $messageFactory, MessageConverter $messageConverter, \MongoClient $mongoClient, $dbName, array $writeConcern = null, $streamCollectionName = null, $transactionTimeout = null)
 {
     Assertion::minLength($dbName, 1, 'Mongo database name is missing');
     $this->messageFactory = $messageFactory;
     $this->messageConverter = $messageConverter;
     $this->mongoClient = $mongoClient;
     $this->dbName = $dbName;
     if (null !== $streamCollectionName) {
         Assertion::minLength($streamCollectionName, 1, 'Stream collection name must be a string with min length 1');
         $this->streamCollectionName = $streamCollectionName;
     }
     if (null !== $writeConcern) {
         $this->writeConcern = $writeConcern;
     }
     if (null !== $transactionTimeout) {
         Assertion::min($transactionTimeout, 1, 'Transaction timeout must be a positive integer');
         $this->transactionTimeout = $transactionTimeout;
     }
 }
Exemplo n.º 21
0
 /**
  * Create a new AnyNumber
  *
  * @param int $value
  * @return void
  */
 public function __construct($value)
 {
     Assertion::min($value, 0);
     $this->value = $value;
 }
Exemplo n.º 22
0
 public function testMin()
 {
     Assertion::min(1, 1);
     Assertion::min(2, 1);
     Assertion::min(2.5, 1);
     $this->setExpectedException('Assert\\AssertionFailedException', null, Assertion::INVALID_MIN);
     Assertion::min(0, 1);
 }
Exemplo n.º 23
0
 /**
  * @param CommandBus $commandBus
  * @param int $versionStep
  */
 public function __construct(CommandBus $commandBus, $versionStep)
 {
     Assertion::min($versionStep, 1);
     $this->commandBus = $commandBus;
     $this->versionStep = $versionStep;
 }
Exemplo n.º 24
0
 /**
  * Validate quantity in stock:
  * 0 <= $quantityInStock <= 500
  * @param int $quantityInStock
  */
 public static function quantityInStock($quantityInStock)
 {
     Assert::min($quantityInStock, 0);
     Assert::max($quantityInStock, 500);
 }
 private function setPage($page)
 {
     Assertion::integer($page, 'Page number should be an integer');
     Assertion::min($page, 1, 'Page number should be at least 1');
     $this->page = $page;
 }
 /**
  * Start consumer
  *
  * @param int $msgAmount
  */
 public function consume($msgAmount = 0)
 {
     Assertion::min($msgAmount, 0);
     $this->target = $msgAmount;
     foreach ($this->queues as $index => $queue) {
         if (!$this->timestampLastAck) {
             $this->timestampLastAck = microtime(true);
         }
         $message = $queue->get();
         if ($message instanceof AMQPEnvelope) {
             try {
                 $processFlag = $this->handleDelivery($message, $queue);
             } catch (\Exception $e) {
                 $this->handleException($e);
                 $processFlag = false;
             }
             $this->handleProcessFlag($message, $processFlag);
         } elseif (0 == $index) {
             // all queues checked, no messages found
             usleep($this->waitTimeout);
         }
         $now = microtime(true);
         if ($this->countMessagesUnacked > 0 && ($this->countMessagesUnacked === $this->blockSize || $now - $this->timestampLastAck > $this->idleTimeout)) {
             $this->ackOrNackBlock();
         }
         if ($this->usePcntlSignalDispatch) {
             // Check for signals
             pcntl_signal_dispatch();
         }
         if (!$this->keepAlive || 0 != $this->target && $this->countMessagesConsumed >= $this->target) {
             break;
         }
     }
 }
Exemplo n.º 27
0
 /**
  * @param int $retryLimit
  */
 private function setRetryLimit($retryLimit)
 {
     Assertion::integer($retryLimit);
     Assertion::min($retryLimit, 0);
     $this->retryLimit = $retryLimit;
 }