本文整理汇总了PHP中IOHelper::isFolderEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper::isFolderEmpty方法的具体用法?PHP IOHelper::isFolderEmpty怎么用?PHP IOHelper::isFolderEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOHelper
的用法示例。
在下文中一共展示了IOHelper::isFolderEmpty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isEmpty
/**
* @return mixed
*/
public function isEmpty()
{
if (!$this->_isEmpty) {
$this->_isEmpty = IOHelper::isFolderEmpty($this->getRealPath());
}
return $this->_isEmpty;
}
示例2: getTemplateFiles
public function getTemplateFiles()
{
$folderEmpty = true;
if (IOHelper::isFolderEmpty(craft()->path->getPluginsPath() . 'formbuilder2/templates/email/layouts')) {
throw new HttpException(404, Craft::t('Looks like you don\'t have any templates in your email/layouts folder.'));
} else {
$folderEmpty = false;
}
$fileList = IOHelper::getFolderContents(craft()->path->getPluginsPath() . 'formbuilder2/templates/email/layouts');
$files = [];
$filesModel = [];
if (!$folderEmpty) {
foreach ($fileList as $key => $file) {
$files[$key] = ['fileName' => IOHelper::getFileName($file, false), 'fileOriginalName' => IOHelper::getFileName($file), 'fileNameCleaned' => IOHelper::cleanFilename(IOHelper::getFileName($file, false)), 'fileExtension' => IOHelper::getExtension($file), 'filePath' => $file, 'fileContents' => IOHelper::getFileContents($file)];
$filesModel[] = FormBuilder2_FileModel::populateModel($files[$key]);
}
}
return $filesModel;
}
示例3: _cleanTempFiles
/**
* Remove any temp files and/or folders that might have been created.
*
* @param string $unzipFolder
* @param string $handle
*
* @return null
*/
private function _cleanTempFiles($unzipFolder, $handle)
{
$path = $handle == 'craft' ? craft()->path->getAppPath() : craft()->path->getPluginsPath() . $handle . '/';
// Get rid of all the .bak files/folders.
$filesToDelete = IOHelper::getFolderContents($path, true, ".*\\.bak\$");
// Now delete any files/folders that were marked for deletion in the manifest file.
$manifestData = UpdateHelper::getManifestData($unzipFolder, $handle);
if ($manifestData) {
foreach ($manifestData as $row) {
if (UpdateHelper::isManifestVersionInfoLine($row)) {
continue;
}
$rowData = explode(';', $row);
if ($rowData[1] == PatchManifestFileAction::Remove) {
if (UpdateHelper::isManifestLineAFolder($rowData[0])) {
$tempFilePath = UpdateHelper::cleanManifestFolderLine($rowData[0]);
} else {
$tempFilePath = $rowData[0];
}
$filesToDelete[] = $path . $tempFilePath;
}
// In case we did the whole app folder
if ($rowData[0][0] == '*') {
$filesToDelete[] = rtrim(IOHelper::normalizePathSeparators($path), '/') . '.bak/';
}
}
foreach ($filesToDelete as $fileToDelete) {
if (IOHelper::fileExists($fileToDelete)) {
if (IOHelper::isWritable($fileToDelete)) {
Craft::log('Deleting file: ' . $fileToDelete, LogLevel::Info, true);
IOHelper::deleteFile($fileToDelete, true);
// If that was the last file in this folder, nuke the folder.
if (IOHelper::isFolderEmpty(IOHelper::getFolderName($fileToDelete))) {
IOHelper::deleteFolder(IOHelper::getFolderName($fileToDelete));
}
}
} else {
if (IOHelper::folderExists($fileToDelete)) {
if (IOHelper::isWritable($fileToDelete)) {
Craft::log('Deleting .bak folder:' . $fileToDelete, LogLevel::Info, true);
IOHelper::clearFolder($fileToDelete, true);
IOHelper::deleteFolder($fileToDelete, true);
}
}
}
}
}
// Clear the temp folder.
IOHelper::clearFolder(craft()->path->getTempPath(), true);
}
示例4: add
/**
* @inheritDoc IZip::add()
*
* @param string $sourceZip
* @param string $pathToAdd
* @param string $basePath
* @param null $pathPrefix
*
* @return bool
*/
public function add($sourceZip, $pathToAdd, $basePath, $pathPrefix = null)
{
$zip = new \ZipArchive();
$zipContents = $zip->open($sourceZip);
if ($zipContents !== true) {
Craft::log('Unable to open zip file: ' . $sourceZip, LogLevel::Error);
return false;
}
if (IOHelper::fileExists($pathToAdd)) {
$folderContents = array($pathToAdd);
} else {
$folderContents = IOHelper::getFolderContents($pathToAdd, true);
}
foreach ($folderContents as $itemToZip) {
if (IOHelper::isReadable($itemToZip)) {
// Figure out the relative path we'll be adding to the zip.
$relFilePath = mb_substr($itemToZip, mb_strlen($basePath));
if ($pathPrefix) {
$pathPrefix = IOHelper::normalizePathSeparators($pathPrefix);
$relFilePath = $pathPrefix . $relFilePath;
}
if (IOHelper::folderExists($itemToZip)) {
if (IOHelper::isFolderEmpty($itemToZip)) {
$zip->addEmptyDir($relFilePath);
}
} elseif (IOHelper::fileExists($itemToZip)) {
// We can't use $zip->addFile() here but it's a terrible, horrible, POS method that's buggy on Windows.
$fileContents = IOHelper::getFileContents($itemToZip);
if (!$zip->addFromString($relFilePath, $fileContents)) {
Craft::log('There was an error adding the file ' . $itemToZip . ' to the zip: ' . $itemToZip, LogLevel::Error);
}
}
}
}
$zip->close();
return true;
}
示例5: add
/**
* Will add either a file or a folder to an existing zip file. If it is a folder, it will add the contents recursively.
*
* @param string $sourceZip The zip file to be added to.
* @param string $pathToAdd A file or a folder to add. If it is a folder, it will recursively add the contents of the folder to the zip.
* @param string $basePath The root path of the file(s) to be added that will be removed before adding.
* @param string $pathPrefix A path to be prepended to each file before it is added to the zip.
* @return bool
*/
public function add($sourceZip, $pathToAdd, $basePath, $pathPrefix = null)
{
$zip = new \PclZip($sourceZip);
if (IOHelper::fileExists($pathToAdd)) {
$folderContents = array($pathToAdd);
} else {
$folderContents = IOHelper::getFolderContents($pathToAdd, true);
}
$filesToAdd = array();
foreach ($folderContents as $itemToZip) {
if (IOHelper::isReadable($itemToZip)) {
if (IOHelper::folderExists($itemToZip) && IOHelper::isFolderEmpty($itemToZip) || IOHelper::fileExists($itemToZip)) {
$filesToAdd[] = $itemToZip;
}
}
}
if (!$pathPrefix) {
$pathPrefix = '';
}
$result = $zip->add($filesToAdd, PCLZIP_OPT_ADD_PATH, $pathPrefix, PCLZIP_OPT_REMOVE_PATH, $basePath);
if ($result == 0) {
Craft::log('Unable to add to zip file: ' . $sourceZip, LogLevel::Error);
return false;
}
return true;
}