コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 /**
  * {@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);
     }
 }
コード例 #3
0
ファイル: Data.php プロジェクト: Atlis/docker-magento2
 /**
  * @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);
 }
コード例 #4
0
ファイル: Image.php プロジェクト: aiesh/magento2
 /**
  * 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;
 }
コード例 #5
0
 /**
  * @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;
 }
コード例 #6
0
ファイル: Minifier.php プロジェクト: Mohitsahu123/mtf
 /**
  * @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;
 }
コード例 #7
0
 /**
  * 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);
 }
コード例 #8
0
ファイル: FileResolver.php プロジェクト: aiesh/magento2
 /**
  * @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;
 }
コード例 #9
0
ファイル: Image.php プロジェクト: aiesh/magento2
 /**
  * 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;
 }
コード例 #10
0
ファイル: CleanMergedJsCss.php プロジェクト: aiesh/magento2
 /**
  * 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);
 }
コード例 #11
0
 /**
  * {@inheritdoc}
  */
 public function publish(Asset\LocalInterface $asset)
 {
     if ($this->appState->getMode() === \Magento\Framework\App\State::MODE_DEVELOPER) {
         return false;
     }
     $dir = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR);
     if ($dir->isExist($asset->getPath())) {
         return true;
     }
     return $this->publishAsset($asset);
 }
コード例 #12
0
ファイル: Link.php プロジェクト: aiesh/magento2
 /**
  * Prepare link to display in grid
  *
  * @param \Magento\Framework\Object $row
  * @return string
  */
 public function render(\Magento\Framework\Object $row)
 {
     /** @var $sitemap \Magento\Sitemap\Model\Sitemap */
     $sitemap = $this->_sitemapFactory->create();
     $url = $this->escapeHtml($sitemap->getSitemapUrl($row->getSitemapPath(), $row->getSitemapFilename()));
     $fileName = preg_replace('/^\\//', '', $row->getSitemapPath() . $row->getSitemapFilename());
     $directory = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::ROOT_DIR);
     if ($directory->isFile($fileName)) {
         return sprintf('<a href="%1$s">%1$s</a>', $url);
     }
     return $url;
 }
コード例 #13
0
ファイル: File.php プロジェクト: aiesh/magento2
 /**
  * Validation callback for checking max file size
  *
  * @param  string $filePath Path to temporary uploaded file
  * @return void
  * @throws \Magento\Framework\Model\Exception
  */
 public function validateMaxSize($filePath)
 {
     $directory = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::SYS_TMP_DIR);
     if ($this->_maxFileSize > 0 && $directory->stat($directory->getRelativePath($filePath))['size'] > $this->_maxFileSize * 1024) {
         throw new \Magento\Framework\Model\Exception(__('The file you\'re uploading exceeds the server size limit of %1 kilobytes.', $this->_maxFileSize));
     }
 }
コード例 #14
0
ファイル: Cert.php プロジェクト: aiesh/magento2
 /**
  * @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);
 }
コード例 #15
0
 /**
  * Get media directory
  *
  * @return \Magento\Framework\Filesystem\Directory\Read
  */
 protected function getMediaDirectory()
 {
     if (!$this->mediaDirectory) {
         $this->mediaDirectory = $this->_filesystem->getDirectoryRead(Filesystem::MEDIA_DIR);
     }
     return $this->mediaDirectory;
 }
コード例 #16
0
 /**
  * @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);
 }
コード例 #17
0
 /**
  * @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;
 }
コード例 #18
0
ファイル: Config.php プロジェクト: pavelnovitsky/magento2
 /**
  * @param \Magento\Framework\App\RequestInterface $request
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Framework\StoreManagerInterface $storeManager
  * @param \Magento\Framework\Message\ManagerInterface $messageManager
  */
 public function __construct(\Magento\Framework\App\RequestInterface $request, \Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Framework\Message\ManagerInterface $messageManager)
 {
     $this->_request = $request;
     $this->_storeManager = $storeManager;
     $this->_filesystem = $filesystem;
     $this->_pubDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::PUB_DIR);
     $this->_configDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::CONFIG_DIR);
     $this->messageManager = $messageManager;
 }
