当前位置: 首页>>代码示例>>PHP>>正文


PHP Assert::regex方法代码示例

本文整理汇总了PHP中Webmozart\Assert\Assert::regex方法的典型用法代码示例。如果您正苦于以下问题:PHP Assert::regex方法的具体用法?PHP Assert::regex怎么用?PHP Assert::regex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Webmozart\Assert\Assert的用法示例。


在下文中一共展示了Assert::regex方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * @param string $value
  */
 public static function create($value)
 {
     try {
         Assert::string($value, 'Value must be a string');
         Assert::regex($value, '{^(?:.*\\d.*){6}$}', 'Value must contain 6 digits');
     } catch (\InvalidArgumentException $e) {
         throw E::wrap($e);
     }
     return new self(preg_replace('{[^0-9]}', '', $value));
 }
开发者ID:cs278,项目名称:bank-modulus,代码行数:13,代码来源:SortCode.php

示例2: __construct

 /**
  * 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;
 }
开发者ID:webmozart,项目名称:console,代码行数:17,代码来源:CommandName.php

示例3: __construct

 /**
  * @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);
 }
开发者ID:cs278,项目名称:bank-modulus,代码行数:19,代码来源:BankAccount.php

示例4: setName

 /**
  * Sets the name of the application.
  *
  * @param string $name The application name.
  *
  * @return static The current instance.
  *
  * @see getName()
  */
 public function setName($name)
 {
     if (null !== $name) {
         Assert::string($name, 'The application name must be a string. Got: %s');
         Assert::notEmpty($name, 'The application name must not be empty.');
         Assert::regex($name, '~^[a-zA-Z0-9\\-]+$~', 'The application name must contain letters, numbers and hyphens only. Did you mean to call setDisplayName()?');
     }
     $this->name = $name;
     return $this;
 }
开发者ID:webmozart,项目名称:console,代码行数:19,代码来源:ApplicationConfig.php

示例5: assertShortNameValid

 private function assertShortNameValid($shortName, $flags)
 {
     if (null !== $shortName) {
         Assert::string($shortName, 'The short option name must be a string or null. Got: %s');
         Assert::notEmpty($shortName, 'The short option name must not be empty.');
         Assert::regex($shortName, '~^[a-zA-Z]$~', 'The short option name must be exactly one letter. Got: "%s"');
     }
     if (null === $shortName && $flags & self::PREFER_SHORT_NAME) {
         throw new InvalidArgumentException('The short option name must be given if the option flag PREFER_SHORT_NAME is selected.');
     }
 }
开发者ID:webmozart,项目名称:console,代码行数:11,代码来源:AbstractOption.php

示例6: assertShortAliasValid

 private function assertShortAliasValid($alias)
 {
     Assert::string($alias, 'An option alias must be a string or null. Got: %s');
     Assert::notEmpty($alias, 'An option alias must not be empty.');
     Assert::regex($alias, '~^[a-zA-Z]$~', 'A short option alias must be exactly one letter. Got: "%s"');
 }
开发者ID:webmozart,项目名称:console,代码行数:6,代码来源:CommandOption.php

示例7: __construct

 /**
  * Creates a new argument.
  *
  * @param string $name         The argument name
  * @param int    $flags        A bitwise combination of the flag constants.
  * @param string $description  A human-readable description of the argument.
  * @param mixed  $defaultValue The default value of the argument (must be
  *                             null for the flag {@link self::REQUIRED}).
  */
 public function __construct($name, $flags = 0, $description = null, $defaultValue = null)
 {
     Assert::string($name, 'The argument name must be a string. Got: %s');
     Assert::notEmpty($name, 'The argument name must not be empty.');
     Assert::startsWithLetter($name, 'The argument name must start with a letter.');
     Assert::regex($name, '~^[a-zA-Z0-9\\-]+$~', 'The argument name must contain letters, digits and hyphens only.');
     Assert::nullOrString($description, 'The argument description must be a string or null. Got: %s');
     Assert::nullOrNotEmpty($description, 'The argument description must not be empty.');
     $this->assertFlagsValid($flags);
     $this->addDefaultFlags($flags);
     $this->name = $name;
     $this->flags = $flags;
     $this->description = $description;
     $this->defaultValue = $this->isMultiValued() ? array() : null;
     if ($this->isOptional() || null !== $defaultValue) {
         $this->setDefaultValue($defaultValue);
     }
 }
开发者ID:webmozart,项目名称:console,代码行数:27,代码来源:Argument.php

示例8: setShortName

 /**
  * Sets the short option name of the command.
  *
  * The short name must consist of a single letter. The short name is
  * preceded by a single dash "-" when calling the command:
  *
  * ```
  * $ server -d localhost
  * ```
  *
  * In the example above, "d" is the short name of the "server --delete"
  * command.
  *
  * @param string $shortName The short option name.
  *
  * @return static The current instance.
  */
 public function setShortName($shortName)
 {
     if (null !== $shortName) {
         Assert::string($shortName, 'The short command name must be a string or null. Got: %s');
         Assert::notEmpty($shortName, 'The short command name must not be empty.');
         Assert::regex($shortName, '~^[a-zA-Z]$~', 'The short command name must contain a single letter. Got: %s');
     }
     // Reset short name preference when unsetting the short name
     if (null === $shortName && false === $this->longNamePreferred) {
         $this->longNamePreferred = null;
     }
     $this->shortName = $shortName;
     return $this;
 }
开发者ID:webmozart,项目名称:console,代码行数:31,代码来源:OptionCommandConfig.php

示例9: addAlias

 /**
  * Adds an alias name.
  *
  * An alias is an alternative name that can be used when calling the
  * command. Aliases are a useful way for migrating a command from one name
  * to another.
  *
  * Existing alias names are preserved.
  *
  * @param string $alias The alias name to add.
  *
  * @return static The current instance.
  *
  * @see addAliases(), setAliases(), getAlias()
  */
 public function addAlias($alias)
 {
     Assert::string($alias, 'The command alias must be a string. Got: %s');
     Assert::notEmpty($alias, 'The command alias must not be empty.');
     Assert::regex($alias, '~^[a-zA-Z0-9\\-]+$~', 'The command alias should contain letters, digits and hyphens only. Got: %s');
     $this->aliases[] = $alias;
     return $this;
 }
开发者ID:webmozart,项目名称:console,代码行数:23,代码来源:CommandConfig.php


注:本文中的Webmozart\Assert\Assert::regex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。