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


PHP WriteInterface::getRelativePath方法代码示例

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


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

示例1: _generateRow

 /**
  * Get backup-specific data from model for each row
  *
  * @param string $filename
  * @return array
  */
 protected function _generateRow($filename)
 {
     $row = parent::_generateRow($filename);
     foreach ($this->_backup->load($row['basename'], $this->_varDirectory->getAbsolutePath($this->_path))->getData() as $key => $value) {
         $row[$key] = $value;
     }
     $row['size'] = $this->_varDirectory->stat($this->_varDirectory->getRelativePath($filename))['size'];
     $row['id'] = $row['time'] . '_' . $row['type'];
     return $row;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:Collection.php

示例2: _deleteExpiredImagesForWebsite

 /**
  * Delete Expired Captcha Images for specific website
  *
  * @param \Magento\Captcha\Helper\Data $helper
  * @param \Magento\Store\Model\Website|null $website
  * @param \Magento\Store\Model\Store|null $store
  * @return void
  */
 protected function _deleteExpiredImagesForWebsite(\Magento\Captcha\Helper\Data $helper, \Magento\Store\Model\Website $website = null, \Magento\Store\Model\Store $store = null)
 {
     $expire = time() - $helper->getConfig('timeout', $store) * 60;
     $imageDirectory = $this->_mediaDirectory->getRelativePath($helper->getImgDir($website));
     foreach ($this->_mediaDirectory->read($imageDirectory) as $filePath) {
         if ($this->_mediaDirectory->isFile($filePath) && pathinfo($filePath, PATHINFO_EXTENSION) == 'png' && $this->_mediaDirectory->stat($filePath)['mtime'] < $expire) {
             $this->_mediaDirectory->delete($filePath);
         }
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:DeleteExpiredImages.php

示例3: downloadFile

 /**
  * Custom options downloader
  *
  * @param array $info
  * @return void
  * @throws \Exception
  */
 public function downloadFile($info)
 {
     $relativePath = $info['order_path'];
     if (!$this->_isCanProcessed($relativePath)) {
         //try get file from quote
         $relativePath = $info['quote_path'];
         if (!$this->_isCanProcessed($relativePath)) {
             throw new LocalizedException(__('Path "%1" is not part of allowed directory "%2"', $relativePath, $this->rootDirBasePath));
         }
     }
     $this->_fileFactory->create($info['title'], ['value' => $this->_rootDir->getRelativePath($relativePath), 'type' => 'filename'], $this->rootDirBasePath);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:Download.php

示例4: downloadFile

 /**
  * Custom options downloader
  *
  * @param array $info
  * @return void
  * @throws \Exception
  */
 public function downloadFile($info)
 {
     $relativePath = $info['order_path'];
     if ($this->_isCanProcessed($relativePath)) {
         //try get file from quote
         $relativePath = $info['quote_path'];
         if ($this->_isCanProcessed($relativePath)) {
             throw new \Exception();
         }
     }
     $this->_fileFactory->create($info['title'], array('value' => $this->_rootDir->getRelativePath($relativePath), 'type' => 'filename'), \Magento\Framework\App\Filesystem::ROOT_DIR);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:19,代码来源:Download.php

示例5: downloadFile

 /**
  * Custom options downloader
  *
  * @param array $info
  * @return void
  * @throws \Exception
  */
 public function downloadFile($info)
 {
     $relativePath = $info['order_path'];
     if ($this->_isCanProcessed($relativePath)) {
         //try get file from quote
         $relativePath = $info['quote_path'];
         if ($this->_isCanProcessed($relativePath)) {
             throw new \Exception();
         }
     }
     $this->_fileFactory->create($info['title'], ['value' => $this->_rootDir->getRelativePath($relativePath), 'type' => 'filename'], DirectoryList::ROOT);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:Download.php

示例6: save

 /**
  * Save config in cache file
  *
  * @return void
  */
 public function save()
 {
     /** @var Write $file */
     $file = $this->rootDirectory->openFile($this->rootDirectory->getRelativePath($this->cacheFilePath), 'w');
     try {
         $file->lock();
         $file->write(json_encode($this->config));
         $file->unlock();
         $file->close();
     } catch (FileSystemException $e) {
         $file->close();
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:Config.php

示例7: _generateRow

 /**
  * Get backup-specific data from model for each row
  *
  * @param string $filename
  * @return array
  */
 protected function _generateRow($filename)
 {
     $row = parent::_generateRow($filename);
     foreach ($this->_backup->load($row['basename'], $this->_varDirectory->getAbsolutePath($this->_path))->getData() as $key => $value) {
         $row[$key] = $value;
     }
     $row['size'] = $this->_varDirectory->stat($this->_varDirectory->getRelativePath($filename))['size'];
     if (isset($row['display_name']) && $row['display_name'] == '') {
         $row['display_name'] = 'WebSetupWizard';
     }
     $row['id'] = $row['time'] . '_' . $row['type'] . (isset($row['display_name']) ? $row['display_name'] : '');
     return $row;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:19,代码来源:Collection.php

示例8: removePreviewImage

 /**
  * Delete preview image
  *
  * @return bool
  */
 public function removePreviewImage()
 {
     $previewImage = $this->theme->getPreviewImage();
     $this->theme->setPreviewImage(null);
     if ($previewImage) {
         $previewImagePath = $this->themeImagePath->getImagePreviewDirectory() . '/' . $previewImage;
         return $this->mediaDirectory->delete($this->mediaDirectory->getRelativePath($previewImagePath));
     }
     return false;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:Image.php

示例9: getUploader

 /**
  * Returns an object for upload a media files
  *
  * @param string $type
  * @param array $parameters
  * @return \Magento\CatalogImportExport\Model\Import\Uploader
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getUploader($type, $parameters)
 {
     $dirConfig = DirectoryList::getDefaultConfig();
     $dirAddon = $dirConfig[DirectoryList::MEDIA][DirectoryList::PATH];
     $DS = DIRECTORY_SEPARATOR;
     if (!empty($parameters[\Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR])) {
         $tmpPath = $parameters[\Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR];
     } else {
         $tmpPath = $dirAddon . $DS . $this->mediaDirectory->getRelativePath('import');
     }
     if (!$this->fileUploader->setTmpDir($tmpPath)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('File directory \'%1\' is not readable.', $tmpPath));
     }
     $destinationDir = "downloadable/files/" . $type;
     $destinationPath = $dirAddon . $DS . $this->mediaDirectory->getRelativePath($destinationDir);
     $this->mediaDirectory->create($destinationDir);
     if (!$this->fileUploader->setDestDir($destinationPath)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('File directory \'%1\' is not writable.', $destinationPath));
     }
     return $this->fileUploader;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:29,代码来源:Uploader.php

示例10: 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

示例11: move

 /**
  * Proceed moving a file from TMP to destination folder
  *
  * @param string $fileName
  * @return array
  */
 public function move($fileName)
 {
     if (preg_match('/\\bhttps?:\\/\\//i', $fileName, $matches)) {
         $url = str_replace($matches[0], '', $fileName);
         $read = $this->_readFactory->create($url, DriverPool::HTTP);
         $fileName = preg_replace('/[^a-z0-9\\._-]+/i', '', $fileName);
         $this->_directory->writeFile($this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName), $read->readAll());
     }
     $filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName);
     $this->_setUploadFile($filePath);
     $result = $this->save($this->getDestDir());
     $result['name'] = self::getCorrectFileName($result['name']);
     return $result;
 }
开发者ID:kid17,项目名称:magento2,代码行数:20,代码来源:Uploader.php

示例12: enableCacheTypes

 /**
  * Enables apppropriate cache types in app/etc/env.php based on the passed in $cacheTypes array
  * TODO: to be removed in scope of MAGETWO-53476
  *
  * @param string[]
  *
  * @return void
  */
 private function enableCacheTypes($cacheTypes)
 {
     if (empty($cacheTypes)) {
         return;
     }
     $envPath = $this->getEnvPath();
     if ($this->write->isReadable($this->write->getRelativePath($envPath))) {
         $envData = (include $envPath);
         foreach ($cacheTypes as $cacheType) {
             if (isset($envData['cache_types'][$cacheType])) {
                 $envData['cache_types'][$cacheType] = 1;
             }
         }
         $formatter = new PhpFormatter();
         $contents = $formatter->format($envData);
         $this->write->writeFile($this->write->getRelativePath($envPath), $contents);
         if (function_exists('opcache_invalidate')) {
             opcache_invalidate($this->write->getAbsolutePath($envPath));
         }
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:29,代码来源:GeneratedFiles.php

示例13: _getUploader

 /**
  * Returns an object for upload a media files
  *
  * @return \Magento\CatalogImportExport\Model\Import\Uploader
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _getUploader()
 {
     if (is_null($this->_fileUploader)) {
         $this->_fileUploader = $this->_uploaderFactory->create();
         $this->_fileUploader->init();
         $dirConfig = DirectoryList::getDefaultConfig();
         $dirAddon = $dirConfig[DirectoryList::MEDIA][DirectoryList::PATH];
         $DS = DIRECTORY_SEPARATOR;
         if (!empty($this->_parameters[\Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR])) {
             $tmpPath = $this->_parameters[\Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR];
         } else {
             $tmpPath = $dirAddon . $DS . $this->_mediaDirectory->getRelativePath('import');
         }
         if (!$this->_fileUploader->setTmpDir($tmpPath)) {
             throw new \Magento\Framework\Exception\LocalizedException(__('File directory \'%1\' is not readable.', $tmpPath));
         }
         $destinationDir = "catalog/product";
         $destinationPath = $dirAddon . $DS . $this->_mediaDirectory->getRelativePath($destinationDir);
         $this->_mediaDirectory->create($destinationPath);
         if (!$this->_fileUploader->setDestDir($destinationPath)) {
             throw new \Magento\Framework\Exception\LocalizedException(__('File directory \'%1\' is not writable.', $destinationPath));
         }
     }
     return $this->_fileUploader;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:31,代码来源:Product.php

示例14: _getFilePath

 /**
  * Get file path.
  *
  * @return string
  */
 protected function _getFilePath()
 {
     return $this->varDirectory->getRelativePath($this->getPath() . '/' . $this->getFileName());
 }
开发者ID:opexsw,项目名称:magento2,代码行数:9,代码来源:Backup.php

示例15: getFilePath

 /**
  * Get file path.
  *
  * @param string $filename
  * @return string
  */
 protected function getFilePath($filename)
 {
     return $this->varDirectory->getRelativePath(Import::IMPORT_HISTORY_DIR . $filename);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:Report.php


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