當前位置: 首頁>>代碼示例>>PHP>>正文


PHP App\Filesystem類代碼示例

本文整理匯總了PHP中Magento\Framework\App\Filesystem的典型用法代碼示例。如果您正苦於以下問題:PHP Filesystem類的具體用法?PHP Filesystem怎麽用?PHP Filesystem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Filesystem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: afterSave

 /**
  * Save uploaded file and set its name to category
  *
  * @param \Magento\Framework\Object $object
  * @return \Magento\Catalog\Model\Category\Attribute\Backend\Image
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName() . '_additional_data');
     // if no image was set - nothing to do
     if (empty($value) && empty($_FILES)) {
         return $this;
     }
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return $this;
     }
     $path = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MEDIA_DIR)->getAbsolutePath('catalog/category/');
     try {
         /** @var $uploader \Magento\Core\Model\File\Uploader */
         $uploader = $this->_fileUploaderFactory->create(array('fileId' => $this->getAttribute()->getName()));
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $result = $uploader->save($path);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (\Exception $e) {
         if ($e->getCode() != \Magento\Core\Model\File\Uploader::TMP_NAME_EMPTY) {
             $this->_logger->logException($e);
         }
     }
     return $this;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:34,代碼來源:Image.php

示例2: __construct

 /**
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Core\Helper\File\Storage\Database $fileStorageDatabase
  * @param \Magento\Core\Model\File\Storage\DatabaseFactory $storageDatabaseFactory
  * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
  */
 public function __construct(\Magento\Framework\App\Filesystem $filesystem, \Magento\Core\Helper\File\Storage\Database $fileStorageDatabase, \Magento\Core\Model\File\Storage\DatabaseFactory $storageDatabaseFactory, \Magento\Framework\App\Response\Http\FileFactory $fileFactory)
 {
     $this->_rootDir = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $this->_fileStorageDatabase = $fileStorageDatabase;
     $this->_storageDatabaseFactory = $storageDatabaseFactory;
     $this->_fileFactory = $fileFactory;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:13,代碼來源:Download.php

示例3: __construct

 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  * @param \Magento\Paypal\Model\CertFactory $certFactory
  * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Framework\Model\Resource\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\Db $resourceCollection
  * @param array $data
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Paypal\Model\CertFactory $certFactory, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = array())
 {
     $this->_certFactory = $certFactory;
     $this->_encryptor = $encryptor;
     $this->_tmpDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::SYS_TMP_DIR);
     parent::__construct($context, $registry, $config, $resource, $resourceCollection, $data);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:18,代碼來源:Cert.php

示例4: ensureSourceFile

 /**
  * Make sure the aggregated configuration is materialized
  *
  * By default write the file if it doesn't exist, but in developer mode always do it.
  *
  * @param string $relPath
  * @return void
  */
 private function ensureSourceFile($relPath)
 {
     $dir = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR);
     if ($this->appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER || !$dir->isExist($relPath)) {
         $dir->writeFile($relPath, $this->config->getConfig());
     }
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:15,代碼來源:FileManager.php

示例5: __construct

 /**
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Magento\Framework\Logger $logger
  * @param \Magento\Framework\Locale\ResolverInterface $localeResolver
  * @param \Magento\Core\Helper\Data $coreData
  * @param \Magento\Core\Model\File\Validator\NotProtectedExtension $fileValidator
  * @param \Magento\Framework\App\Filesystem $filesystem
  */
 public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Framework\Logger $logger, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Core\Helper\Data $coreData, \Magento\Core\Model\File\Validator\NotProtectedExtension $fileValidator, \Magento\Framework\App\Filesystem $filesystem)
 {
     parent::__construct($localeDate, $logger, $localeResolver);
     $this->_coreData = $coreData;
     $this->_fileValidator = $fileValidator;
     $this->_directory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::MEDIA_DIR);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:15,代碼來源:File.php

示例6: __construct

 /**
  * @param \Magento\Framework\Code\Minifier\StrategyInterface $strategy
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param string $directoryName
  */
 public function __construct(\Magento\Framework\Code\Minifier\StrategyInterface $strategy, \Magento\Framework\App\Filesystem $filesystem, $directoryName)
 {
     $this->_strategy = $strategy;
     $this->rootDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $this->pubViewCacheDir = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::PUB_VIEW_CACHE_DIR);
     $this->directoryName = $directoryName;
 }
開發者ID:Mohitsahu123,項目名稱:mtf,代碼行數:12,代碼來源:Minifier.php

示例7: __construct

 /**
  * @param Filesystem $filesystem
  * @param \Magento\Framework\Config\FileIteratorFactory $iteratorFactory
  */
 public function __construct(Filesystem $filesystem, \Magento\Framework\Config\FileIteratorFactory $iteratorFactory)
 {
     $this->iteratorFactory = $iteratorFactory;
     $this->modulesDirectory = $filesystem->getDirectoryRead(Filesystem::MODULES_DIR);
     $this->configDirectory = $filesystem->getDirectoryRead(Filesystem::CONFIG_DIR);
     $this->rootDirectory = $filesystem->getDirectoryRead(Filesystem::ROOT_DIR);
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:11,代碼來源:FileResolver.php

示例8: __construct

 /**
  * @param \Magento\Framework\App\Filesystem                   $filesystem
  * @param \Magento\Framework\Module\Dir\Reader            $moduleReader
  * @param \Magento\Framework\Config\FileIteratorFactory   $iteratorFactory
  */
 public function __construct(\Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\Module\Dir\Reader $moduleReader, \Magento\Framework\Config\FileIteratorFactory $iteratorFactory)
 {
     $this->themesDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::THEMES_DIR);
     $this->modulesDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MODULES_DIR);
     $this->iteratorFactory = $iteratorFactory;
     $this->_moduleReader = $moduleReader;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:12,代碼來源:FileResolver.php

