本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\Write::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Write::create方法的具体用法?PHP Write::create怎么用?PHP Write::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\Write
的用法示例。
在下文中一共展示了Write::create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpBeforeClass
public static function setUpBeforeClass()
{
/** @var \Magento\Framework\App\Filesystem $filesystem */
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\Filesystem');
self::$_varDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
self::$_tmpDir = self::$_varDirectory->getAbsolutePath('ConfigTest');
self::$_varDirectory->create(self::$_varDirectory->getRelativePath(self::$_tmpDir));
}
示例2: __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'));
}
示例3: __construct
/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Backend\Model\Session $session
* @param \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory
*/
public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Filesystem $filesystem, \Magento\Backend\Model\Session $session, \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory)
{
parent::__construct($context);
$this->filesystem = $filesystem;
$this->_session = $session;
$this->_themeFactory = $themeFactory;
$this->mediaDirectoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->mediaDirectoryWrite->create($this->mediaDirectoryWrite->getRelativePath($this->getStorageRoot()));
}
示例4: _saveFatalErrorReport
/**
* Log information about fatal error.
*
* @param string $reportData
* @return string
*/
protected function _saveFatalErrorReport($reportData)
{
$this->directoryWrite->create('report/api');
$reportId = abs(intval(microtime(true) * rand(100, 1000)));
$this->directoryWrite->writeFile('report/api/' . $reportId, serialize($reportData));
return $reportId;
}
示例5: check
/**
* Check var/generation read and write access
*
* @return bool
*/
public function check()
{
$initParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
$filesystemDirPaths = isset($initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : [];
$directoryList = new DirectoryList(BP, $filesystemDirPaths);
$generationDirectoryPath = $directoryList->getPath(DirectoryList::GENERATION);
$driverPool = new DriverPool();
$fileWriteFactory = new WriteFactory($driverPool);
/** @var \Magento\Framework\Filesystem\DriverInterface $driver */
$driver = $driverPool->getDriver(DriverPool::FILE);
$directoryWrite = new Write($fileWriteFactory, $driver, $generationDirectoryPath);
if ($directoryWrite->isExist()) {
if ($directoryWrite->isDirectory() || $directoryWrite->isReadable()) {
try {
$probeFilePath = $generationDirectoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . 'tmp';
$fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w');
$driver->deleteFile($probeFilePath);
} catch (\Exception $e) {
return false;
}
} else {
return false;
}
} else {
try {
$directoryWrite->create();
} catch (\Exception $e) {
return false;
}
}
return true;
}
示例6: resizeFile
/**
* Create thumbnail for image and save it to thumbnails directory
*
* @param string $source Image path to be resized
* @param bool $keepRation Keep aspect ratio or not
* @return bool|string Resized filepath or false if errors were occurred
*/
public function resizeFile($source, $keepRation = true)
{
$realPath = $this->_directory->getRelativePath($source);
if (!$this->_directory->isFile($realPath) || !$this->_directory->isExist($realPath)) {
return false;
}
$targetDir = $this->getThumbsPath($source);
$pathTargetDir = $this->_directory->getRelativePath($targetDir);
if (!$this->_directory->isExist($pathTargetDir)) {
$this->_directory->create($pathTargetDir);
}
if (!$this->_directory->isExist($pathTargetDir)) {
return false;
}
$image = $this->_imageFactory->create();
$image->open($source);
$image->keepAspectRatio($keepRation);
$image->resize($this->_resizeParameters['width'], $this->_resizeParameters['height']);
$dest = $targetDir . '/' . pathinfo($source, PATHINFO_BASENAME);
$image->save($dest);
if ($this->_directory->isFile($this->_directory->getRelativePath($dest))) {
return $dest;
}
return false;
}
示例7: createPackageV1x
/**
* Create package file compatible with previous version of Magento Connect Manager
*
* @return boolean
*/
public function createPackageV1x()
{
try {
$this->writeDirectory->create('pear/');
} catch (\Magento\Framework\Filesystem\FilesystemException $e) {
$this->logger->addStreamLog(\Magento\Framework\Logger::LOGGER_EXCEPTION);
$this->logger->log($e->getMessage());
return false;
}
if (!$this->getPackageXml()) {
$this->generatePackageXml();
}
$this->getPackage()->saveV1x($this->writeDirectory->getAbsolutePath('pear/'));
return true;
}
示例8: createFolder
/**
* Create folder
*
* @param string $name
* @param string $path
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function createFolder($name, $path)
{
if (!preg_match(self::DIRECTORY_NAME_REGEXP, $name)) {
throw new \Magento\Framework\Exception\LocalizedException(__('Use only standard alphanumeric, dashes and underscores.'));
}
if (!$this->mediaWriteDirectory->isWritable($path)) {
$path = $this->_helper->getStorageRoot();
}
$newPath = $path . '/' . $name;
if ($this->mediaWriteDirectory->isExist($newPath)) {
throw new \Magento\Framework\Exception\LocalizedException(__('We found a directory with the same name.'));
}
$this->mediaWriteDirectory->create($newPath);
$result = ['name' => $name, 'short_name' => $this->_helper->getShortFilename($name), 'path' => str_replace($this->_helper->getStorageRoot(), '', $newPath), 'id' => $this->_helper->convertPathToId($newPath)];
return $result;
}
示例9: getCurrentPath
/**
* Return path of the current selected directory or root directory for startup
* Try to create target directory if it doesn't exist
*
* @return string
* @throws \Magento\Framework\Model\Exception
*/
public function getCurrentPath()
{
if (!$this->_currentPath) {
$currentPath = $this->_directory->getAbsolutePath() . \Magento\Cms\Model\Wysiwyg\Config::IMAGE_DIRECTORY;
$path = $this->_getRequest()->getParam($this->getTreeNodeName());
if ($path) {
$path = $this->convertIdToPath($path);
if ($this->_directory->isDirectory($this->_directory->getRelativePath($path))) {
$currentPath = $path;
}
}
try {
$currentDir = $this->_directory->getRelativePath($currentPath);
if (!$this->_directory->isExist($currentDir)) {
$this->_directory->create($currentDir);
}
} catch (\Magento\Framework\Filesystem\FilesystemException $e) {
$message = __('The directory %1 is not writable by server.', $currentPath);
throw new \Magento\Framework\Model\Exception($message);
}
$this->_currentPath = $currentPath;
}
return $this->_currentPath;
}
示例10: testCreate
public function testCreate()
{
$this->driver->expects($this->once())->method('isDirectory')->will($this->returnValue(false));
$this->driver->expects($this->once())->method('createDirectory')->will($this->returnValue(true));
$this->assertTrue($this->write->create('correct-path'));
}