コード例 #19
0
ファイル: Media.php プロジェクト: aiesh/magento2
 /**
  * Collect file info
  *
  * Return array(
  *  filename    => string
  *  content     => string|bool
  *  update_time => string
  *  directory   => string
  *
  * @param string $mediaDirectory
  * @param string $path
  * @return array
  * @throws \Magento\Framework\Model\Exception
  */
 public function collectFileInfo($mediaDirectory, $path)
 {
     $path = ltrim($path, '\\/');
     $fullPath = $mediaDirectory . '/' . $path;
     $dir = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MEDIA_DIR);
     $relativePath = $dir->getRelativePath($fullPath);
     if (!$dir->isFile($relativePath)) {
         throw new \Magento\Framework\Model\Exception(__('File %1 does not exist', $fullPath));
     }
     if (!$dir->isReadable($relativePath)) {
         throw new \Magento\Framework\Model\Exception(__('File %1 is not readable', $fullPath));
     }
     $path = str_replace(array('/', '\\'), '/', $path);
     $directory = dirname($path);
     if ($directory == '.') {
         $directory = null;
     }
     return array('filename' => basename($path), 'content' => $dir->readFile($relativePath), 'update_time' => $this->_date->date(), 'directory' => $directory);
 }
コード例 #20
0
 /**
  * {@inheritdoc}
  */
 public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset)
 {
     $sourceDir = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $mTime = null;
     /** @var \Magento\Framework\View\Asset\MergeableInterface $asset */
     foreach ($assetsToMerge as $asset) {
         $mTime .= $sourceDir->stat($sourceDir->getRelativePath($asset->getSourceFile()))['mtime'];
     }
     if (null === $mTime) {
         return;
         // nothing to merge
     }
     $dat = $resultAsset->getPath() . '.dat';
     $targetDir = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR);
     if (!$targetDir->isExist($dat) || strcmp($mTime, $targetDir->readFile($dat)) !== 0) {
         $this->strategy->merge($assetsToMerge, $resultAsset);
         $targetDir->writeFile($dat, $mTime);
     }
 }
コード例 #21
0
ファイル: Config.php プロジェクト: aiesh/magento2
 /**
  * Initialize dependencies.
  *
  * @param \Magento\Framework\ObjectManager $objectManager
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Webapi\Model\Config $config
  * @param \Magento\Webapi\Model\Config\ClassReflector $classReflector
  * @param \Magento\Webapi\Helper\Data $helper
  */
 public function __construct(\Magento\Framework\ObjectManager $objectManager, \Magento\Framework\App\Filesystem $filesystem, \Magento\Webapi\Model\Config $config, \Magento\Webapi\Model\Config\ClassReflector $classReflector, \Magento\Webapi\Helper\Data $helper)
 {
     // TODO: Check if Service specific XSD is already cached
     $this->modulesDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MODULES_DIR);
     $this->_config = $config;
     $this->_objectManager = $objectManager;
     $this->_helper = $helper;
     $this->_classReflector = $classReflector;
     $this->_initServicesMetadata();
 }
コード例 #22
0
ファイル: Console.php プロジェクト: aiesh/magento2
 /**
  * @param \Magento\Install\Model\Installer\ConsoleFactory $installerFactory
  * @param \Magento\Install\App\Output $output
  * @param \Magento\Framework\App\State $state
  * @param \Magento\Framework\App\ObjectManager\ConfigLoader $loader
  * @param \Magento\Framework\ObjectManager $objectManager
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param Response $response
  * @param array $arguments
  */
 public function __construct(\Magento\Install\Model\Installer\ConsoleFactory $installerFactory, \Magento\Install\App\Output $output, \Magento\Framework\App\State $state, \Magento\Framework\App\ObjectManager\ConfigLoader $loader, \Magento\Framework\ObjectManager $objectManager, \Magento\Framework\App\Filesystem $filesystem, Response $response, array $arguments = array())
 {
     $this->rootDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $this->_loader = $loader;
     $this->_state = $state;
     $this->_installerFactory = $installerFactory;
     $this->_arguments = $this->_buildInitArguments($arguments);
     $this->_output = $output;
     $this->_response = $response;
     $this->_objectManager = $objectManager;
 }
