本文整理匯總了PHP中Puli\Manager\Assert\Assert::string方法的典型用法代碼示例。如果您正苦於以下問題:PHP Assert::string方法的具體用法?PHP Assert::string怎麽用?PHP Assert::string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Puli\Manager\Assert\Assert
的用法示例。
在下文中一共展示了Assert::string方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
Assert::keyExists($options, 'rootDir', 'The "rootDir" option is missing.');
$options = array_replace(self::$defaultOptions, $options);
if (!isset($options['path'])) {
$options['path'] = $targetMethod->getClass()->getDirectory() . '/repository';
}
Assert::string($options['path'], 'The "path" option should be a string. Got: %s');
Assert::string($options['rootDir'], 'The "rootDir" option should be a string. Got: %s');
Assert::boolean($options['symlink'], 'The "symlink" option should be a boolean. Got: %s');
$path = Path::makeAbsolute($options['path'], $options['rootDir']);
$relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
$escPath = $relPath ? '__DIR__.' . var_export('/' . $relPath, true) : '__DIR__';
if ($relPath) {
$targetMethod->addBody(<<<EOF
if (!file_exists({$escPath})) {
mkdir({$escPath}, 0777, true);
}
EOF
);
}
$targetMethod->getClass()->addImport(new Import('Puli\\Repository\\FilesystemRepository'));
$targetMethod->addBody(sprintf('$%s = new FilesystemRepository(%s, %s);', $varName, $escPath, var_export($options['symlink'], true)));
}
示例2: add
/**
* Adds an attribute to the name.
*
* @param string $name The attribute name. Must start with a letter and
* contain letters, digits and hyphens only.
* @param string $value The attribute value. Any non-empty string is
* allowed.
*
* @see merge()
*/
public function add($name, $value)
{
Assert::string($name, 'The attribute name must be a string. Got: %s');
Assert::notEmpty($name, 'The attribute name must not be empty.');
Assert::startsWithLetter($name, 'The attribute name %s must start with a letter.');
Assert::true((bool) preg_match('~^[a-zA-Z][a-zA-Z0-9\\-]*$~', $name), sprintf('The attribute name must contain letters, numbers and hyphens only. Got: "%s"', $name));
Assert::string($value, 'The attribute value must be a string. Got: %s');
$this->attributes[$name] = $value;
}
示例3: __construct
/**
* Creates the mapping.
*
* @param string $glob A glob for resources in the repository.
* @param string $targetName The name of the install target.
* @param string $webPath The web path of the resource in the install
* target.
* @param Uuid $uuid The UUID of the mapping.
*/
public function __construct($glob, $targetName, $webPath, Uuid $uuid = null)
{
Assert::stringNotEmpty($glob, 'The glob must be a non-empty string. Got: %s');
Assert::stringNotEmpty($targetName, 'The target name must be a non-empty string. Got: %s');
Assert::string($webPath, 'The web path must be a string. Got: %s');
$this->uuid = $uuid ?: Uuid::uuid4();
$this->glob = $glob;
$this->targetName = $targetName;
$this->webPath = '/' . trim($webPath, '/');
}
示例4: __construct
/**
* Creates the mapping.
*
* @param string $glob A glob for resources in the repository.
* @param string $serverName The name of the asset server.
* @param string $serverPath The path of the resource in the document root
* of the server.
* @param Uuid $uuid The UUID of the mapping.
*/
public function __construct($glob, $serverName, $serverPath, Uuid $uuid = null)
{
Assert::stringNotEmpty($glob, 'The glob must be a non-empty string. Got: %s');
Assert::stringNotEmpty($serverName, 'The server name must be a non-empty string. Got: %s');
Assert::string($serverPath, 'The public path must be a string. Got: %s');
$this->uuid = $uuid ?: Uuid::uuid4();
$this->glob = $glob;
$this->serverName = $serverName;
$this->serverPath = '/' . trim($serverPath, '/');
}
示例5: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
$options = array_replace(self::$defaultOptions, $options);
Assert::string($options['host'], 'The host must be a string. Got: %s');
Assert::integer($options['port'], 'The port must be an integer. Got: %s');
$escHost = var_export($options['host'], true);
$escPort = var_export($options['port'], true);
$targetMethod->getClass()->addImports(array(new Import('Redis'), new Import('Webmozart\\KeyValueStore\\PhpRedisStore')));
$targetMethod->addBody(<<<EOF
\$client = new Redis();
\$client->connect({$escHost}, {$escPort});
\${$varName} = new PhpRedisStore(\$client);
EOF
);
}
示例6: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
Assert::keyExists($options, 'bucket', 'The "bucket" option is missing.');
$options = array_replace(self::$defaultOptions, $options);
Assert::string($options['bucket'], 'The bucket must be a string. Got: %s');
Assert::string($options['host'], 'The host must be a string. Got: %s');
Assert::integer($options['port'], 'The port must be an integer. Got: %s');
$escBucket = var_export($options['bucket'], true);
$escHost = var_export($options['host'], true);
$escPort = var_export($options['port'], true);
$targetMethod->getClass()->addImports(array(new Import('Basho\\Riak\\Riak'), new Import('Webmozart\\KeyValueStore\\RiakStore')));
$targetMethod->addBody(<<<EOF
\$client = new Riak({$escHost}, {$escPort});
\${$varName} = new RiakStore({$escBucket}, \$client);
EOF
);
}
示例7: getBindingType
/**
* {@inheritdoc}
*/
public function getBindingType($typeName, $packageName)
{
Assert::string($typeName, 'The type name must be a string. Got: %s');
Assert::string($packageName, 'The package name must be a string. Got: %s');
$this->assertPackagesLoaded();
if (!$this->typeDescriptors->contains($typeName, $packageName)) {
throw NoSuchTypeException::forTypeName($typeName);
}
return $this->typeDescriptors->get($typeName, $packageName);
}
示例8: getTypeDescriptor
/**
* {@inheritdoc}
*/
public function getTypeDescriptor($typeName, $moduleName)
{
Assert::string($typeName, 'The type name must be a string. Got: %s');
Assert::string($moduleName, 'The module name must be a string. Got: %s');
$this->assertModulesLoaded();
if (!$this->typeDescriptors->contains($typeName, $moduleName)) {
throw NoSuchTypeException::forTypeName($typeName);
}
return $this->typeDescriptors->get($typeName, $moduleName);
}
示例9: hasPathMapping
/**
* {@inheritdoc}
*/
public function hasPathMapping($repositoryPath, $packageName)
{
Assert::string($repositoryPath, 'The repository path must be a string. Got: %s');
Assert::string($packageName, 'The package name must be a string. Got: %s');
$this->assertMappingsLoaded();
return $this->mappings->contains($repositoryPath, $packageName);
}
示例10: hasModule
/**
* {@inheritdoc}
*/
public function hasModule($name)
{
Assert::string($name, 'The module name must be a string. Got: %s');
$this->assertModulesLoaded();
return $this->modules->contains($name);
}
示例11: hasPackage
/**
* {@inheritdoc}
*/
public function hasPackage($name)
{
Assert::string($name, 'The package name must be a string. Got: %s');
$this->assertPackagesLoaded();
return $this->packages->contains($name);
}
示例12: setVersion
/**
* Sets the version of the module file.
*
* @param string $version The module file version.
*/
public function setVersion($version)
{
Assert::string($version, 'The module file version must be a string. Got: %s');
Assert::regex($version, '~^\\d\\.\\d$~', 'The module file version must have the format "<digit>.<digit>". Got: %s</digit>');
$this->version = $version;
}