本文整理匯總了PHP中Puli\Manager\Assert\Assert::boolean方法的典型用法代碼示例。如果您正苦於以下問題:PHP Assert::boolean方法的具體用法?PHP Assert::boolean怎麽用?PHP Assert::boolean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Puli\Manager\Assert\Assert
的用法示例。
在下文中一共展示了Assert::boolean方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
$options = array_replace_recursive(self::$defaultOptions, $options);
if (!isset($options['path'])) {
$options['path'] = $targetMethod->getClass()->getDirectory() . '/path-mappings.json';
}
Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
Assert::boolean($options['optimize'], 'The "optimize" option should be a boolean. Got: %s');
Assert::isArray($options['change-stream'], 'The "change-stream" option should be an array. Got: %s');
$path = Path::makeAbsolute($options['path'], $options['root-dir']);
$relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
$relBaseDir = Path::makeRelative($options['root-dir'], $targetMethod->getClass()->getDirectory());
$escPath = '__DIR__.' . var_export('/' . $relPath, true);
$escBaseDir = $relBaseDir ? '__DIR__.' . var_export('/' . $relBaseDir, true) : '__DIR__';
if ($options['optimize']) {
$streamGenerator = $generatorRegistry->getServiceGenerator(GeneratorRegistry::CHANGE_STREAM, $options['change-stream']['type']);
$streamOptions = $options['change-stream'];
$streamOptions['root-dir'] = $options['root-dir'];
$streamGenerator->generateNewInstance('stream', $targetMethod, $generatorRegistry, $streamOptions);
$targetMethod->getClass()->addImport(new Import('Puli\\Repository\\OptimizedJsonRepository'));
$targetMethod->addBody(sprintf('$%s = new OptimizedJsonRepository(%s, %s, false, $stream);', $varName, $escPath, $escBaseDir));
} else {
$targetMethod->getClass()->addImport(new Import('Puli\\Repository\\JsonRepository'));
$targetMethod->addBody(sprintf('$%s = new JsonRepository(%s, %s, true);', $varName, $escPath, $escBaseDir));
}
}
示例3: generateNewInstance
/**
* {@inheritdoc}
*/
public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
{
Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
$options = array_replace(self::$defaultOptions, $options);
Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
Assert::boolean($options['serialize-strings'], 'The "serialize-strings" option should be a boolean. Got: %s');
Assert::boolean($options['serialize-arrays'], 'The "serialize-arrays" option should be a boolean. Got: %s');
Assert::boolean($options['escape-slash'], 'The "escape-slash" option should be a boolean. Got: %s');
Assert::boolean($options['pretty-print'], 'The "pretty-print" option should be a boolean. Got: %s');
$path = Path::makeAbsolute($options['path'], $options['root-dir']);
$relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
$flags = array();
if (!$options['serialize-strings']) {
$flags[] = 'JsonFileStore::NO_SERIALIZE_STRINGS';
}
if (!$options['serialize-arrays']) {
$flags[] = 'JsonFileStore::NO_SERIALIZE_ARRAYS';
}
if (!$options['serialize-arrays']) {
$flags[] = 'JsonFileStore::NO_ESCAPE_SLASH';
}
if ($options['pretty-print']) {
$flags[] = 'JsonFileStore::PRETTY_PRINT';
}
$targetMethod->getClass()->addImport(new Import('Webmozart\\KeyValueStore\\JsonFileStore'));
$targetMethod->addBody(sprintf('$%s = new JsonFileStore(%s%s%s);', $varName, $flags ? "\n " : '', '__DIR__.' . var_export('/' . $relPath, true), $flags ? ",\n " . implode("\n | ", $flags) . "\n" : ''));
}
示例4: markDuplicate
/**
* Marks or unmarks the type as duplicate.
*
* The method {@link load()} needs to be called before calling this method,
* otherwise an exception is thrown.
*
* @param bool $duplicate Whether or not the type is a duplicate.
*
* @throws NotLoadedException If the descriptor is not loaded.
*/
public function markDuplicate($duplicate)
{
Assert::boolean($duplicate);
if (null === $this->state) {
throw new NotLoadedException('The type descriptor is not loaded.');
}
$this->state = $duplicate ? BindingTypeState::DUPLICATE : BindingTypeState::ENABLED;
}
示例5: findConfigKeys
/**
* {@inheritdoc}
*/
public function findConfigKeys(Expression $expr, $includeFallback = false, $includeUnset = false, $raw = true)
{
Assert::boolean($includeFallback, 'The argument $includeFallback must be a boolean.');
Assert::boolean($includeUnset, 'The argument $includeUnset must be a boolean.');
$values = array();
foreach ($this->getConfigKeys($includeFallback, $includeUnset, $raw) as $key => $value) {
if ($expr->evaluate($key)) {
$values[$key] = $value;
}
}
return $values;
}