本文整理汇总了PHP中Webmozart\Assert\Assert::allString方法的典型用法代码示例。如果您正苦于以下问题:PHP Assert::allString方法的具体用法?PHP Assert::allString怎么用?PHP Assert::allString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Webmozart\Assert\Assert
的用法示例。
在下文中一共展示了Assert::allString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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;
}
示例2: join
/**
* Joins two or more path strings.
*
* The result is a canonical path.
*
* @param string[]|string $paths Path parts as parameters or array.
*
* @return string The joint path.
*
* @since 2.0 Added method.
*/
public static function join($paths)
{
if (!is_array($paths)) {
$paths = func_get_args();
}
Assert::allString($paths, 'The paths must be strings. Got: %s');
$finalPath = null;
$wasScheme = false;
foreach ($paths as $path) {
$path = (string) $path;
if ('' === $path) {
continue;
}
if (null === $finalPath) {
// For first part we keep slashes, like '/top', 'C:\' or 'phar://'
$finalPath = $path;
$wasScheme = strpos($path, '://') !== false;
continue;
}
// Only add slash if previous part didn't end with '/' or '\'
if (!in_array(substr($finalPath, -1), array('/', '\\'))) {
$finalPath .= '/';
}
// If first part included a scheme like 'phar://' we allow current part to start with '/', otherwise trim
$finalPath .= $wasScheme ? $path : ltrim($path, '/');
$wasScheme = false;
}
if (null === $finalPath) {
return '';
}
return self::canonicalize($finalPath);
}