コード例 #23
0
ファイル: File.php プロジェクト: aiesh/magento2
 /**
  * Collect files and directories recursively
  *
  * @param string $dir
  * @return array
  */
 public function getStorageData($dir = '/')
 {
     $files = array();
     $directories = array();
     $directoryInstance = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MEDIA_DIR);
     if ($directoryInstance->isDirectory($dir)) {
         foreach ($directoryInstance->readRecursively($dir) as $path) {
             $itemName = basename($path);
             if ($itemName == '.svn' || $itemName == '.htaccess') {
                 continue;
             }
             if ($directoryInstance->isDirectory($path)) {
                 $directories[] = array('name' => $itemName, 'path' => dirname($path) == '.' ? '/' : dirname($path));
             } else {
                 $files[] = $path;
             }
         }
     }
     return array('files' => $files, 'directories' => $directories);
 }
コード例 #24
0
 /**
  * Initializes application and parses input parameters
  *
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param string $entryPoint
  * @throws \Exception
  */
 public function __construct(\Magento\Framework\App\Filesystem $filesystem, $entryPoint)
 {
     if (isset($_SERVER['REQUEST_METHOD'])) {
         throw new \Exception('This script cannot be run from Browser. This is the shell script.');
     }
     $this->rootDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $this->_entryPoint = $entryPoint;
     $this->_rawArgs = $_SERVER['argv'];
     $this->_applyPhpVariables();
     $this->_parseArgs();
 }
コード例 #25
0
ファイル: Service.php プロジェクト: aiesh/magento2
 /**
  * Constructor
  *
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Framework\File\Size $fileSize
  * @param \Magento\Core\Model\File\UploaderFactory $uploaderFactory
  * @param array $uploadLimits keys are 'css' and 'js' for file type, values defines maximum file size, example: 2M
  */
 public function __construct(\Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\File\Size $fileSize, \Magento\Core\Model\File\UploaderFactory $uploaderFactory, array $uploadLimits = array())
 {
     $this->_tmpDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::SYS_TMP_DIR);
     $this->_fileSize = $fileSize;
     $this->_uploaderFactory = $uploaderFactory;
     if (isset($uploadLimits['css'])) {
         $this->_cssUploadLimit = $uploadLimits['css'];
     }
     if (isset($uploadLimits['js'])) {
         $this->_jsUploadLimit = $uploadLimits['js'];
     }
 }
コード例 #26
0
ファイル: Media.php プロジェクト: pavelnovitsky/magento2
 /**
  * @param ObjectManager $objectManager
  * @param Request $request
  * @param Response $response
  * @param \Closure $isAllowed
  * @param string $workingDirectory
  * @param string $mediaDirectory
  * @param string $configCacheFile
  * @param string $relativeFileName
  * @param \Magento\Framework\App\Filesystem $filesystem
  */
 public function __construct(ObjectManager $objectManager, Request $request, Response $response, \Closure $isAllowed, $workingDirectory, $mediaDirectory, $configCacheFile, $relativeFileName, \Magento\Framework\App\Filesystem $filesystem)
 {
     $this->_objectManager = $objectManager;
     $this->_request = $request;
     $this->_response = $response;
     $this->_isAllowed = $isAllowed;
     $this->_workingDirectory = $workingDirectory;
     $this->_mediaDirectory = $mediaDirectory;
     $this->_configCacheFile = $configCacheFile;
     $this->_relativeFileName = $relativeFileName;
     $this->filesystem = $filesystem;
     $this->directory = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MEDIA_DIR);
 }
