本文整理汇总了PHP中Puli\Manager\Assert\Assert类的典型用法代码示例。如果您正苦于以下问题:PHP Assert类的具体用法?PHP Assert怎么用?PHP Assert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Assert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Adds support for interceptors to an atomic operation.
*
* @param AtomicOperation $operation The operation.
* @param OperationInterceptor|OperationInterceptor[] $interceptors The interceptor(s).
*/
public function __construct(AtomicOperation $operation, $interceptors)
{
$interceptors = is_array($interceptors) ? $interceptors : array($interceptors);
Assert::allIsInstanceOf($interceptors, __NAMESPACE__ . '\\OperationInterceptor');
$this->operation = $operation;
$this->interceptors = $interceptors;
}
示例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(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" : ''));
}
示例3: 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)));
}
示例4: 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));
}
}
示例5: fromJson
/**
* {@inheritdoc}
*/
public function fromJson($jsonData, array $options = array())
{
Assert::isInstanceOf($jsonData, 'stdClass');
$moduleFile = new ModuleFile(null, isset($options['path']) ? $options['path'] : null);
$this->addJsonToModuleFile($jsonData, $moduleFile);
return $moduleFile;
}
示例6: __construct
/**
* Creates the environment.
*
* @param string|null $homeDir The path to the home
* directory or `null` if
* none exists.
* @param string $rootDir The path to the project's
* root directory.
* @param Config $config The configuration.
* @param RootPackageFile $rootPackageFile The root package file.
* @param ConfigFile $configFile The configuration file or
* `null` if none exists.
* @param EventDispatcherInterface $dispatcher The event dispatcher.
*/
public function __construct($homeDir, $rootDir, Config $config, RootPackageFile $rootPackageFile, ConfigFile $configFile = null, EventDispatcherInterface $dispatcher = null)
{
Assert::directory($rootDir, 'The root directory %s is not a directory.');
parent::__construct($homeDir, $config, $configFile, $dispatcher);
$this->rootDir = Path::canonicalize($rootDir);
$this->rootPackageFile = $rootPackageFile;
}
示例7: __construct
/**
* Creates a new package.
*
* @param PackageFile|null $packageFile The package file or `null` if the
* package file could not be loaded.
* @param string $installPath The absolute install path.
* @param InstallInfo|null $installInfo The install info of this package.
* @param Exception[] $loadErrors The errors that happened during
* loading of the package, if any.
*/
public function __construct(PackageFile $packageFile = null, $installPath, InstallInfo $installInfo = null, array $loadErrors = array())
{
Assert::absoluteSystemPath($installPath);
Assert::true($packageFile || $loadErrors, 'The load errors must be passed if the package file is null.');
Assert::allIsInstanceOf($loadErrors, 'Exception');
// If a package name was set during installation, that name wins over
// the predefined name in the puli.json file (if any)
$this->name = $installInfo && null !== $installInfo->getPackageName() ? $installInfo->getPackageName() : ($packageFile ? $packageFile->getPackageName() : null);
if (null === $this->name) {
$this->name = $this->getDefaultName();
}
// The path is stored both here and in the install info. While the
// install info contains the path as it is stored in the install file
// (i.e. relative or absolute), the install path of the package is
// always an absolute path.
$this->installPath = $installPath;
$this->installInfo = $installInfo;
$this->packageFile = $packageFile;
$this->loadErrors = $loadErrors;
if (!file_exists($installPath)) {
$this->state = PackageState::NOT_FOUND;
} elseif (count($loadErrors) > 0) {
$this->state = PackageState::NOT_LOADABLE;
} else {
$this->state = PackageState::ENABLED;
}
}
示例8: __construct
/**
* Creates the context.
*
* @param string|null $homeDir The path to the home directory
* or `null` if none exists.
* @param Config $config The configuration.
* @param ConfigFile $configFile The configuration file or
* `null` if none exists.
* @param EventDispatcherInterface $dispatcher The event dispatcher.
*/
public function __construct($homeDir, Config $config, ConfigFile $configFile = null, EventDispatcherInterface $dispatcher = null)
{
Assert::nullOrDirectory($homeDir, 'The home directory %s is not a directory.');
$this->homeDir = $homeDir ? Path::canonicalize($homeDir) : null;
$this->config = $config;
$this->dispatcher = $dispatcher ?: new EventDispatcher();
$this->configFile = $configFile;
}
示例9: __construct
/**
* Creates a new configuration file.
*
* @param string|null $path The path where the configuration file is stored
* or `null` if this configuration is not stored
* on the file system.
* @param Config $baseConfig The configuration that the configuration will
* inherit its values from.
*
* @throws InvalidArgumentException If the path is not a string or empty.
*/
public function __construct($path = null, Config $baseConfig = null)
{
Assert::nullOrString($path, 'The path to the configuration file should be a string or null. Got: %s');
Assert::nullOrNotEmpty($path, 'The path to the configuration file should not be empty.');
// Inherit from default configuration
$this->config = new Config($baseConfig);
$this->path = $path;
}
示例10: 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);
$path = Path::makeAbsolute($options['path'], $options['rootDir']);
$relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
$targetMethod->getClass()->addImport(new Import('Webmozart\\KeyValueStore\\JsonFileStore'));
$targetMethod->addBody(sprintf('$%s = new JsonFileStore(%s, %s);', $varName, '__DIR__.' . var_export('/' . $relPath, true), $options['cache'] ? 'true' : 'false'));
}
示例11: __construct
/**
* Creates the context.
*
* @param string|null $homeDir The path to the
* home directory or
* `null` if none
* exists.
* @param string $rootDir The path to the
* project's root
* directory.
* @param Config $config The configuration.
* @param RootModuleFile $rootModuleFile The root module
* file.
* @param ConfigFile|null $configFile The configuration
* file or `null` if
* none exists.
* @param EventDispatcherInterface|null $dispatcher The event
* dispatcher.
* @param string $env The environment
* that Puli is
* running in.
*/
public function __construct($homeDir, $rootDir, Config $config, RootModuleFile $rootModuleFile, ConfigFile $configFile = null, EventDispatcherInterface $dispatcher = null, $env = Environment::DEV)
{
Assert::directory($rootDir, 'The root directory %s is not a directory.');
Assert::oneOf($env, Environment::all(), 'The environment must be one of: %2$s. Got: %s');
parent::__construct($homeDir, $config, $configFile, $dispatcher);
$this->rootDir = Path::canonicalize($rootDir);
$this->rootModuleFile = $rootModuleFile;
$this->env = $env;
}
示例12: 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;
}
示例13: __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, '/');
}
示例14: __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, '/');
}
示例15: __construct
/**
* Creates a new migration manager.
*
* @param JsonMigration[] $migrations
*/
public function __construct(array $migrations)
{
Assert::allIsInstanceOf($migrations, __NAMESPACE__ . '\\JsonMigration');
foreach ($migrations as $migration) {
$this->migrationsByOriginVersion[$migration->getOriginVersion()] = $migration;
$this->migrationsByTargetVersion[$migration->getTargetVersion()] = $migration;
}
uksort($this->migrationsByOriginVersion, 'version_compare');
uksort($this->migrationsByTargetVersion, 'version_compare');
}