本文整理匯總了PHP中Puli\Manager\Assert\Assert::true方法的典型用法代碼示例。如果您正苦於以下問題:PHP Assert::true方法的具體用法?PHP Assert::true怎麽用?PHP Assert::true使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Puli\Manager\Assert\Assert
的用法示例。
在下文中一共展示了Assert::true方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __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;
}
}
示例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;
}