コード例 #27
0
ファイル: Factory.php プロジェクト: aiesh/magento2
 /**
  * Create new instance
  *
  * @param string $type
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @param \Magento\Framework\View\Design\ThemeInterface $parentTheme
  * @param string[] $files
  * @return \Magento\DesignEditor\Model\Editor\Tools\Controls\Configuration
  * @throws \Magento\Framework\Exception
  */
 public function create($type, \Magento\Framework\View\Design\ThemeInterface $theme = null, \Magento\Framework\View\Design\ThemeInterface $parentTheme = null, array $files = array())
 {
     $files[] = $this->_getFilePathByType($type, $theme);
     switch ($type) {
         case self::TYPE_QUICK_STYLES:
             $class = 'Magento\\DesignEditor\\Model\\Config\\Control\\QuickStyles';
             break;
         case self::TYPE_IMAGE_SIZING:
             $class = 'Magento\\DesignEditor\\Model\\Config\\Control\\ImageSizing';
             break;
         default:
             throw new \Magento\Framework\Exception("Unknown control configuration type: \"{$type}\"");
     }
     $rootDirectory = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $paths = array();
     foreach ($files as $file) {
         $paths[] = $rootDirectory->getRelativePath($file);
     }
     $fileIterator = $this->fileIteratorFactory->create($rootDirectory, $paths);
     /** @var $config \Magento\DesignEditor\Model\Config\Control\AbstractControl */
     $config = $this->_objectManager->create($class, array('configFiles' => $fileIterator));
     return $this->_objectManager->create('Magento\\DesignEditor\\Model\\Editor\\Tools\\Controls\\Configuration', array('configuration' => $config, 'theme' => $theme, 'parentTheme' => $parentTheme));
 }
コード例 #28
0
ファイル: Tablerate.php プロジェクト: aiesh/magento2
 /**
  * Upload table rate file and import data from it
  *
  * @param \Magento\Framework\Object $object
  * @throws \Magento\Framework\Model\Exception
  * @return \Magento\OfflineShipping\Model\Resource\Carrier\Tablerate
  * @todo: this method should be refactored as soon as updated design will be provided
  * @see https://wiki.corp.x.com/display/MCOMS/Magento+Filesystem+Decisions
  */
 public function uploadAndImport(\Magento\Framework\Object $object)
 {
     if (empty($_FILES['groups']['tmp_name']['tablerate']['fields']['import']['value'])) {
         return $this;
     }
     $csvFile = $_FILES['groups']['tmp_name']['tablerate']['fields']['import']['value'];
     $website = $this->_storeManager->getWebsite($object->getScopeId());
     $this->_importWebsiteId = (int) $website->getId();
     $this->_importUniqueHash = array();
     $this->_importErrors = array();
     $this->_importedRows = 0;
     $tmpDirectory = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::SYS_TMP_DIR);
     $path = $tmpDirectory->getRelativePath($csvFile);
     $stream = $tmpDirectory->openFile($path);
     // check and skip headers
     $headers = $stream->readCsv();
     if ($headers === false || count($headers) < 5) {
         $stream->close();
         throw new \Magento\Framework\Model\Exception(__('Please correct Table Rates File Format.'));
     }
     if ($object->getData('groups/tablerate/fields/condition_name/inherit') == '1') {
         $conditionName = (string) $this->_coreConfig->getValue('carriers/tablerate/condition_name', 'default');
     } else {
         $conditionName = $object->getData('groups/tablerate/fields/condition_name/value');
     }
     $this->_importConditionName = $conditionName;
     $adapter = $this->_getWriteAdapter();
     $adapter->beginTransaction();
     try {
         $rowNumber = 1;
         $importData = array();
         $this->_loadDirectoryCountries();
         $this->_loadDirectoryRegions();
         // delete old data by website and condition name
         $condition = array('website_id = ?' => $this->_importWebsiteId, 'condition_name = ?' => $this->_importConditionName);
         $adapter->delete($this->getMainTable(), $condition);
         while (false !== ($csvLine = $stream->readCsv())) {
             $rowNumber++;
             if (empty($csvLine)) {
                 continue;
             }
             $row = $this->_getImportRow($csvLine, $rowNumber);
             if ($row !== false) {
                 $importData[] = $row;
             }
             if (count($importData) == 5000) {
                 $this->_saveImportData($importData);
                 $importData = array();
             }
         }
         $this->_saveImportData($importData);
         $stream->close();
     } catch (\Magento\Framework\Model\Exception $e) {
         $adapter->rollback();
         $stream->close();
         throw new \Magento\Framework\Model\Exception($e->getMessage());
     } catch (\Exception $e) {
         $adapter->rollback();
         $stream->close();
         $this->_logger->logException($e);
         throw new \Magento\Framework\Model\Exception(__('Something went wrong while importing table rates.'));
     }
     $adapter->commit();
     if ($this->_importErrors) {
         $error = __('We couldn\'t import this file because of these errors: %1', implode(" \n", $this->_importErrors));
         throw new \Magento\Framework\Model\Exception($error);
     }
     return $this;
 }