示例9: __construct

 /**
  * Initialize dependencies
  *
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Theme\Helper\Storage $helper
  * @param \Magento\Framework\ObjectManager $objectManager
  * @param \Magento\Framework\Image\AdapterFactory $imageFactory
  */
 public function __construct(\Magento\Framework\App\Filesystem $filesystem, \Magento\Theme\Helper\Storage $helper, \Magento\Framework\ObjectManager $objectManager, \Magento\Framework\Image\AdapterFactory $imageFactory)
 {
     $this->mediaWriteDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::MEDIA_DIR);
     $this->_helper = $helper;
     $this->_objectManager = $objectManager;
     $this->_imageFactory = $imageFactory;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:15,代碼來源:Storage.php

示例10: __construct

 /**
  * @param \Magento\Framework\Logger $logger
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Framework\Logger\AdapterFactory $adapterFactory
  * @param array $data
  */
 public function __construct(\Magento\Framework\Logger $logger, \Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\Logger\AdapterFactory $adapterFactory, array $data = array())
 {
     $this->_logger = $logger;
     $this->_varDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
     $this->_adapterFactory = $adapterFactory;
     parent::__construct($data);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:13,代碼來源:AbstractModel.php

示例11: afterSave

 /**
  * After save
  *
  * @param \Magento\Framework\Object $object
  * @return $this|void
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName());
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return;
     }
     try {
         /** @var $uploader \Magento\Core\Model\File\Uploader */
         $uploader = $this->_fileUploaderFactory->create(array('fileId' => $this->getAttribute()->getName()));
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
     } catch (\Exception $e) {
         return $this;
     }
     $path = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MEDIA_DIR)->getAbsolutePath('catalog/product/');
     $uploader->save($path);
     $fileName = $uploader->getUploadedFileName();
     if ($fileName) {
         $object->setData($this->getAttribute()->getName(), $fileName);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     }
     return $this;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:32,代碼來源:Image.php

示例12: __construct

 /**
  * @param \Magento\Framework\App\Helper\Context $context
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\App\State $appState
  * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Framework\Convert\Xml $xmlConverter
  * @param bool $dbCompatibleMode
  */
 public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\State $appState, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, \Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\Convert\Xml $xmlConverter, $dbCompatibleMode = true)
 {
     $this->filesystem = $filesystem;
     $this->readDirectory = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::VAR_DIR);
     $this->_xmlConverter = $xmlConverter;
     parent::__construct($context, $scopeConfig, $storeManager, $appState, $priceCurrency, $dbCompatibleMode);
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:17,代碼來源:Data.php

示例13: __construct

 /**
  * Set base dir
  *
  * @param \Magento\Core\Model\EntityFactory $entityFactory
  * @param \Magento\Framework\App\Filesystem $filesystem
  */
 public function __construct(\Magento\Core\Model\EntityFactory $entityFactory, \Magento\Framework\App\Filesystem $filesystem)
 {
     parent::__construct($entityFactory);
     $this->filesystem = $filesystem;
     $this->connectDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
     $this->connectDirectory->create('connect');
     $this->addTargetDir($this->connectDirectory->getAbsolutePath('connect'));
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:14,代碼來源:Collection.php

示例14: __construct

 /**
  * @param Resource\LogFactory $resLogFactory
  * @param \Magento\Captcha\Helper\Data $helper
  * @param \Magento\Captcha\Helper\Adminhtml\Data $adminHelper
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Store\Model\StoreManager $storeManager
  */
 public function __construct(Resource\LogFactory $resLogFactory, \Magento\Captcha\Helper\Data $helper, \Magento\Captcha\Helper\Adminhtml\Data $adminHelper, \Magento\Framework\App\Filesystem $filesystem, \Magento\Store\Model\StoreManager $storeManager)
 {
     $this->_resLogFactory = $resLogFactory;
     $this->_helper = $helper;
     $this->_adminHelper = $adminHelper;
     $this->_mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::MEDIA_DIR);
     $this->_storeManager = $storeManager;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:15,代碼來源:Cron.php

示例15: aroundCleanMergedJsCss

 /**
  * Clean files in database on cleaning merged assets
  *
  * @param \Magento\Framework\View\Asset\MergeService $subject
  * @param callable $proceed
  *
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundCleanMergedJsCss(\Magento\Framework\View\Asset\MergeService $subject, \Closure $proceed)
 {
     $proceed();
     /** @var \Magento\Framework\Filesystem\Directory\ReadInterface $pubStaticDirectory */
     $pubStaticDirectory = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR);
     $mergedDir = $pubStaticDirectory->getAbsolutePath() . '/' . \Magento\Framework\View\Asset\Merged::getRelativeDir();
     $this->database->deleteFolder($mergedDir);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:17,代碼來源:CleanMergedJsCss.php


注:本文中的Magento\Framework\App\Filesystem類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。