本文整理汇总了PHP中Assetic\Asset\AssetInterface::getNamingConvention方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetInterface::getNamingConvention方法的具体用法?PHP AssetInterface::getNamingConvention怎么用?PHP AssetInterface::getNamingConvention使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assetic\Asset\AssetInterface
的用法示例。
在下文中一共展示了AssetInterface::getNamingConvention方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeAssetToFilesystem
/**
* @param string|AssetInterface $asset
* @param NULL|string $path
* @param bool $overwrite
*
* @throws Exceptions\InvalidArgumentException
* @throws Exceptions\WriterException
* @throws Exceptions\TargetPathNotSetException
*
* @return string
*/
private function writeAssetToFilesystem(AssetInterface $asset, $path = NULL, $overwrite = FALSE)
{
if ($path === NULL) {
// If target path is set explicit (by method parameter or asset targetPath).
if ($asset->getTargetPath() !== NULL) {
$path = $asset->getTargetPath();
} elseif ($asset instanceof AssetCollection && $asset->getNamingConvention() !== NULL) {
$path = $asset->getNamingConvention()->getPath($asset, $this->globalEnvironment ? $this->globalEnvironment->getHash() : "");
} else {
if ($asset instanceof AssetCollection) {
throw new TargetPathNotSetException("AssertWriter::writerAsset() Target path for asset collection \"{$asset->getName()}\" is NULL. You have to set \"namingConvention\" or directly \"targetPath\".");
} else {
/** @var AssetInterface $asset */
throw new TargetPathNotSetException("AssertWriter::writerAsset() Target path for asset is NULL. You have to set target path.");
}
}
}
$absolutePath = self::normalizePath(self::isPathAbsolute($path) ? $path : $this->targetDir . '/' . $path);
// File already exists?
if ($overwrite || !file_exists($absolutePath)) {
// Dir exits?
if (!file_exists($dir = dirname($absolutePath)) && !@mkdir($dir, 0777, TRUE)) {
throw new WriterException("Can not create dir: \"{$dir}\"");
}
// Is file writable?
if (!is_writable(dirname($absolutePath))) {
throw new WriterException("Can not write to file: \"{$absolutePath}\"");
}
$content = $asset->dump();
if (file_put_contents('safe://' . $absolutePath, $content) === FALSE) {
throw new WriterException("Error writing to file: \"{$absolutePath}\"");
}
}
return $absolutePath;
}