コード例 #29
0
ファイル: FilesystemTest.php プロジェクト: aiesh/magento2
 /**
  * Test getDirectoryRead method return valid instance
  */
 public function testGetDirectoryReadInstance()
 {
     $dir = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::VAR_DIR);
     $this->assertInstanceOf('\\Magento\\Framework\\Filesystem\\Directory\\Read', $dir);
 }
コード例 #30
0
ファイル: Carrier.php プロジェクト: aiesh/magento2
 /**
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Sales\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
  * @param \Magento\Framework\Logger\AdapterFactory $logAdapterFactory
  * @param \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory
  * @param \Magento\Shipping\Model\Rate\ResultFactory $rateFactory
  * @param \Magento\Sales\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory
  * @param \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory
  * @param \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory
  * @param \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory
  * @param \Magento\Directory\Model\RegionFactory $regionFactory
  * @param \Magento\Directory\Model\CountryFactory $countryFactory
  * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
  * @param \Magento\Directory\Helper\Data $directoryData
  * @param \Magento\Shipping\Helper\Carrier $carrierHelper
  * @param \Magento\Framework\Stdlib\DateTime\DateTime $coreDate
  * @param \Magento\Framework\Module\Dir\Reader $configReader
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\Stdlib\String $string
  * @param \Magento\Framework\Math\Division $mathDivision
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param \Magento\Framework\Stdlib\DateTime $dateTime
  * @param \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory
  * @param \Magento\CatalogInventory\Service\V1\StockItemService $stockItemService
  * @param array $data
  */
 public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Sales\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Magento\Framework\Logger\AdapterFactory $logAdapterFactory, \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory, \Magento\Shipping\Model\Rate\ResultFactory $rateFactory, \Magento\Sales\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory, \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory, \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Directory\Helper\Data $directoryData, \Magento\CatalogInventory\Service\V1\StockItemService $stockItemService, \Magento\Shipping\Helper\Carrier $carrierHelper, \Magento\Framework\Stdlib\DateTime\DateTime $coreDate, \Magento\Framework\Module\Dir\Reader $configReader, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\String $string, \Magento\Framework\Math\Division $mathDivision, \Magento\Framework\App\Filesystem $filesystem, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory, array $data = array())
 {
     $this->modulesDirectory = $filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MODULES_DIR);
     $this->_carrierHelper = $carrierHelper;
     $this->_coreDate = $coreDate;
     $this->_storeManager = $storeManager;
     $this->_configReader = $configReader;
     $this->string = $string;
     $this->mathDivision = $mathDivision;
     $this->_dateTime = $dateTime;
     $this->_httpClientFactory = $httpClientFactory;
     $this->stockItemService = $stockItemService;
     parent::__construct($scopeConfig, $rateErrorFactory, $logAdapterFactory, $xmlElFactory, $rateFactory, $rateMethodFactory, $trackFactory, $trackErrorFactory, $trackStatusFactory, $regionFactory, $countryFactory, $currencyFactory, $directoryData, $stockItemService, $data);
     if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_DOC) {
         $this->_freeMethod = 'free_method_doc';
     }
 }