当前位置: 首页>>代码示例>>PHP>>正文


PHP IOHelper::changePermissions方法代码示例

本文整理汇总了PHP中IOHelper::changePermissions方法的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper::changePermissions方法的具体用法?PHP IOHelper::changePermissions怎么用?PHP IOHelper::changePermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOHelper的用法示例。


在下文中一共展示了IOHelper::changePermissions方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSetWithFailure

 /**
  * Test set with failure.
  *
  * @expectedException Craft\Exception
  *
  * @covers ::set
  */
 public final function testSetWithFailure()
 {
     // Lock it for writing
     $file = __DIR__ . '/../translations/test.php';
     IOHelper::changePermissions($file, 0444);
     $service = new TranslateService();
     $service->set('test', array());
 }
开发者ID:boboldehampsink,项目名称:translate,代码行数:15,代码来源:TranslateServiceTest.php

示例2: saveUserPhoto

 /**
  * Crops and saves a user’s photo.
  *
  * @param string    $fileName The name of the file.
  * @param Image     $image    The image.
  * @param UserModel $user     The user.
  *
  * @throws \Exception
  * @return bool Whether the photo was saved successfully.
  */
 public function saveUserPhoto($fileName, Image $image, UserModel $user)
 {
     $userName = IOHelper::cleanFilename($user->username);
     $userPhotoFolder = craft()->path->getUserPhotosPath() . $userName . '/';
     $targetFolder = $userPhotoFolder . 'original/';
     IOHelper::ensureFolderExists($userPhotoFolder);
     IOHelper::ensureFolderExists($targetFolder);
     $targetPath = $targetFolder . AssetsHelper::cleanAssetName($fileName);
     $result = $image->saveAs($targetPath);
     if ($result) {
         IOHelper::changePermissions($targetPath, craft()->config->get('defaultFilePermissions'));
         $record = UserRecord::model()->findById($user->id);
         $record->photo = $fileName;
         $record->save();
         $user->photo = $fileName;
         return true;
     }
     return false;
 }
开发者ID:webremote,项目名称:craft_boilerplate,代码行数:29,代码来源:UsersService.php

