本文整理汇总了PHP中Webmozart\Assert\Assert::stringNotEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP Assert::stringNotEmpty方法的具体用法?PHP Assert::stringNotEmpty怎么用?PHP Assert::stringNotEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Webmozart\Assert\Assert
的用法示例。
在下文中一共展示了Assert::stringNotEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* {@inheritdoc}
*/
public static function create($body, TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
{
Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
$parts = preg_split('/(\\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$type = null;
$variableName = '';
$isVariadic = false;
// if the first item that is encountered is not a variable; it is a type
if (isset($parts[0]) && strlen($parts[0]) > 0 && $parts[0][0] !== '$') {
$type = $typeResolver->resolve(array_shift($parts), $context);
array_shift($parts);
}
// if the next item starts with a $ or ...$ it must be the variable name
if (isset($parts[0]) && strlen($parts[0]) > 0 && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')) {
$variableName = array_shift($parts);
array_shift($parts);
if (substr($variableName, 0, 3) === '...') {
$isVariadic = true;
$variableName = substr($variableName, 3);
}
if (substr($variableName, 0, 1) === '$') {
$variableName = substr($variableName, 1);
}
}
$description = $descriptionFactory->create(implode('', $parts), $context);
return new static($variableName, $type, $isVariadic, $description);
}
示例2: create
/**
* {@inheritdoc}
*/
public static function create($body, TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, Context $context = null)
{
Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
// 1. none or more whitespace
// 2. optionally the keyword "static" followed by whitespace
// 3. optionally a word with underscores followed by whitespace : as
// type for the return value
// 4. then optionally a word with underscores followed by () and
// whitespace : as method name as used by phpDocumentor
// 5. then a word with underscores, followed by ( and any character
// until a ) and whitespace : as method name with signature
// 6. any remaining text : as description
if (!preg_match('/^
# Static keyword
# Declares a static method ONLY if type is also present
(?:
(static)
\\s+
)?
# Return type
(?:
([\\w\\|_\\\\]+)
\\s+
)?
# Legacy method name (not captured)
(?:
[\\w_]+\\(\\)\\s+
)?
# Method name
([\\w\\|_\\\\]+)
# Arguments
\\(([^\\)]*)\\)
\\s*
# Description
(.*)
$/sux', $body, $matches)) {
return null;
}
list(, $static, $returnType, $methodName, $arguments, $description) = $matches;
$static = $static === 'static';
$returnType = $typeResolver->resolve($returnType, $context);
$description = $descriptionFactory->create($description, $context);
$arguments = explode(',', $arguments);
foreach ($arguments as &$argument) {
$argument = explode(' ', trim($argument));
if ($argument[0][0] === '$') {
$argumentName = substr($argument[0], 1);
$argumentType = new Void();
} else {
$argumentType = $typeResolver->resolve($argument[0], $context);
$argumentName = '';
if (isset($argument[1])) {
$argumentName = substr($argument[1], 1);
}
}
$argument = ['name' => $argumentName, 'type' => $argumentType];
}
return new static($methodName, $arguments, $returnType, $static, $description);
}
示例3: undefineType
/**
* {@inheritdoc}
*/
public function undefineType($typeName)
{
Assert::stringNotEmpty($typeName, 'The type name must be a non-empty string. Got: %s');
$this->removeBindingsByType($typeName);
unset($this->types[$typeName]);
unset($this->typeIndex[$typeName]);
}
示例4: create
/**
* 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);
}
示例5: __construct
/**
* Creates a new version list.
*
* @param string $path The Puli path.
* @param PuliResource[] $versions The versions of the resource, starting
* with the first.
*/
public function __construct($path, array $versions)
{
Assert::stringNotEmpty($path, 'The Puli path must be a non-empty string. Got: %s');
Assert::allIsInstanceOf($versions, 'Puli\\Repository\\Api\\Resource\\PuliResource');
Assert::greaterThanEq(count($versions), 1, 'Expected at least one version.');
$this->path = $path;
$this->versions = array_values($versions);
}
示例6: __construct
/**
* Creates a new binding.
*
* You can pass parameters that have been defined for the type. If you pass
* unknown parameters, or if a required parameter is missing, an exception
* is thrown.
*
* All parameters that you do not set here will receive the default values
* set for the parameter.
*
* @param string $typeName The name of the type to bind against.
* @param array $parameterValues The values of the parameters defined
* for the type.
*
* @throws NoSuchParameterException If an invalid parameter was passed.
* @throws MissingParameterException If a required parameter was not passed.
*/
public function __construct($typeName, array $parameterValues = array())
{
Assert::stringNotEmpty($typeName, 'The type name must be a non-empty string. Got: %s');
ksort($parameterValues);
$this->typeName = $typeName;
$this->userParameterValues = $parameterValues;
$this->parameterValues = $parameterValues;
}
示例7: __construct
/**
* Creates a new return value.
*
* @param string $value The value as source code.
* @param string $type The type shown in the doc block.
* @param string $description The doc block description.
*/
public function __construct($value, $type = 'mixed', $description = null)
{
Assert::stringNotEmpty($value, 'The return value must be a non-empty string. Got: %s');
Assert::stringNotEmpty($type, 'The return value type must be a non-empty string. Got: %s');
Assert::nullOrStringNotEmpty($description, 'The return value description must be a non-empty string or null. Got: %s');
$this->value = $value;
$this->type = $type;
$this->description = $description;
}
示例8: resolvePath
/**
* Return the path with the basePath prefix
* if it has been set.
*
* @param string $path
*
* @return string
*/
protected function resolvePath($path)
{
Assert::stringNotEmpty($path, 'The path must be a non-empty string. Got: %s');
Assert::startsWith($path, '/', 'The path %s is not absolute.');
if ($this->basePath) {
$path = $this->basePath . $path;
}
$path = Path::canonicalize($path);
return $path;
}
示例9: __construct
/**
* Creates the violation.
*
* @param int $code The violation code. One of the constants
* defined in this class.
* @param mixed $invalidValue The value that caused this violation.
* @param string $installerName The name of the validated installer.
* @param string|null $parameterName The name of the validated installer
* parameter or `null` if this is a generic
* error.
*/
public function __construct($code, $invalidValue, $installerName, $parameterName = null)
{
Assert::oneOf($code, self::$codes, 'The violation code %s is not valid.');
Assert::stringNotEmpty($installerName, 'The installer name must be a non-empty string. Got: %s');
Assert::nullOrStringNotEmpty($parameterName, 'The parameter name must be a non-empty string or null. Got: %s');
$this->code = $code;
$this->installerName = $installerName;
$this->parameterName = $parameterName;
$this->invalidValue = $invalidValue;
}
示例10: __construct
/**
* 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;
}
示例11: __construct
/**
* @param Key $source
* @param string $key
* @param int $bits
* @param int $type
* @param array $details
*/
public function __construct(Key $source, $key, $bits, $type, array $details = [])
{
Assert::stringNotEmpty($key, __CLASS__ . '::$key expected a non empty string. Got: %s');
Assert::integer($bits, __CLASS__ . '::$bits expected an integer. Got: %s');
Assert::oneOf($type, [OPENSSL_KEYTYPE_RSA, OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH, OPENSSL_KEYTYPE_EC], __CLASS__ . '::$type expected one of: %2$s. Got: %s');
$this->source = $source;
$this->key = $key;
$this->bits = $bits;
$this->type = $type;
$this->details = $details;
}
示例12: __construct
/**
* Creates a new parameter.
*
* @param string $name The parameter name.
* @param int $flags A bitwise combination of the flag constants
* in this class.
* @param mixed $defaultValue The parameter's default value.
*/
public function __construct($name, $flags = self::OPTIONAL, $defaultValue = null)
{
Assert::stringNotEmpty($name, 'The parameter name must be a non-empty string. Got: %s');
Assert::startsWithLetter($name, 'The parameter name must start with a letter. Got: %s');
Assert::nullOrInteger($flags, 'The parameter "$flags" must be an integer or null. Got: %s');
if ($flags & self::REQUIRED && null !== $defaultValue) {
throw new RuntimeException('Required parameters must not have default values.');
}
$this->name = $name;
$this->flags = $flags;
$this->defaultValue = $defaultValue;
}
示例13: __construct
/**
* Creates a new type.
*
* @param string $name The name of the type.
* @param BindingParameter[] $parameters The parameters that can be set
* during binding.
*/
public function __construct($name, array $parameters = array())
{
Assert::stringNotEmpty($name, 'The type name must be a non-empty string. Got: %s');
Assert::startsWithLetter($name, 'The type name must start with a letter. Got: %s');
Assert::allIsInstanceOf($parameters, 'Puli\\Discovery\\Api\\Binding\\BindingParameter');
$this->name = $name;
foreach ($parameters as $parameter) {
$this->parameters[$parameter->getName()] = $parameter;
}
// Sort to facilitate comparison
ksort($this->parameters);
}
示例14: __construct
/**
* @param string $domain
* @param string $type
* @param string $url
* @param string $token
* @param string $payload
*/
public function __construct($domain, $type, $url, $token, $payload)
{
Assert::stringNotEmpty($domain, 'Challenge::$domain expected a non-empty string. Got: %s');
Assert::stringNotEmpty($type, 'Challenge::$type expected a non-empty string. Got: %s');
Assert::stringNotEmpty($url, 'Challenge::$url expected a non-empty string. Got: %s');
Assert::stringNotEmpty($token, 'Challenge::$token expected a non-empty string. Got: %s');
Assert::stringNotEmpty($payload, 'Challenge::$payload expected a non-empty string. Got: %s');
$this->domain = $domain;
$this->type = $type;
$this->url = $url;
$this->token = $token;
$this->payload = $payload;
}
示例15: __construct
/**
* Creates a new type.
*
* @param string $name The name of the type.
* @param string $bindingClass The class name of the accepted
* bindings.
* @param BindingParameter[] $parameters The parameters that can be set
* for a binding.
*/
public function __construct($name, $bindingClass, array $parameters = array())
{
Assert::stringNotEmpty($name, 'The type name must be a non-empty string. Got: %s');
Assert::allIsInstanceOf($parameters, 'Puli\\Discovery\\Api\\Type\\BindingParameter');
if (!class_exists($bindingClass) && !interface_exists($bindingClass)) {
throw new InvalidArgumentException(sprintf('The binding class "%s" is neither a class nor an ' . 'interface name. Is there a typo?', $bindingClass));
}
$this->name = $name;
$this->acceptedBindingClass = $bindingClass;
foreach ($parameters as $parameter) {
$this->parameters[$parameter->getName()] = $parameter;
}
// Sort to facilitate comparison
ksort($this->parameters);
}