string() public static method

Assert that value is a string
public static string ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
return boolean
Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 /**
  * @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]);
 }
Exemplo n.º 4
0
 /**
  * @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;
 }
Exemplo n.º 5
0
 /**
  * @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;
 }
Exemplo n.º 6
0
 /**
  * @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;
 }
Exemplo n.º 7
0
 /**
  * Устанавливает описание 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;
 }
Exemplo n.º 8
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.º 9
0
 /**
  * @param string $value
  */
 public function __construct($value)
 {
     Assertion::string($value);
     Assertion::minLength($value, 1);
     Assertion::maxLength($value, 50);
     $this->value = strtolower($value);
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 /**
  * 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;
 }
Exemplo n.º 12
0
 /**
  * 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]);
 }
Exemplo n.º 13
0
 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);
     }
 }
Exemplo n.º 14
0
 /**
  * @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;
 }
Exemplo n.º 15
0
 /**
  * @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));
 }
Exemplo n.º 16
0
 /**
  * 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;
 }
Exemplo n.º 17
0
 private function assertConfig(array $config)
 {
     Assertion::keyExists($config, "dbname");
     Assertion::string($config['dbname']);
     Assertion::keyExists($config, "driver");
     Assertion::inArray($config["driver"], $this->supportedDrivers);
 }
Exemplo n.º 18
0
 /**
  * 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;
 }
Exemplo n.º 19
0
 public function __construct($templateId, $id)
 {
     Assertion::notEmpty($templateId);
     Assertion::string($id);
     $this->id = $id;
     $this->templateId = $templateId;
 }
Exemplo n.º 20
0
 public function __construct($name, $set)
 {
     Assertion::string($name);
     Assertion::boolean($set);
     $this->name = $name;
     $this->set = $set;
 }
Exemplo n.º 21
0
 /**
  * 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;
 }
Exemplo n.º 24
0
 /**
  * @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;
 }
Exemplo n.º 25
0
 /**
  * @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;
 }
Exemplo n.º 26
0
 /**
  * @param $text
  */
 public function __construct($text)
 {
     Assertion::string($text);
     Assertion::minLength($text, 1);
     Assertion::maxLength($text, 1000);
     $this->text = $text;
 }
Exemplo n.º 27
0
 /**
  * @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);
 }
Exemplo n.º 29
0
 /**
  * @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;
 }
Exemplo n.º 30
0
 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();
 }