本文整理汇总了PHP中IOHelper::isWritable方法的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper::isWritable方法的具体用法?PHP IOHelper::isWritable怎么用?PHP IOHelper::isWritable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOHelper
的用法示例。
在下文中一共展示了IOHelper::isWritable方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isWritable
/**
* @return mixed
*/
public function isWritable()
{
if (!$this->_isWritable) {
$this->_isWritable = IOHelper::isWritable($this->getRealPath());
}
return $this->_isWritable;
}
示例2: onBeforeInstall
public function onBeforeInstall()
{
$craftTemplateFolder = realpath(CRAFT_TEMPLATES_PATH);
if (!IOHelper::isWritable($craftTemplateFolder)) {
throw new Exception(Craft::t('Your Template folder is not writeable by PHP. ' . 'InstaBlog needs PHP to have permissions to create template files. Give PHP write permissions to ' . $craftTemplateFolder . ' and try Install again.'));
}
$sources = craft()->assetSources->getAllSourceIds();
if (empty($sources)) {
throw new Exception(Craft::t('You don\'t have any asset sources set up. ' . 'InstaBlog needs an asset source to be defined. Please create an asset source ' . ' and try Install again.'));
}
}
示例3: onBeforeInstall
public function onBeforeInstall()
{
if (!(craft()->getEdition() > 0 || craft()->sections->canHaveMore("channel"))) {
throw new Exception(Craft::t('Your version of Craft only permits one channel section. ' . 'Please upgrade or remove the existing channel section before installing InstaBlog.'));
}
$craftTemplateFolder = realpath(CRAFT_TEMPLATES_PATH);
if (!IOHelper::isWritable($craftTemplateFolder)) {
throw new Exception(Craft::t('Your Template folder is not writeable by PHP. ' . 'InstaBlog needs PHP to have permissions to create template files. Give PHP write permissions to ' . $craftTemplateFolder . ' and try Install again.'));
}
$sources = craft()->assetSources->getAllSourceIds();
if (empty($sources)) {
throw new Exception(Craft::t('You don\'t have any asset sources set up. ' . 'InstaBlog needs an asset source to be defined. Please create an asset source ' . ' and try Install again.'));
}
}
示例4: _validateNewRequirements
/**
* @param string $unzipFolder
*
* @throws Exception
* @return array
*/
private function _validateNewRequirements($unzipFolder)
{
$requirementsFolderPath = $unzipFolder . '/app/etc/requirements/';
$requirementsFile = $requirementsFolderPath . 'Requirements.php';
$errors = array();
if (!IOHelper::fileExists($requirementsFile)) {
throw new Exception(Craft::t('The Requirements file is required and it does not exist at {path}.', array('path' => $requirementsFile)));
}
// Make sure we can write to craft/app/requirements
if (!IOHelper::isWritable(craft()->path->getAppPath() . 'etc/requirements/')) {
throw new Exception(StringHelper::parseMarkdown(Craft::t('Craft CMS needs to be able to write to your craft/app/etc/requirements folder and cannot. Please check your [permissions]({url}).', array('url' => 'http://craftcms.com/docs/updating#one-click-updating'))));
}
$tempFileName = StringHelper::UUID() . '.php';
// Make a dupe of the requirements file and give it a random file name.
IOHelper::copyFile($requirementsFile, $requirementsFolderPath . $tempFileName);
$newTempFilePath = craft()->path->getAppPath() . 'etc/requirements/' . $tempFileName;
// Copy the random file name requirements to the requirements folder.
// We don't want to execute any PHP from the storage folder.
IOHelper::copyFile($requirementsFolderPath . $tempFileName, $newTempFilePath);
require_once $newTempFilePath;
$checker = new RequirementsChecker();
$checker->run();
if ($checker->getResult() == RequirementResult::Failed) {
foreach ($checker->getRequirements() as $requirement) {
if ($requirement->getResult() == InstallStatus::Failed) {
Craft::log('Requirement "' . $requirement->getName() . '" failed with the message: ' . $requirement->getNotes(), LogLevel::Error, true);
$errors[] = $requirement->getNotes();
}
}
}
// Cleanup
IOHelper::deleteFile($newTempFilePath);
return $errors;
}
示例5: getResourcePath
/**
* Resolves a resource path to the actual file system path, or returns false if the resource cannot be found.
*
* @param string $path
*
* @throws HttpException
* @return string
*/
public function getResourcePath($path)
{
$segs = explode('/', $path);
// Special resource routing
if (isset($segs[0])) {
switch ($segs[0]) {
case 'js':
// Route to js/compressed/ if useCompressedJs is enabled
// unless js/uncompressed/* is requested, in which case drop the uncompressed/ seg
if (isset($segs[1]) && $segs[1] == 'uncompressed') {
array_splice($segs, 1, 1);
} else {
if (craft()->config->get('useCompressedJs')) {
array_splice($segs, 1, 0, 'compressed');
}
}
$path = implode('/', $segs);
break;
case 'userphotos':
if (isset($segs[1]) && $segs[1] == 'temp') {
if (!isset($segs[2])) {
return false;
}
return craft()->path->getTempUploadsPath() . 'userphotos/' . $segs[2] . '/' . $segs[3];
} else {
if (!isset($segs[3])) {
return false;
}
$size = AssetsHelper::cleanAssetName($segs[2], false);
// Looking for either a numeric size or "original" keyword
if (!is_numeric($size) && $size != "original") {
return false;
}
$username = AssetsHelper::cleanAssetName($segs[1], false);
$filename = AssetsHelper::cleanAssetName($segs[3]);
$userPhotosPath = craft()->path->getUserPhotosPath() . $username . '/';
$sizedPhotoFolder = $userPhotosPath . $size . '/';
$sizedPhotoPath = $sizedPhotoFolder . $filename;
// If the photo doesn't exist at this size, create it.
if (!IOHelper::fileExists($sizedPhotoPath)) {
$originalPhotoPath = $userPhotosPath . 'original/' . $filename;
if (!IOHelper::fileExists($originalPhotoPath)) {
return false;
}
IOHelper::ensureFolderExists($sizedPhotoFolder);
if (IOHelper::isWritable($sizedPhotoFolder)) {
craft()->images->loadImage($originalPhotoPath)->resize($size)->saveAs($sizedPhotoPath);
} else {
Craft::log('Tried to write to target folder and could not: ' . $sizedPhotoFolder, LogLevel::Error);
}
}
return $sizedPhotoPath;
}
case 'defaultuserphoto':
return craft()->path->getResourcesPath() . 'images/user.svg';
case 'tempuploads':
array_shift($segs);
return craft()->path->getTempUploadsPath() . implode('/', $segs);
case 'tempassets':
array_shift($segs);
return craft()->path->getAssetsTempSourcePath() . implode('/', $segs);
case 'assetthumbs':
if (empty($segs[1]) || empty($segs[2]) || !is_numeric($segs[1]) || !is_numeric($segs[2])) {
return $this->_getBrokenImageThumbPath();
}
$fileModel = craft()->assets->getFileById($segs[1]);
if (empty($fileModel)) {
return $this->_getBrokenImageThumbPath();
}
$size = $segs[2];
try {
return craft()->assetTransforms->getThumbServerPath($fileModel, $size);
} catch (\Exception $e) {
return $this->_getBrokenImageThumbPath();
}
case 'icons':
if (empty($segs[1]) || !preg_match('/^\\w+/i', $segs[1])) {
return false;
}
return $this->_getIconPath($segs[1]);
case 'rebrand':
if (!in_array($segs[1], array('logo', 'icon'))) {
return false;
}
return craft()->path->getRebrandPath() . $segs[1] . "/" . $segs[2];
case 'transforms':
try {
if (!empty($segs[1])) {
$transformIndexModel = craft()->assetTransforms->getTransformIndexModelById((int) $segs[1]);
}
if (empty($transformIndexModel)) {
throw new HttpException(404);
//.........这里部分代码省略.........
示例6: _isConfigFolderWritable
/**
* @return bool
*/
private function _isConfigFolderWritable()
{
return IOHelper::isWritable(IOHelper::getFolderName(craft()->path->getLicenseKeyPath()));
}
示例7: getUnwritableFolders
/**
* Checks to see if Craft can write to a defined set of folders/files that are needed for auto-update to work.
*
* @return array|null
*/
public function getUnwritableFolders()
{
$checkPaths = array(craft()->path->getAppPath(), craft()->path->getPluginsPath());
$errorPath = null;
foreach ($checkPaths as $writablePath) {
if (!IOHelper::isWritable($writablePath)) {
$errorPath[] = IOHelper::getRealPath($writablePath);
}
}
return $errorPath;
}
示例8: createSourceFolder
/**
* @inheritDoc BaseAssetSourceType::createSourceFolder()
*
* @param AssetFolderModel $parentFolder
* @param string $folderName
*
* @return bool
*/
protected function createSourceFolder(AssetFolderModel $parentFolder, $folderName)
{
if (!IOHelper::isWritable($this->getSourceFileSystemPath() . $parentFolder->path)) {
return false;
}
return IOHelper::createFolder($this->getSourceFileSystemPath() . $parentFolder->path . $folderName);
}
示例9: flightcheck
/**
* Perform pre-flight checks to ensure we can run.
*
* @return this
*/
protected function flightcheck()
{
if (!self::$_pluginSettings) {
throw new Exception(Craft::t('Minimee is not installed.'));
}
if (!$this->settings->enabled) {
throw new Exception(Craft::t('Minimee has been disabled via settings.'));
}
if (!$this->settings->validate()) {
$exceptionErrors = '';
foreach ($this->settings->getErrors() as $error) {
$exceptionErrors .= implode('. ', $error);
}
throw new Exception(Craft::t('Minimee has detected invalid plugin settings: ') . $exceptionErrors);
}
if ($this->settings->useResourceCache()) {
IOHelper::ensureFolderExists($this->makePathToStorageFolder());
} else {
if (!IOHelper::folderExists($this->settings->cachePath)) {
throw new Exception(Craft::t('Minimee\'s Cache Folder does not exist: ' . $this->settings->cachePath));
}
if (!IOHelper::isWritable($this->settings->cachePath)) {
throw new Exception(Craft::t('Minimee\'s Cache Folder is not writable: ' . $this->settings->cachePath));
}
}
if (!$this->assets) {
throw new Exception(Craft::t('Minimee has no assets to operate upon.'));
}
if (!$this->type) {
throw new Exception(Craft::t('Minimee has no value for `type`.'));
}
return $this;
}
示例10: _validateManifestPathsWritable
/**
* Checks to see if the files that we are about to update are writable by Craft.
*
* @access private
* @param $unzipFolder
* @return bool
*/
private function _validateManifestPathsWritable($unzipFolder)
{
$manifestData = UpdateHelper::getManifestData($unzipFolder);
$writableErrors = array();
foreach ($manifestData as $row) {
if (UpdateHelper::isManifestVersionInfoLine($row)) {
continue;
}
$rowData = explode(';', $row);
$filePath = IOHelper::normalizePathSeparators(craft()->path->getAppPath() . $rowData[0]);
if (UpdateHelper::isManifestLineAFolder($filePath)) {
$filePath = UpdateHelper::cleanManifestFolderLine($filePath);
}
// Check to see if the file/folder we need to update is writable.
if (IOHelper::fileExists($filePath) || IOHelper::folderExists($filePath)) {
if (!IOHelper::isWritable($filePath)) {
$writableErrors[] = $filePath;
}
} else {
if (($folderPath = IOHelper::folderExists(IOHelper::getFolderName($filePath))) == true) {
if (!IOHelper::isWritable($folderPath)) {
$writableErrors[] = $filePath;
}
}
}
}
return $writableErrors;
}
示例11: getResourcePath
/**
* Resolves a resource path to the actual file system path, or returns false if the resource cannot be found.
*
* @param string $path
*
* @throws HttpException
* @return string
*/
public function getResourcePath($path)
{
$segs = explode('/', $path);
// Special resource routing
if (isset($segs[0])) {
switch ($segs[0]) {
case 'js':
// Route to js/compressed/ if useCompressedJs is enabled
if (craft()->config->get('useCompressedJs') && !craft()->request->getQuery('uncompressed')) {
array_splice($segs, 1, 0, 'compressed');
$path = implode('/', $segs);
}
break;
case 'userphotos':
if (isset($segs[1]) && $segs[1] == 'temp') {
if (!isset($segs[2])) {
return false;
}
return craft()->path->getTempUploadsPath() . 'userphotos/' . $segs[2] . '/' . $segs[3];
} else {
if (!isset($segs[3])) {
return false;
}
$size = AssetsHelper::cleanAssetName($segs[2]);
// Looking for either a numeric size or "original" keyword
if (!is_numeric($size) && $size != "original") {
return false;
}
$username = AssetsHelper::cleanAssetName($segs[1]);
$filename = AssetsHelper::cleanAssetName($segs[3]);
$userPhotosPath = craft()->path->getUserPhotosPath() . $username . '/';
$sizedPhotoFolder = $userPhotosPath . $size . '/';
$sizedPhotoPath = $sizedPhotoFolder . $filename;
// If the photo doesn't exist at this size, create it.
if (!IOHelper::fileExists($sizedPhotoPath)) {
$originalPhotoPath = $userPhotosPath . 'original/' . $filename;
if (!IOHelper::fileExists($originalPhotoPath)) {
return false;
}
IOHelper::ensureFolderExists($sizedPhotoFolder);
if (IOHelper::isWritable($sizedPhotoFolder)) {
craft()->images->loadImage($originalPhotoPath)->resize($size)->saveAs($sizedPhotoPath);
} else {
Craft::log('Tried to write to target folder and could not: ' . $sizedPhotoFolder, LogLevel::Error);
}
}
return $sizedPhotoPath;
}
case 'defaultuserphoto':
if (!isset($segs[1]) || !is_numeric($segs[1])) {
return;
}
$size = $segs[1];
$sourceFile = craft()->path->getResourcesPath() . 'images/' . static::DefaultUserphotoFilename;
$targetFolder = craft()->path->getUserPhotosPath() . '__default__/';
IOHelper::ensureFolderExists($targetFolder);
if (IOHelper::isWritable($targetFolder)) {
$targetFile = $targetFolder . $size . '.' . IOHelper::getExtension($sourceFile);
craft()->images->loadImage($sourceFile)->resize($size)->saveAs($targetFile);
return $targetFile;
} else {
Craft::log('Tried to write to the target folder, but could not:' . $targetFolder, LogLevel::Error);
}
case 'tempuploads':
array_shift($segs);
return craft()->path->getTempUploadsPath() . implode('/', $segs);
case 'tempassets':
array_shift($segs);
return craft()->path->getAssetsTempSourcePath() . implode('/', $segs);
case 'assetthumbs':
if (empty($segs[1]) || empty($segs[2]) || !is_numeric($segs[1]) || !is_numeric($segs[2])) {
return false;
}
$fileModel = craft()->assets->getFileById($segs[1]);
if (empty($fileModel)) {
return false;
}
$size = $segs[2];
return craft()->assetTransforms->getThumbServerPath($fileModel, $size);
case 'icons':
if (empty($segs[1]) || empty($segs[2]) || !is_numeric($segs[2]) || !preg_match('/^(?P<extension>[a-z_0-9]+)/i', $segs[1])) {
return false;
}
$ext = StringHelper::toLowerCase($segs[1]);
$size = $segs[2];
$iconPath = $this->_getIconPath($ext, $size);
return $iconPath;
case 'logo':
return craft()->path->getStoragePath() . implode('/', $segs);
case 'transforms':
try {
if (!empty($segs[1])) {
//.........这里部分代码省略.........
示例12: _createSourceFolder
/**
* Create a physical folder, return TRUE on success.
*
* @param AssetFolderModel $parentFolder
* @param $folderName
* @return boolean
*/
protected function _createSourceFolder(AssetFolderModel $parentFolder, $folderName)
{
if (!IOHelper::isWritable($this->_getSourceFileSystemPath() . $parentFolder->fullPath)) {
return false;
}
return IOHelper::createFolder($this->_getSourceFileSystemPath() . $parentFolder->fullPath . $folderName, IOHelper::getWritableFolderPermissions());
}
示例13: run
/**
*/
public function run()
{
$this->init();
$installResult = InstallStatus::Success;
foreach ($this->_requirements as $requirement) {
if ($requirement->getResult() == RequirementResult::Failed) {
$installResult = InstallStatus::Failure;
break;
} else {
if ($requirement->getResult() == RequirementResult::Warning) {
$installResult = InstallStatus::Warning;
}
}
}
$writableFolders = $this->_getWritableFolders();
$errorFolders = null;
foreach ($writableFolders as $writableFolder) {
if (!IOHelper::isWritable($writableFolder)) {
$errorFolders[] = IOHelper::getRealPath($writableFolder);
$installResult = InstallStatus::Failure;
}
}
$this->_result = $installResult;
$this->_serverInfo = $this->_calculateServerInfo();
$this->_errorFolders = $errorFolders;
}