示例3: changePermissions

 /**
  * @param $permissions
  * @return bool
  */
 public function changePermissions($permissions)
 {
     if (!IOHelper::changePermissions($this->getRealPath(), $permissions)) {
         return false;
     }
     return true;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:11,代码来源:BaseIO.php

示例4: setValue

 /**
  * Stores a value identified by a key in cache. This is the implementation of the method declared in the parent class.
  *
  * @param  string  $key    The key identifying the value to be cached
  * @param  string  $value  The value to be cached
  * @param  integer $expire The number of seconds in which the cached value will expire. 0 means never expire.
  * @return boolean true    If the value is successfully stored into cache, false otherwise
  */
 protected function setValue($key, $value, $expire)
 {
     if (!$this->_gced && mt_rand(0, 1000000) < $this->getGCProbability()) {
         $this->gc();
         $this->_gced = true;
     }
     if ($expire <= 0) {
         $expire = 31536000;
         // 1 year
     }
     $expire += time();
     $cacheFile = $this->getCacheFile($key);
     if ($this->directoryLevel > 0) {
         IOHelper::createFolder(IOHelper::getFolderName($cacheFile), IOHelper::getWritableFolderPermissions());
     }
     if ($this->_originalKey == 'useWriteFileLock') {
         if (IOHelper::writeToFile($cacheFile, $value, true, false, true) !== false) {
             IOHelper::changePermissions($cacheFile, IOHelper::getWritableFilePermissions());
             return IOHelper::touch($cacheFile, $expire);
         } else {
             return false;
         }
     } else {
         if (IOHelper::writeToFile($cacheFile, $value) !== false) {
             IOHelper::changePermissions($cacheFile, IOHelper::getWritableFilePermissions());
             return IOHelper::touch($cacheFile, $expire);
         } else {
             return false;
         }
     }
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:39,代码来源:FileCache.php

示例5: insertFileInFolder

 /**
  * @inheritDoc BaseAssetSourceType::insertFileInFolder()
  *
  * @param AssetFolderModel $folder
  * @param string           $filePath
  * @param string           $fileName
  *
  * @throws Exception
  * @return AssetOperationResponseModel
  */
 protected function insertFileInFolder(AssetFolderModel $folder, $filePath, $fileName)
 {
     // Check if the set file system path exists
     $basePath = $this->getSourceFileSystemPath();
     if (empty($basePath)) {
         $basePath = $this->getBasePath();
         if (!empty($basePath)) {
             throw new Exception(Craft::t('The file system path “{folder}” set for this source does not exist.', array('folder' => $this->getBasePath())));
         }
     }
     $targetFolder = $this->getSourceFileSystemPath() . $folder->path;
     // Make sure the folder exists.
     if (!IOHelper::folderExists($targetFolder)) {
         throw new Exception(Craft::t('The folder “{folder}” does not exist.', array('folder' => $targetFolder)));
     }
     // Make sure the folder is writable
     if (!IOHelper::isWritable($targetFolder)) {
         throw new Exception(Craft::t('The folder “{folder}” is not writable.', array('folder' => $targetFolder)));
     }
     $fileName = AssetsHelper::cleanAssetName($fileName);
     $targetPath = $targetFolder . $fileName;
     $extension = IOHelper::getExtension($fileName);
     if (!IOHelper::isExtensionAllowed($extension)) {
         throw new Exception(Craft::t('This file type is not allowed'));
     }
     if (IOHelper::fileExists($targetPath)) {
         $response = new AssetOperationResponseModel();
         return $response->setPrompt($this->getUserPromptOptions($fileName))->setDataItem('fileName', $fileName);
     }
     if (!IOHelper::copyFile($filePath, $targetPath)) {
         throw new Exception(Craft::t('Could not copy file to target destination'));
     }
     IOHelper::changePermissions($targetPath, craft()->config->get('defaultFilePermissions'));
     $response = new AssetOperationResponseModel();
     return $response->setSuccess()->setDataItem('filePath', $targetPath);
 }
开发者ID:nathanedwards,项目名称:cowfields.craft,代码行数:46,代码来源:LocalAssetSourceType.php

示例6: cropAndSaveUserPhoto

 /**
  * Crop and save a user's photo by coordinates for a given user model.
  *
  * @param $source
  * @param $x1
  * @param $x2
  * @param $y1
  * @param $y2
  * @param UserModel $user
  * @return bool
  * @throws \Exception
  */
 public function cropAndSaveUserPhoto($source, $x1, $x2, $y1, $y2, UserModel $user)
 {
     $userPhotoFolder = craft()->path->getUserPhotosPath() . $user->username . '/';
     $targetFolder = $userPhotoFolder . 'original/';
     IOHelper::ensureFolderExists($userPhotoFolder);
     IOHelper::ensureFolderExists($targetFolder);
     $filename = IOHelper::getFileName($source);
     $targetPath = $targetFolder . $filename;
     $image = craft()->images->loadImage($source);
     $image->crop($x1, $x2, $y1, $y2);
     $result = $image->saveAs($targetPath);
     if ($result) {
         IOHelper::changePermissions($targetPath, IOHelper::getWritableFilePermissions());
         $record = UserRecord::model()->findById($user->id);
         $record->photo = $filename;
         $record->save();
         $user->photo = $filename;
         return true;
     }
     return false;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:33,代码来源:UsersService.php

示例7: _insertFileInFolder

 /**
  * Insert a file from path in folder.
  *
  * @param AssetFolderModel $folder
  * @param $filePath
  * @param $fileName
  * @return AssetOperationResponseModel
  * @throws Exception
  */
 protected function _insertFileInFolder(AssetFolderModel $folder, $filePath, $fileName)
 {
     $targetFolder = $this->_getSourceFileSystemPath() . $folder->fullPath;
     // Make sure the folder exists.
     if (!IOHelper::folderExists($targetFolder)) {
         throw new Exception(Craft::t('The “File System Path” specified for this asset source does not appear to exist.'));
     }
     // Make sure the folder is writable
     if (!IOHelper::isWritable($targetFolder)) {
         throw new Exception(Craft::t('Craft is not able to write to the “File System Path” specified for this asset source.'));
     }
     $fileName = IOHelper::cleanFilename($fileName);
     $targetPath = $targetFolder . $fileName;
     $extension = IOHelper::getExtension($fileName);
     if (!IOHelper::isExtensionAllowed($extension)) {
         throw new Exception(Craft::t('This file type is not allowed'));
     }
     if (IOHelper::fileExists($targetPath)) {
         $response = new AssetOperationResponseModel();
         return $response->setPrompt($this->_getUserPromptOptions($fileName))->setDataItem('fileName', $fileName);
     }
     if (!IOHelper::copyFile($filePath, $targetPath)) {
         throw new Exception(Craft::t('Could not copy file to target destination'));
     }
     IOHelper::changePermissions($targetPath, IOHelper::getWritableFilePermissions());
     $response = new AssetOperationResponseModel();
     return $response->setSuccess()->setDataItem('filePath', $targetPath);
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:37,代码来源:LocalAssetSourceType.php


注:本文中的IOHelper::changePermissions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。