/** * 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; }
/** * Test for processException method report * * @covers \Magento\Framework\Error\Handler::processException * @runInSeparateProcess */ public function testProcessExceptionReport() { $this->appState->expects($this->any())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEFAULT)); $this->filesystem->expects($this->atLeastOnce())->method('getPath')->with(\Magento\Framework\App\Filesystem::PUB_DIR)->will($this->returnValue(dirname(__DIR__) . '/../../_files')); $exception = new \Exception('TestMessage'); $this->handler->processException($exception); }
/** * @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; }
/** * @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); }
/** * @param Dir $moduleDirs * @param ModuleListInterface $moduleList * @param Filesystem $filesystem * @param FileIteratorFactory $fileIteratorFactory */ public function __construct(Dir $moduleDirs, ModuleListInterface $moduleList, Filesystem $filesystem, FileIteratorFactory $fileIteratorFactory) { $this->moduleDirs = $moduleDirs; $this->modulesList = $moduleList; $this->fileIteratorFactory = $fileIteratorFactory; $this->modulesDirectory = $filesystem->getDirectoryRead(Filesystem::MODULES_DIR); }
/** * 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()); } }
/** * {@inheritdoc} */ public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset) { $dir = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR); if (!$dir->isExist($resultAsset->getPath())) { $this->strategy->merge($assetsToMerge, $resultAsset); } }
/** * @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); }
/** * @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; }
/** * @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); }
/** * Constructor * * @param \Magento\Framework\App\Filesystem $filesystem * @param string $filename */ public function __construct(\Magento\Framework\App\Filesystem $filesystem, $filename = \Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME) { $this->filesystem = $filesystem; $this->filename = $filename; $this->mediaDirectoryRead = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MEDIA_DIR); $this->themeDirectoryRead = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::THEMES_DIR); }
/** * @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; }
/** * @param \Magento\Framework\App\Filesystem $filesystem * @param \Magento\Framework\View\Asset\Repository $assetRepo * @param \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport $magentoImportProcessor * @param \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor */ public function __construct(\Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport $magentoImportProcessor, \Magento\Framework\Less\PreProcessor\Instruction\Import $importProcessor) { $this->tmpDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR); $this->assetRepo = $assetRepo; $this->magentoImportProcessor = $magentoImportProcessor; $this->importProcessor = $importProcessor; }
/** * 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; }
/** * @param FileListFactory $fileListFactory * @param Filesystem $filesystem * @param Factory $fileFactory */ public function __construct(FileListFactory $fileListFactory, Filesystem $filesystem, Factory $fileFactory) { $this->fileListFactory = $fileListFactory; $this->libraryDirectory = $filesystem->getDirectoryRead(Filesystem::LIB_WEB); $this->themesDirectory = $filesystem->getDirectoryRead(Filesystem::THEMES_DIR); $this->fileFactory = $fileFactory; }
/** * @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); }
/** * 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; }
/** * @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); }
/** * 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')); }
/** * @param \Magento\Framework\App\Filesystem $filesystem * @param \Magento\Framework\View\File\Factory $fileFactory * @param CollectorInterface $baseFiles * @param CollectorInterface $themeFiles * @param CollectorInterface $themeModularFiles */ public function __construct(\Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\View\File\Factory $fileFactory, CollectorInterface $baseFiles, CollectorInterface $themeFiles, CollectorInterface $themeModularFiles) { $this->libDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::LIB_WEB); $this->fileFactory = $fileFactory; $this->baseFiles = $baseFiles; $this->themeFiles = $themeFiles; $this->themeModularFiles = $themeModularFiles; }
/** * @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; }
/** * 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); }
public function setup() { $this->filesystemMock = $this->getMockBuilder('Magento\\Framework\\App\\Filesystem')->disableOriginalConstructor()->getMock(); $this->themesDirectoryMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMock(); $this->filesystemMock->expects($this->any())->method('getDirectoryRead')->will($this->returnValue($this->themesDirectoryMock)); $this->fileFactoryMock = $this->getMockBuilder('Magento\\Framework\\View\\File\\Factory')->disableOriginalConstructor()->getMock(); $this->themeMock = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->getMock(); }
/** * Publish the asset * * @param Asset\LocalInterface $asset * @return bool */ private function publishAsset(Asset\LocalInterface $asset) { $dir = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR); $rootDir = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::ROOT_DIR); $source = $rootDir->getRelativePath($asset->getSourceFile()); $destination = $asset->getPath(); return $rootDir->copyFile($source, $destination, $dir); }
protected function setUp() { $this->_directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', array(), array(), '', false); $this->_filesystemMock = $this->getMock('Magento\\Framework\\App\\Filesystem', array(), array(), '', false); $this->_filesystemMock->expects($this->any())->method('getPath')->with(\Magento\Framework\App\Filesystem::CONFIG_DIR)->will($this->returnValue(TESTS_TEMP_DIR)); $this->_filesystemMock->expects($this->any())->method('getDirectoryWrite')->will($this->returnValue($this->_directoryMock)); $this->_messageManager = $this->getMock('\\Magento\\Framework\\Message\\ManagerInterface', array(), array(), '', false); $this->_model = new \Magento\Install\Model\Installer\Config($this->getMock('Magento\\Install\\Model\\Installer', array(), array(), '', false), $this->getMock('Magento\\Framework\\App\\RequestInterface', array(), array(), '', false), $this->_filesystemMock, $this->getMock('Magento\\Store\\Model\\StoreManagerInterface', array(), array(), '', false), $this->_messageManager); }
protected function setUp() { $this->filesystemMock = $this->getMock('Magento\\Framework\\App\\Filesystem', array(), array(), '', false, false); $this->directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', array(), array(), '', false, false); $this->_stringMock = $this->getMock('Magento\\Framework\\Stdlib\\String', array(), array(), '', false, false); $this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module')); $this->filesystemMock->expects($this->once())->method('getDirectoryRead')->will($this->returnValue($this->directoryMock)); $this->_model = new \Magento\Framework\Module\Dir($this->filesystemMock, $this->_stringMock); }
/** * Construct * * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Backend\Helper\Data $backendData * @param \Magento\Core\Helper\Data $coreData * @param \Magento\Framework\App\Filesystem $filesystem * @param \Magento\Framework\StoreManagerInterface $storeManager */ public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Backend\Helper\Data $backendData, \Magento\Core\Helper\Data $coreData, \Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\StoreManagerInterface $storeManager) { parent::__construct($context); $this->_backendData = $backendData; $this->_coreData = $coreData; $this->_storeManager = $storeManager; $this->_directory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::MEDIA_DIR); $this->_directory->create(\Magento\Cms\Model\Wysiwyg\Config::IMAGE_DIRECTORY); }
/** * Constructor * * @param \Magento\Framework\Convert\ConvertArray $convertArray * @param \Magento\Framework\App\Filesystem $filesystem * @param Session $session * @param \Magento\Framework\Logger $logger * @param array $data */ public function __construct(\Magento\Framework\Convert\ConvertArray $convertArray, \Magento\Framework\App\Filesystem $filesystem, \Magento\Connect\Model\Session $session, \Magento\Framework\Logger $logger, array $data = array()) { $this->_convertArray = $convertArray; $this->_session = $session; $this->filesystem = $filesystem; $this->writeDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR); $this->logger = $logger; parent::__construct($data); }
/** * Test for get method with primary scope * * @dataProvider providerGet * @param string $filename * @param array $fileList * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function testGetPrimary($filename, $fileList) { $scope = 'primary'; $directory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', array('search', 'getRelativePath'), array(), '', false); $directory->expects($this->once())->method('search')->with(sprintf('{%1$s,*/%1$s}', $filename))->will($this->returnValue($fileList)); $this->filesystem->expects($this->once())->method('getDirectoryRead')->with(\Magento\Framework\App\Filesystem::CONFIG_DIR)->will($this->returnValue($directory)); $this->iteratorFactory->expects($this->once())->method('create')->with($directory, $fileList)->will($this->returnValue(true)); $this->assertTrue($this->model->get($filename, $scope)); }
/** * @param \Magento\Framework\App\Filesystem $filesystem * @param \Magento\Framework\View\Design\Theme\FileFactory $fileFactory * @param \Magento\Core\Model\Layout\Link $link * @param \Magento\Core\Model\Layout\UpdateFactory $updateFactory * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Framework\View\Design\Theme\Customization\Path $customization */ public function __construct(\Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\View\Design\Theme\FileFactory $fileFactory, \Magento\Core\Model\Layout\Link $link, \Magento\Core\Model\Layout\UpdateFactory $updateFactory, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\View\Design\Theme\Customization\Path $customization) { $this->_directory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::MEDIA_DIR); $this->_fileFactory = $fileFactory; $this->_link = $link; $this->_updateFactory = $updateFactory; $this->_eventManager = $eventManager; $this->_customizationPath = $customization; }