private function setPath($path) { Assertion::string($path); Assertion::regex($path, '|(?mi-Us)^(/[a-zA-Z][a-zA-Z0-9_-]*)+(/@[a-zA-Z][a-zA-Z0-9_-]*)?$|'); $this->path = $path; return $this; }
/** * @param string $name */ protected function setName($name) { Assertion::string($name); Assertion::notBlank($name); $this->attributes['name'] = $name; $this->name = $name; }
/** * @param string $workflowName * @param string $workflowId * @return CreateWorkflow */ public static function withName($workflowName, $workflowId) { Assertion::string($workflowName); Assertion::notEmpty($workflowName); Assertion::uuid($workflowId); return new self(__CLASS__, ['workflow_id' => $workflowId, 'name' => $workflowName]); }
/** * @param MappingInterface[] $mappings */ public function __construct(array $mappings, string $className, callable $apply = null, callable $unapply = null) { foreach ($mappings as $mappingKey => $mapping) { Assertion::string($mappingKey); Assertion::isInstanceOf($mapping, MappingInterface::class); $this->mappings[$mappingKey] = $mapping->withPrefixAndRelativeKey($this->key, $mappingKey); } Assertion::classExists($className); if (null === $apply) { $apply = function (...$arguments) { return new $this->className(...array_values($arguments)); }; } if (null === $unapply) { $unapply = function ($value) { Assertion::isInstanceOf($value, $this->className); $values = []; $reflectionClass = new ReflectionClass($this->className); foreach ($reflectionClass->getProperties() as $property) { /* @var $property ReflectionProperty */ $property->setAccessible(true); $values[$property->getName()] = $property->getValue($value); } return $values; }; } $this->className = $className; $this->apply = $apply; $this->unapply = $unapply; }
/** * @param string $filename */ public function setFilename($filename) { Assertion::string($filename, 'Invalid filename.'); Assertion::directory(dirname($filename), 'The selected directory does not exist.'); Assertion::writeable(dirname($filename), 'The selected directory is not writable.'); $this->filename = $filename; }
/** * @param string $text * @param callable $selectAction * @param bool $showItemExtra */ public function __construct($text, callable $selectAction, $showItemExtra = false) { Assertion::string($text); $this->text = $text; $this->selectAction = $selectAction; $this->showItemExtra = (bool) $showItemExtra; }
/** * Устанавливает описание gitlab'a * * @param string $token * * @return $this * @throws \Assert\AssertionFailedException */ public function setToken($token) { Assertion::notEmpty($token); Assertion::string($token); $this->token = $token; return $this; }
/** * @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]); }
/** * @param string $value */ public function __construct($value) { Assertion::string($value); Assertion::minLength($value, 1); Assertion::maxLength($value, 50); $this->value = strtolower($value); }
protected function createExchangePipeline(MigrationTargetInterface $migration_target, $exchange_name) { Assertion::string($exchange_name); $wait_exchange_name = $exchange_name . self::WAIT_SUFFIX; $wait_queue_name = $wait_exchange_name . self::QUEUE_SUFFIX; $unrouted_exchange_name = $exchange_name . self::UNROUTED_SUFFIX; $unrouted_queue_name = $unrouted_exchange_name . self::QUEUE_SUFFIX; $repub_exchange_name = $exchange_name . self::REPUB_SUFFIX; $repub_queue_name = $repub_exchange_name . self::QUEUE_SUFFIX; $channel = $this->getConnection($migration_target)->channel(); // Setup the default exchange and queue pipelines $channel->exchange_declare($unrouted_exchange_name, 'fanout', false, true, false, true); //internal $channel->exchange_declare($repub_exchange_name, 'fanout', false, true, false, true); //internal $channel->exchange_declare($wait_exchange_name, 'fanout', false, true, false); $channel->exchange_declare($exchange_name, 'direct', false, true, false, false, false, ['alternate-exchange' => ['S', $unrouted_exchange_name]]); $channel->queue_declare($wait_queue_name, false, true, false, false, false, ['x-dead-letter-exchange' => ['S', $exchange_name]]); $channel->queue_bind($wait_queue_name, $wait_exchange_name); $channel->queue_declare($unrouted_queue_name, false, true, false, false, false, ['x-dead-letter-exchange' => ['S', $repub_exchange_name], 'x-message-ttl' => ['I', self::REPUB_INTERVAL]]); $channel->queue_bind($unrouted_queue_name, $unrouted_exchange_name); $channel->queue_declare($repub_queue_name, false, true, false, false); $channel->queue_bind($repub_queue_name, $repub_exchange_name); $this->createShovel($migration_target, $repub_exchange_name, $exchange_name, $repub_queue_name); }
/** * Returns a project config instance. * * @param string $project Project name * * @return Config */ public function getProjectConfig($project) { Assertion::string($project); Assertion::notEmpty($project); $config = $this->configLoader->load(array($this->getConfigFilePath($project))); return $config; }
/** * Initializes and returns a coordinate object with the specified coordinate information in string format. * * Valid format: * "latitude in degrees, longitude in degrees" * * Example: * "51.3703748, 6.1724031" * * Please note that UTM and MGRS coordinates are not yet supported! * * @param $coordinate Coordinate information in string format * * @return static */ public static function fromString($coordinate) { Assertion::string($coordinate); Assertion::true(substr_count($coordinate, ',') === 1); $coordinate = explode(',', $coordinate); return new static((double) $coordinate[0], (double) $coordinate[1]); }
private function addOptions(DOMDocument $document, DOMNode $node, array $options, array $selectedValues) { foreach ($options as $value => $label) { if (is_int($value)) { $value = (string) $value; } else { Assertion::string($value); } Assertion::true(is_string($label) || is_array($label)); if (is_array($label)) { $optgroup = $document->createElement('optgroup'); $this->addAttributes($optgroup, ['label' => $value]); $this->addOptions($document, $optgroup, $label, $selectedValues); $node->appendChild($optgroup); continue; } $option = $document->createElement('option'); $option->appendChild($document->createTextNode($label)); $htmlAttributes = ['value' => $value]; if (in_array($value, $selectedValues)) { $htmlAttributes['selected'] = 'selected'; } $this->addAttributes($option, $htmlAttributes); $node->appendChild($option); } }
/** * @param string $type * @param string $code */ public function __construct($type, $code) { Assertion::inArray($type, $this->types); Assertion::string($code); $this->type = $type; $this->code = $code; }
/** * @param string $messageName * @return string */ public static function normalize($messageName) { Assertion::notEmpty($messageName); Assertion::string($messageName); $search = array(static::MESSAGE_NAME_PREFIX, "-", "\\", "/", " "); return strtolower(str_replace($search, "", $messageName)); }
/** * Builds an environment. * * @param string $name Name * @param array $environment Environment * @param Project $project Project instance * * @return Environment */ public function build($name, array $environment, Project $project) { Assertion::string($name); $this->logger->debug(sprintf("Building environment '%s'", $name)); if (empty($environment)) { throw new \DomainException(sprintf("No configuration for environment '%s' given", $name)); } if (!array_key_exists('servers', $environment) || empty($environment['servers'])) { throw new \DomainException(sprintf("No servers for environment '%s' given", $name)); } if (!array_key_exists('stages', $environment) || empty($environment['stages'])) { throw new \DomainException(sprintf("No stages for environment '%s' given", $name)); } $this->tasks = $project->getTasks(); $this->logger->debug("Creating environment instance."); $options = $environment; $environment = new Environment($name); if (array_key_exists('config', $options)) { $this->logger->debug("Config section given. Hydrating config instance."); $environment->getConfig()->merge(new Config($options['config'])); } else { $this->logger->debug("No config section given."); } foreach ($options['stages'] as $name => $stage) { if (!$stage) { throw new \DomainException(sprintf("No tasks for stage '%s' in environment '%s' given", $name, $environment->getName())); } $environment->addStage($this->buildStage($name, $stage)); } $this->logger->debug(sprintf("Resolving task/server mapping.")); $environment->setMapping($this->mappingResolver->resolve($options, $environment, $project)); return $environment; }
private function assertConfig(array $config) { Assertion::keyExists($config, "dbname"); Assertion::string($config['dbname']); Assertion::keyExists($config, "driver"); Assertion::inArray($config["driver"], $this->supportedDrivers); }
/** * Initialise text item * * @param string $breakChar * @param int $lines */ public function __construct($breakChar = ' ', $lines = 1) { Assertion::string($breakChar); Assertion::integer($lines); $this->breakChar = $breakChar; $this->lines = $lines; }
public function __construct($templateId, $id) { Assertion::notEmpty($templateId); Assertion::string($id); $this->id = $id; $this->templateId = $templateId; }
public function __construct($name, $set) { Assertion::string($name); Assertion::boolean($set); $this->name = $name; $this->set = $set; }
/** * Create a new Setting * * @param NotificationId $id * @param User $user * @param string $key * @return void */ public function __construct(SettingId $id, User $user, $key) { Assertion::string($key); $this->setId($id); $this->setUser($user); $this->setKey($key); }
/** * @param string $field * @param string $operator * @param string|array $value ['min' => 1, 'max' => 10] for between operator */ public function __construct($field, $operator, $value) { Assertion::string($field); $this->field = $field; $this->value = $value; $this->operator = $operator; }
private function __construct($repositoryName) { Ensure::string($repositoryName); Ensure::notBlank($repositoryName); Ensure::regex($repositoryName, '/^[a-zA-Z0-9\\-]+\\/[a-zA-Z0-9\\-\\.]+$/'); $this->repositoryName = $repositoryName; }
/** * @param $name */ public function __construct($name) { Assertion::string($name, 'StreamName must be a string'); Assertion::notEmpty($name, 'StreamName must not be empty'); Assertion::maxLength($name, 200, 'StreamName should not be longer than 200 chars'); $this->name = $name; }
/** * @param string $text * @param CliMenu $subMenu * @param bool $disabled */ public function __construct($text, CliMenu $subMenu, $disabled = false) { Assertion::string($text); $this->text = $text; $this->subMenu = $subMenu; $this->disabled = $disabled; }
/** * @param $text */ public function __construct($text) { Assertion::string($text); Assertion::minLength($text, 1); Assertion::maxLength($text, 1000); $this->text = $text; }
/** * @param string $text * @param string $position */ public function __construct($text, $position = self::POSITION_CENTER) { Assertion::string($text); Assertion::inArray($position, [self::POSITION_CENTER, self::POSITION_RIGHT, self::POSITION_LEFT]); $this->text = $text; $this->position = $position; $this->artLength = max(array_map('mb_strlen', explode("\n", $text))); }
private function setType($type) { Assertion::string($type, 'Token type should be a string'); Assertion::startsWith($type, 'T_', 'Token type should start with T_'); Assertion::true(defined($type), 'Token type should be the name of a defined constant'); $this->type = $type; $this->code = constant($type); }
/** * @param string $title * * @throws \InvalidArgumentException * * @return static */ public function withTitle($title) { Assertion::string($title); Assertion::notBlank($title); $instance = clone $this; $instance->title = $title; return $instance; }
public function __invoke($value) : ValidationResult { Assertion::string($value); if (false === filter_var($value, FILTER_VALIDATE_EMAIL)) { return new ValidationResult(new ValidationError('error.email-address')); } return new ValidationResult(); }