本文整理汇总了PHP中Magento\Framework\Filesystem::getDirectoryRead方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::getDirectoryRead方法的具体用法?PHP Filesystem::getDirectoryRead怎么用?PHP Filesystem::getDirectoryRead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem
的用法示例。
在下文中一共展示了Filesystem::getDirectoryRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param \Magento\Framework\Filesystem $filesystem
* @param string $filename
*/
public function __construct(\Magento\Framework\Filesystem $filesystem, $filename = \Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME)
{
$this->filesystem = $filesystem;
$this->filename = $filename;
$this->mediaDirectoryRead = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$this->themeDirectoryRead = $this->filesystem->getDirectoryRead(DirectoryList::THEMES);
}
示例2: checkJson
/**
* Check JSON file created by Setup cron command and Updater cron script
*
* @param string $type
* @return array
*/
private function checkJson($type)
{
$read = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
try {
switch ($type) {
case self::SETUP:
$key = ReadinessCheck::KEY_DB_WRITE_PERMISSION_VERIFIED;
$jsonData = json_decode($read->readFile(ReadinessCheck::SETUP_CRON_JOB_STATUS_FILE), true);
break;
case self::UPDATER:
$key = self::UPDATER_KEY_FILE_PERMISSIONS_VERIFIED;
$jsonData = json_decode($read->readFile(self::UPDATER_CRON_JOB_STATS_FILE), true);
break;
default:
return ['success' => false, 'error' => 'Internal Error'];
}
} catch (\Magento\Framework\Exception\FileSystemException $e) {
$error = 'Cron job has not been configured yet';
if ($type == self::SETUP) {
$error .= self::OTHER_CHECKS_WILL_FAIL_MSG;
}
return ['success' => false, 'error' => $error];
}
if (isset($jsonData[ReadinessCheck::KEY_READINESS_CHECKS]) && isset($jsonData[ReadinessCheck::KEY_READINESS_CHECKS][$key])) {
if ($jsonData[ReadinessCheck::KEY_READINESS_CHECKS][$key]) {
return $this->checkCronTime($jsonData);
}
return ['success' => false, 'error' => $jsonData[ReadinessCheck::KEY_READINESS_CHECKS]['error']];
}
$error = 'Cron job has not been configured yet';
if ($type == self::SETUP) {
$error .= self::OTHER_CHECKS_WILL_FAIL_MSG;
}
return ['success' => false, 'error' => $error];
}
示例3: __construct
/**
* @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(DirectoryList::LIB_WEB);
$this->themesDirectory = $filesystem->getDirectoryRead(DirectoryList::THEMES);
$this->fileFactory = $fileFactory;
}
示例4: testGetDirectoryRead
public function testGetDirectoryRead()
{
/** @var \Magento\Framework\Filesystem\Directory\ReadInterface $dirReadMock */
$dirReadMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
$this->_dirReadFactoryMock->expects($this->once())->method('create')->will($this->returnValue($dirReadMock));
$this->assertEquals($dirReadMock, $this->_filesystem->getDirectoryRead(DirectoryList::ROOT));
}
示例5: afterSave
/**
* Save uploaded file and set its name to category
*
* @param \Magento\Framework\DataObject $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(DirectoryList::MEDIA)->getAbsolutePath('catalog/category/');
try {
/** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
$uploader = $this->_fileUploaderFactory->create(['fileId' => $this->getAttribute()->getName()]);
$uploader->setAllowedExtensions(['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\MediaStorage\Model\File\Uploader::TMP_NAME_EMPTY) {
$this->_logger->critical($e);
}
}
return $this;
}
示例6: __construct
/**
* Constructor
*
* @param \Magento\Framework\Filesystem $filesystem
* @param ComponentRegistrarInterface $componentRegistrar
* @param string $filename
*/
public function __construct(\Magento\Framework\Filesystem $filesystem, ComponentRegistrarInterface $componentRegistrar, $filename = \Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME)
{
$this->filesystem = $filesystem;
$this->filename = $filename;
$this->mediaDirectoryRead = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$this->componentRegistrar = $componentRegistrar;
}
示例7: execute
/**
* Image upload action in iframe
*
* @return string
*/
public function execute()
{
try {
$uploader = $this->uploaderFactory->create(['fileId' => 'datafile']);
$uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
/** @var \Magento\Framework\Image\Adapter\AdapterInterface $imageAdapter */
$imageAdapter = $this->adapterFactory->create();
$uploader->addValidateCallback('catalog_product_image', $imageAdapter, 'validateUploadFile');
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
/** @var \Magento\Framework\Filesystem\Directory\Read $mediaDirectory */
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$config = $this->config;
$result = $uploader->save($mediaDirectory->getAbsolutePath($config->getBaseTmpMediaPath()));
$this->_eventManager->dispatch('swatch_gallery_upload_image_after', ['result' => $result, 'action' => $this]);
unset($result['tmp_name']);
unset($result['path']);
$result['url'] = $this->config->getTmpMediaUrl($result['file']);
$result['file'] = $result['file'] . '.tmp';
$newFile = $this->swatchHelper->moveImageFromTmp($result['file']);
$this->swatchHelper->generateSwatchVariations($newFile);
$fileData = ['swatch_path' => $this->swatchHelper->getSwatchMediaUrl(), 'file_path' => $newFile];
$this->getResponse()->setBody(json_encode($fileData));
} catch (\Exception $e) {
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
$this->getResponse()->setBody(json_encode($result));
}
}
示例8: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->updateMemoryLimit();
$sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages();
if (!empty($sampleDataPackages)) {
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
$commonArgs = ['--working-dir' => $baseDir, '--no-progress' => 1];
$packages = [];
foreach ($sampleDataPackages as $name => $version) {
$packages[] = "{$name}:{$version}";
}
$commonArgs = array_merge(['packages' => $packages], $commonArgs);
$arguments = array_merge(['command' => 'require'], $commonArgs);
/** @var ArrayInput $commandInput */
$commandInput = $this->arrayInputFactory->create(['parameters' => $arguments]);
/** @var Application $application */
$application = $this->applicationFactory->create();
$application->setAutoExit(false);
$result = $application->run($commandInput, $output);
if ($result !== 0) {
$output->writeln('<info>' . 'There is an error during sample data deployment.' . '</info>');
}
} else {
$output->writeln('<info>' . 'There is no sample data for current set of modules.' . '</info>');
}
}
示例9: merge
/**
* {@inheritdoc}
*/
public function merge(array $assetsToMerge, \Magento\Framework\View\Asset\LocalInterface $resultAsset)
{
$dir = $this->filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
if (!$dir->isExist($resultAsset->getPath())) {
$this->strategy->merge($assetsToMerge, $resultAsset);
}
}
示例10: sizeValidate
/**
* Validate image size.
*
* @param $filePath
*
* @throws LocalizedException
*/
public function sizeValidate($filePath)
{
$directory = $this->_filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
if ($this->_maxSize > 0 && $directory->stat($directory->getRelativePath($filePath))['size'] > $this->_maxSize * 1024) {
throw new LocalizedException(__('The file you\'re uploading exceeds the server size limit of %1 kilobytes.', $this->_maxSize));
}
}
示例11: afterSave
/**
* After save
*
* @param \Magento\Framework\DataObject $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\MediaStorage\Model\File\Uploader */
$uploader = $this->_fileUploaderFactory->create(['fileId' => $this->getAttribute()->getName()]);
$uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
} catch (\Exception $e) {
return $this;
}
$path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->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;
}
示例12: read
/**
* {@inheritdoc}
*/
public function read($sessionId)
{
try {
return parent::read($sessionId);
} catch (ConcurrentConnectionsExceededException $e) {
require $this->filesystem->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/503.php');
}
}
示例13: publish
/**
* @param Asset\LocalInterface $asset
* @return bool
*/
public function publish(Asset\LocalInterface $asset)
{
$dir = $this->filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
if ($dir->isExist($asset->getPath())) {
return true;
}
return $this->publishAsset($asset);
}
示例14: __construct
/**
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Framework\Config\ThemeFactory $themeConfigFactory
*/
public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Config\ThemeFactory $themeConfigFactory, \Magento\Framework\Module\ThemeDir $themeDirs)
{
parent::__construct($entityFactory);
$this->_directory = $filesystem->getDirectoryRead(DirectoryList::THEMES);
$this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
$this->themeConfigFactory = $themeConfigFactory;
$this->themeDirs = $themeDirs;
}
示例15: __construct
/**
* Constructor
*
* @param Filesystem $filesystem
* @param Factory $fileFactory
* @param string $subDir
*/
public function __construct(Filesystem $filesystem, Factory $fileFactory, \Magento\Framework\Module\ThemeDir $themeDirs, $subDir = '')
{
$this->themesDirectory = $filesystem->getDirectoryRead(DirectoryList::THEMES);
$this->themeDirs = $themeDirs;
$this->fileFactory = $fileFactory;
$this->subDir = $subDir ? $subDir . '/' : '';
$this->modulesDir = $filesystem->getDirectoryRead(DirectoryList::MODULES);
}