string() public static method

public static string ( $value, $message = '' )
Esempio n. 1
0
 /**
  * Adds a participation to the data collector.
  *
  * @param string $testIdentifier It will look like "Qp0gahJ3RAO3DJ18b0XoUQ"
  * @param int $variationIndex
  * @throws InvalidArgumentException
  */
 public function addParticipation($testIdentifier, $variationIndex)
 {
     Assert::string($testIdentifier, 'Test identifier must be a string');
     Assert::integer($variationIndex, 'Variation index must be integer');
     Assert::greaterThan($variationIndex, -1, 'Variation index must be integer >= 0');
     $this->participations[$testIdentifier] = $variationIndex;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public static function create($body, FqsenResolver $resolver = null, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
 {
     Assert::string($body);
     Assert::allNotNull([$resolver, $descriptionFactory]);
     $parts = preg_split('/\\s+/Su', $body, 2);
     return new static($resolver->resolve($parts[0], $context), $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context));
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function convertNameToCode($name, $locale = 'en')
 {
     $names = Intl::getLocaleBundle()->getLocaleNames($locale);
     $code = array_search($name, $names, true);
     Assert::string($code, sprintf('Cannot find code for "%s" locale name', $name));
     return $code;
 }
Esempio n. 4
0
 public static function create($body)
 {
     Assert::string($body);
     $scope = preg_split('/(,?\\s+)/Su', $body);
     $scope = array_filter($scope);
     return new static($scope);
 }
Esempio n. 5
0
 /**
  * Creates a new tag that represents any unknown tag type.
  *
  * @param string             $body
  * @param string             $name
  * @param DescriptionFactory $descriptionFactory
  * @param Context            $context
  *
  * @return static
  */
 public static function create($body, $name = '', DescriptionFactory $descriptionFactory = null, Context $context = null)
 {
     Assert::string($body);
     Assert::stringNotEmpty($name);
     $description = $descriptionFactory && $body ? $descriptionFactory->create($body, $context) : null;
     return new static($name, $description);
 }
Esempio n. 6
0
 /**
  * @param string      $variableName
  * @param Type        $type
  * @param Description $description
  */
 public function __construct($variableName, Type $type = null, Description $description = null)
 {
     Assert::string($variableName);
     $this->variableName = $variableName;
     $this->type = $type;
     $this->description = $description;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
 {
     Assert::string($body);
     Assert::notNull($descriptionFactory);
     $parts = preg_split('/\\s+/Su', $body, 2);
     $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
     return new static($parts[0], $description);
 }
Esempio n. 8
0
 private function doDelete($name)
 {
     Assert::string($name, "Name must be a string. Got: %s");
     foreach ((yield \Amp\File\scandir($this->root . "/" . $name)) as $file) {
         (yield \Amp\File\unlink($this->root . "/" . $name . "/" . $file));
     }
     (yield \Amp\File\rmdir($this->root . "/" . $name));
 }
Esempio n. 9
0
 private function doDelete($token)
 {
     Assert::string($token, "Token must be a string. Got: %s");
     $path = $this->docroot . "/.well-known/acme-challenge/{$token}";
     $realpath = realpath($path);
     if ($realpath) {
         (yield \Amp\File\unlink($realpath));
     }
 }
Esempio n. 10
0
 public static function create($body)
 {
     Assert::string($body);
     $parts = preg_split('/(\\n+)/Su', $body, 2);
     if (!empty($parts[0])) {
         $group = array_shift($parts);
     }
     return new static($group);
 }
Esempio n. 11
0
 /**
  * @param string $variableName
  * @param Type $type
  * @param bool $isVariadic
  * @param Description $description
  */
 public function __construct($variableName, Type $type = null, $isVariadic = false, Description $description = null)
 {
     Assert::string($variableName);
     Assert::boolean($isVariadic);
     $this->variableName = $variableName;
     $this->type = $type;
     $this->isVariadic = $isVariadic;
     $this->description = $description;
 }
Esempio n. 12
0
 /**
  * Create a Serializer instance.
  *
  * @param int $indent The number of times the indent string is repeated.
  * @param string   $indentString    The string to indent the comment with.
  * @param bool     $indentFirstLine Whether to indent the first line.
  * @param int|null $lineLength The max length of a line or NULL to disable line wrapping.
  */
 public function __construct($indent = 0, $indentString = ' ', $indentFirstLine = true, $lineLength = null)
 {
     Assert::integer($indent);
     Assert::string($indentString);
     Assert::boolean($indentFirstLine);
     Assert::nullOrInteger($lineLength);
     $this->indent = $indent;
     $this->indentString = $indentString;
     $this->isFirstLineIndented = $indentFirstLine;
     $this->lineLength = $lineLength;
 }
Esempio n. 13
0
 /**
  * Creates a new package DTO.
  *
  * @param string $name          The package name.
  * @param string $installerName The name of the installer.
  * @param string $installPath   The absolute install path.
  * @param string $state         One of the STATE_* constants in this class.
  */
 public function __construct($name, $installerName, $installPath, $state)
 {
     Assert::stringNotEmpty($name, 'The package name must be a non-empty string. Got: %s');
     Assert::string($installerName, 'The installer name must be a string. Got: %s');
     Assert::stringNotEmpty($installPath, 'The install path must be a non-empty string. Got: %s');
     Assert::oneOf($state, self::$states, 'The package state must be one of %2$s. Got: %s');
     $this->name = $name;
     $this->installerName = $installerName;
     $this->installPath = $installPath;
     $this->state = $state;
 }
Esempio n. 14
0
 public static function create($body, Context $context = null)
 {
     Assert::string($body);
     $parts = preg_split('/(\\s+)/Su', $body, 1);
     if (!empty($parts[0])) {
         $key = array_shift($parts);
     } else {
         $key = null;
     }
     return new static($key);
 }
Esempio n. 15
0
 /**
  * Attempts to create a new Author object based on †he tag body.
  *
  * @param string $body
  *
  * @return static
  */
 public static function create($body)
 {
     Assert::string($body);
     $splitTagContent = preg_match('/^([^\\<]*)(?:\\<([^\\>]*)\\>)?$/u', $body, $matches);
     if (!$splitTagContent) {
         return null;
     }
     $authorName = trim($matches[1]);
     $email = isset($matches[2]) ? trim($matches[2]) : '';
     return new static($authorName, $email);
 }
Esempio n. 16
0
 /**
  * Creates a new command name.
  *
  * @param string   $string  The command name.
  * @param string[] $aliases The alias names.
  */
 public function __construct($string, array $aliases = array())
 {
     Assert::string($string, 'The command name must be a string. Got: %s');
     Assert::notEmpty($string, 'The command name must not be empty.');
     Assert::regex($string, '~^[a-zA-Z0-9\\-]+$~', 'The command name must contain letters, digits and hyphens only. Got: "%s"');
     Assert::allString($aliases, 'The command aliases must be strings. Got: %s');
     Assert::allNotEmpty($aliases, 'The command aliases must not be empty.');
     Assert::allRegex($aliases, '~^[a-zA-Z0-9\\-]+$~', 'The command aliases must contain letters, digits and hyphens only. Got: "%s"');
     $this->string = $string;
     $this->aliases = $aliases;
 }
Esempio n. 17
0
 /**
  * @param string|SortCode $sortCode
  * @param string          $accountNumber
  */
 public function __construct($sortCode, $accountNumber)
 {
     try {
         if (!$sortCode instanceof SortCode) {
             Assert::string($sortCode, 'Sort code must be a string or instance of SortCode');
             $sortCode = SortCode::create($sortCode);
         }
         Assert::string($accountNumber, 'Account number must be a string');
         Assert::regex($accountNumber, '{^(?:.*\\d.*){6}$}', 'Account number must contain at least 6 digits');
     } catch (\InvalidArgumentException $e) {
         throw E::wrap($e);
     }
     $this->sortCode = $sortCode;
     $this->accountNumber = preg_replace('{[^0-9]}', '', $accountNumber);
 }
Esempio n. 18
0
 public static function create($body, DescriptionFactory $description_factory = null, Context $context = null)
 {
     Assert::string($body);
     $field = null;
     $group = null;
     $type = null;
     $size = null;
     $optional = null;
     $default_value = null;
     $description = null;
     //Is the first part our group?
     if (preg_match('/^\\([^)]*\\)/', $body) !== 0) {
         $parts = preg_split('/\\)\\s*/', $body, 2);
         $group = substr($parts[0], 1);
         $body = $parts[1];
     }
     $parts = preg_split('/(\\s+)/Su', $body, null, PREG_SPLIT_DELIM_CAPTURE);
     //Is the first part our type?
     if (preg_match('/{([^{]+)(?:{([^}]+)})?}/', $parts[0], $matches) !== 0) {
         array_shift($parts);
         array_shift($parts);
         if (!empty($matches[1])) {
             $type = $matches[1];
         } else {
             $type = null;
         }
         if (!empty($matches[2])) {
             $size = $matches[2];
         } else {
             $size = null;
         }
     }
     $field = array_shift($parts);
     array_shift($parts);
     if (strpos($field, '?') === 0) {
         $optional = true;
         $field = substr($field, 1);
     } else {
         $optional = false;
     }
     if (strpos($field, '=') !== false) {
         list($field, $default_value) = preg_split('/=/', $field, 2);
     } else {
         $default_value = null;
     }
     $description = $description_factory->create(implode('', $parts), $context);
     return new static($field, $group, $type, $size, $optional, $default_value, $description);
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 public function sendMessage(ConversationInterface $conversation, PersonInterface $sender, $body)
 {
     Assert::string($body, '$body expected a string in Sender::sendMessage(). Got: %s');
     // Create the message
     $message = $this->createAndPersistMessage($conversation, $sender, $body);
     // Add the conversation persons links
     foreach ($conversation->getConversationPersons() as $conversationPerson) {
         $person = $conversationPerson->getPerson();
         $this->createAndPersistMessagePerson($message, $person, $person->getId() === $sender->getId());
     }
     // Flush the previously persisted entities
     $this->driver->flush();
     // Dispatch the event
     $this->dispatchMessageEvent($message);
     return $message;
 }
Esempio n. 20
0
 public static function create($body, DescriptionFactory $description_factory = null, Context $context = null)
 {
     Assert::string($body);
     $parts = preg_split('/(\\s+)/Su', $body, 3);
     if (!empty($parts[0])) {
         $var = array_shift($parts);
     }
     if (!empty($parts[0])) {
         $type = array_shift($parts);
     }
     if (!empty($parts[0])) {
         $description = $description_factory->create($parts[0], $context);
     } else {
         $description = null;
     }
     return new static($var, $type, $size, $description);
 }
Esempio n. 21
0
 /**
  * Creates instance of Image
  *
  * @param string $path Path to the image
  * @param string $link Url of the link
  * @param string $alt Alt text
  * @param string $title Title text
  *
  * @throws \InvalidArgumentException
  */
 public function __construct($path, $link = null, $alt = null, $title = null)
 {
     Assert::string($path, '$path must be a string');
     $this->path = $path;
     if (!is_null($link)) {
         Assert::string($link, '$link must be a string');
         $this->link = $link;
     }
     if (!is_null($alt)) {
         Assert::string($alt, '$alt must be a string');
         $this->alt = $alt;
     }
     if (!is_null($title)) {
         Assert::string($title, '$alt must be a string');
         $this->title = $title;
     }
 }
Esempio n. 22
0
/**
 * Resolves a server to a valid URI. If a valid shortcut is passed, it's resolved to the defined URI. If a URI without
 * protocol is passed, it will default to HTTPS.
 *
 * @param string $uri URI to resolve
 * @return string resolved URI
 */
function resolveServer($uri)
{
    Assert::string($uri, "URI must be a string. Got: %s");
    $shortcuts = ["letsencrypt" => "https://acme-v01.api.letsencrypt.org/directory", "letsencrypt:production" => "https://acme-v01.api.letsencrypt.org/directory", "letsencrypt:staging" => "https://acme-staging.api.letsencrypt.org/directory"];
    if (isset($shortcuts[$uri])) {
        return $shortcuts[$uri];
    }
    if (strpos($uri, "/") === false) {
        throw new InvalidArgumentException("Invalid server URI: " . $uri);
    }
    $protocol = substr($uri, 0, strpos($uri, "://"));
    if (!$protocol || $protocol === $uri) {
        return "https://{$uri}";
    } else {
        return $uri;
    }
}
Esempio n. 23
0
 /**
  * @param BankAccountInterface $bankAccount
  * @param string|SortCode      $sortCode
  * @param string               $accountNumber
  */
 public function __construct(BankAccountInterface $bankAccount, $sortCode, $accountNumber)
 {
     try {
         if (!$sortCode instanceof SortCode) {
             Assert::string($sortCode, 'Sort code must be a string or instance of SortCode');
             $sortCode = SortCode::create($sortCode);
         }
         Assert::string($accountNumber, 'Account number must be a string');
     } catch (\InvalidArgumentException $e) {
         throw E::wrap($e);
     }
     $this->bankAccount = $bankAccount;
     $this->sortCode = $sortCode;
     $this->accountNumber = preg_replace('{[^0-9]}', '', $accountNumber);
     if (self::LENGTH !== strlen($this->accountNumber)) {
         throw Exception\AccountNumberInvalidException::create($accountNumber);
     }
 }
Esempio n. 24
0
 /**
  * Turns a URL into a relative path.
  *
  * The result is a canonical path. This class is using functionality of Path class.
  *
  * @see Path
  *
  * @param string $url     A URL to make relative.
  * @param string $baseUrl A base URL.
  *
  * @return string
  *
  * @throws InvalidArgumentException If the URL and base URL does
  *                                  not match.
  */
 public static function makeRelative($url, $baseUrl)
 {
     Assert::string($url, 'The URL must be a string. Got: %s');
     Assert::string($baseUrl, 'The base URL must be a string. Got: %s');
     Assert::contains($baseUrl, '://', '%s is not an absolute Url.');
     list($baseHost, $basePath) = self::split($baseUrl);
     if (false === strpos($url, '://')) {
         if (0 === strpos($url, '/')) {
             $host = $baseHost;
         } else {
             $host = '';
         }
         $path = $url;
     } else {
         list($host, $path) = self::split($url);
     }
     if ('' !== $host && $host !== $baseHost) {
         throw new InvalidArgumentException(sprintf('The URL "%s" cannot be made relative to "%s" since their host names are different.', $host, $baseHost));
     }
     return Path::makeRelative($path, $basePath);
 }
Esempio n. 25
0
 public static function create($body, DescriptionFactory $description_factory = null, Context $context = null)
 {
     Assert::string($body);
     $field = null;
     $group = null;
     $type = null;
     $description = null;
     $parts = preg_split('/(\\s+)/Su', $body, 4, PREG_SPLIT_DELIM_CAPTURE);
     //Is the first part our group?
     if (preg_match('/\\([^)]+\\)/', $parts[0]) !== 0) {
         $group = substr(array_shift($parts), 1, -1);
         array_shift($parts);
     }
     //Is the first part our type?
     if (preg_match('/\\{[^}]+\\}/', $parts[0]) !== 0) {
         $type = substr(array_shift($parts), 1, -1);
         array_shift($parts);
     }
     $field = array_shift($parts);
     array_shift($parts);
     $description = $description_factory->create(implode('', $parts), $context);
     return new static($field, $group, $type, $description);
 }
Esempio n. 26
0
 public static function create($body)
 {
     Assert::string($body);
     $parts = explode('.', $body);
     if (!empty($parts[0])) {
         Assert::integerish($parts[0]);
         $major = (int) array_shift($parts);
     } else {
         $major = 0;
     }
     if (!empty($parts[0])) {
         Assert::integerish($parts[0]);
         $minor = (int) array_shift($parts);
     } else {
         $minor = 0;
     }
     if (!empty($parts[0])) {
         Assert::integerish($parts[0]);
         $patch = (int) array_shift($parts);
     } else {
         $patch = 0;
     }
     return new static($major, $minor, $patch);
 }
Esempio n. 27
0
 /**
  * @param string $recipient
  *
  * @throws /InvalidArgumentException
  */
 private function assertRecipientIsValid($recipient)
 {
     Assert::notEmpty($recipient, 'The recipient cannot be empty.');
     Assert::string($recipient, sprintf('The recipient must be a string, %s given.', gettype($recipient)));
     Assert::notEq(false, filter_var($recipient, FILTER_VALIDATE_EMAIL), 'Given recipient is not a valid email address.');
 }
Esempio n. 28
0
 /**
  * Returns an option by its long or short name.
  *
  * @param string $name        The long or short option name.
  * @param bool   $includeBase Whether to include options in the base format
  *                            in the search.
  *
  * @return Option The option.
  *
  * @throws NoSuchOptionException If the option with the given name does not
  *                               not exist.
  */
 public function getOption($name, $includeBase = true)
 {
     Assert::string($name, 'The option name must be a string. Got: %s');
     Assert::notEmpty($name, 'The option name must not be empty.');
     Assert::boolean($includeBase, 'The parameter $includeBase must be a boolean. Got: %s');
     if (isset($this->options[$name])) {
         return $this->options[$name];
     }
     if (isset($this->optionsByShortName[$name])) {
         return $this->optionsByShortName[$name];
     }
     if ($includeBase && $this->baseFormat) {
         return $this->baseFormat->getOption($name);
     }
     throw NoSuchOptionException::forOptionName($name);
 }
Esempio n. 29
0
 /**
  * {@inheritdoc}
  */
 public function setCurrencyCode($currencyCode)
 {
     Assert::string($currencyCode);
     $this->currencyCode = $currencyCode;
 }
Esempio n. 30
0
 /**
  * {@inheritdoc}
  */
 public function setBody($body)
 {
     Assert::string($body);
     $this->body = $body;
 }