本文整理汇总了PHP中IOHelper::cleanPath方法的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper::cleanPath方法的具体用法?PHP IOHelper::cleanPath怎么用?PHP IOHelper::cleanPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOHelper
的用法示例。
在下文中一共展示了IOHelper::cleanPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _resolveSourcePathToFolderId
/**
* Resolve a source path to it's folder ID by the source path and the matched source beginning.
*
* @param int $sourceId
* @param string $subpath
*
* @throws Exception
* @return mixed
*/
private function _resolveSourcePathToFolderId($sourceId, $subpath)
{
// Are we looking for a subfolder?
$subpath = is_string($subpath) ? trim($subpath, '/') : '';
if (strlen($subpath) === 0) {
// Get the root folder in the source
$folder = craft()->assets->getRootFolderBySourceId($sourceId);
// Make sure the root folder actually exists
if (!$folder) {
throw new Exception('Cannot find the target folder.');
}
} else {
// Prepare the path by parsing tokens and normalizing slashes.
try {
$renderedSubpath = craft()->templates->renderObjectTemplate($subpath, $this->element);
} catch (\Exception $e) {
throw new InvalidSubpathException($subpath);
}
// Did any of the tokens return null?
if (strlen($renderedSubpath) === 0 || trim($renderedSubpath, '/') != $renderedSubpath || strpos($renderedSubpath, '//') !== false) {
throw new InvalidSubpathException($subpath);
}
$subpath = IOHelper::cleanPath($renderedSubpath, craft()->config->get('convertFilenamesToAscii'));
$folder = craft()->assets->findFolder(array('sourceId' => $sourceId, 'path' => $subpath . '/'));
// Ensure that the folder exists
if (!$folder) {
// Start at the root, and, go over each folder in the path and create it if it's missing.
$parentFolder = craft()->assets->getRootFolderBySourceId($sourceId);
// Make sure the root folder actually exists
if (!$parentFolder) {
throw new Exception('Cannot find the target folder.');
}
$segments = explode('/', $subpath);
foreach ($segments as $segment) {
$folder = craft()->assets->findFolder(array('parentId' => $parentFolder->id, 'name' => $segment));
// Create it if it doesn't exist
if (!$folder) {
$folderId = $this->_createSubFolder($parentFolder, $segment);
$folder = craft()->assets->getFolderById($folderId);
}
// In case there's another segment after this...
$parentFolder = $folder;
}
}
}
return $folder->id;
}