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


PHP WriteInterface::changePermissions方法代码示例

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


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

示例1: _hideBackupsForApache

 /**
  * Create .htaccess file and deny backups directory access from web
  *
  * @return void
  */
 protected function _hideBackupsForApache()
 {
     $filename = '.htaccess';
     if (!$this->_varDirectory->isFile($filename)) {
         $this->_varDirectory->writeFile($filename, 'deny from all');
         $this->_varDirectory->changePermissions($filename, 0640);
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:Collection.php

示例2: addImage

 /**
  * Add image to media gallery and return new filename
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param string $file file path of image in file system
  * @param string|string[] $mediaAttribute code of attribute with type 'media_image',
  *                                                      leave blank if image should be only in gallery
  * @param boolean $move if true, it will move source file
  * @param boolean $exclude mark image as disabled in product page view
  * @return string
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function addImage(\Magento\Catalog\Model\Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true)
 {
     $file = $this->_mediaDirectory->getRelativePath($file);
     if (!$this->_mediaDirectory->isFile($file)) {
         throw new LocalizedException(__('The image does not exist.'));
     }
     $pathinfo = pathinfo($file);
     $imgExtensions = ['jpg', 'jpeg', 'gif', 'png'];
     if (!isset($pathinfo['extension']) || !in_array(strtolower($pathinfo['extension']), $imgExtensions)) {
         throw new LocalizedException(__('Please correct the image file type.'));
     }
     $fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($pathinfo['basename']);
     $dispretionPath = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
     $fileName = $dispretionPath . '/' . $fileName;
     $fileName = $this->_getNotDuplicatedFilename($fileName, $dispretionPath);
     $destinationFile = $this->_mediaConfig->getTmpMediaPath($fileName);
     try {
         /** @var $storageHelper \Magento\MediaStorage\Helper\File\Storage\Database */
         $storageHelper = $this->_fileStorageDb;
         if ($move) {
             $this->_mediaDirectory->renameFile($file, $destinationFile);
             //If this is used, filesystem should be configured properly
             $storageHelper->saveFile($this->_mediaConfig->getTmpMediaShortUrl($fileName));
         } else {
             $this->_mediaDirectory->copyFile($file, $destinationFile);
             $storageHelper->saveFile($this->_mediaConfig->getTmpMediaShortUrl($fileName));
             $this->_mediaDirectory->changePermissions($destinationFile, 0777);
         }
     } catch (\Exception $e) {
         throw new LocalizedException(__('We couldn\'t move this file: %1.', $e->getMessage()));
     }
     $fileName = str_replace('\\', '/', $fileName);
     $attrCode = $this->getAttribute()->getAttributeCode();
     $mediaGalleryData = $product->getData($attrCode);
     $position = 0;
     if (!is_array($mediaGalleryData)) {
         $mediaGalleryData = ['images' => []];
     }
     foreach ($mediaGalleryData['images'] as &$image) {
         if (isset($image['position']) && $image['position'] > $position) {
             $position = $image['position'];
         }
     }
     $position++;
     $mediaGalleryData['images'][] = ['file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude];
     $product->setData($attrCode, $mediaGalleryData);
     if ($mediaAttribute !== null) {
         $this->setMediaAttribute($product, $mediaAttribute, $fileName);
     }
     return $fileName;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:65,代码来源:Media.php

示例3: makeConfig

 /**
  * @return string Path to config file
  * @throws \Exception
  */
 public function makeConfig()
 {
     if (!$this->directory->isExist($this->basePath)) {
         //$this->directory->delete($this->basePath);
         $this->directory->create($this->basePath);
         $this->directory->changePermissions($this->basePath, 0777);
     }
     $jsonData = [];
     $sphinxData = ['time' => date('d.m.Y H:i:s'), 'host' => $this->host, 'port' => $this->port, 'fallback_port' => $this->port - 1, 'logdir' => $this->directory->getAbsolutePath($this->basePath), 'sphinxdir' => $this->directory->getAbsolutePath($this->basePath), 'indexes' => '', 'localdir' => dirname(dirname(__FILE__)), 'custom' => $this->config->getAdditionalSearchdConfig()];
     $sphinxTemplate = $this->config->getSphinxConfigurationTemplate();
     $indexTemplate = $this->config->getSphinxIndexConfigurationTemplate();
     /** @var \Mirasvit\Search\Model\Index $index */
     foreach ($this->indexCollectionFactory->create() as $index) {
         foreach (array_keys($this->storeManager->getStores()) as $storeId) {
             $indexName = $index->getIndexInstance()->getIndexer()->getIndexName($storeId);
             $data = ['name' => $indexName, 'min_word_len' => 1, 'path' => $this->directory->getAbsolutePath($this->basePath) . '/' . $indexName, 'custom' => $this->config->getAdditionalIndexConfig()];
             $jsonAttributes = [];
             $attributes = [];
             foreach (array_keys($index->getIndexInstance()->getAttributes(true)) as $attribute) {
                 $attributes[] = "    rt_field = {$attribute}";
                 $jsonAttributes[] = $attribute;
                 if (count($attributes) > 250) {
                     break;
                 }
             }
             $attributes[] = "    rt_field = options";
             $jsonAttributes[] = "options";
             $data['attributes'] = implode(PHP_EOL, $attributes);
             $sphinxData['indexes'] .= $this->helper->filterTemplate($indexTemplate, $data);
             $jsonData[$indexName] = $jsonAttributes;
         }
     }
     $config = $this->helper->filterTemplate($sphinxTemplate, $sphinxData);
     if ($this->directory->isWritable($this->basePath)) {
         $this->directory->writeFile($this->configFilePath, $config);
         $this->directory->writeFile($this->configFilePath . '.attr', json_encode($jsonData));
     } else {
         if ($this->directory->isExist($this->configFilePath)) {
             throw new \Exception(__('File %1 does not writable', $this->configFilePath));
         } else {
             throw new \Exception(__('Directory %1 does not writable', $this->basePath));
         }
     }
     return $this->directory->getAbsolutePath($this->configFilePath);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:49,代码来源:Engine.php


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