本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\WriteInterface::getAbsolutePath方法的典型用法代码示例。如果您正苦于以下问题:PHP WriteInterface::getAbsolutePath方法的具体用法?PHP WriteInterface::getAbsolutePath怎么用?PHP WriteInterface::getAbsolutePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\WriteInterface
的用法示例。
在下文中一共展示了WriteInterface::getAbsolutePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFile
/**
* Write down contents to a temporary file and return its absolute path
*
* @param string $relativePath
* @param string $contents
* @return string
*/
public function createFile($relativePath, $contents)
{
$filePath = $this->config->getLessMaterializationRelativePath() . '/' . $relativePath;
if (!$this->tmpDirectory->isExist($filePath)) {
$this->tmpDirectory->writeFile($filePath, $contents);
}
return $this->tmpDirectory->getAbsolutePath($filePath);
}
示例2: setUp
protected function setUp()
{
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$filesystem = $this->_objectManager->create('Magento\\Framework\\App\\Filesystem');
$this->_varDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
$fullFileName = $this->_varDirectory->getAbsolutePath(self::FILE_PATH);
$this->_testFileHandler = fopen($fullFileName, 'w');
}
示例3: uploadFromTmp
/**
* Upload file from temporary folder.
* @param string $tmpPath
* @param \Magento\Core\Model\File\Uploader $uploader
* @return array
*/
public function uploadFromTmp($tmpPath, \Magento\Core\Model\File\Uploader $uploader)
{
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$absoluteTmpPath = $this->_mediaDirectory->getAbsolutePath($tmpPath);
$result = $uploader->save($absoluteTmpPath);
return $result;
}
示例4: execute
/**
* Flash ISM_BaseRunner cache
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$dir = $this->_mediaDirectory->getAbsolutePath(Upload::UPLOAD_POST_IMAGE_DIR . 'cache/');
if (is_dir($dir)) {
$dir = $this->_mediaDirectory->getDriver()->readDirectory($dir);
foreach ($dir as $file) {
$this->_mediaDirectory->delete(Upload::UPLOAD_POST_IMAGE_DIR . 'cache/' . basename($file));
}
}
}
示例5: _generateRow
/**
* Get backup-specific data from model for each row
*
* @param string $filename
* @return array
*/
protected function _generateRow($filename)
{
$row = parent::_generateRow($filename);
foreach ($this->_backup->load($row['basename'], $this->_varDirectory->getAbsolutePath($this->_path))->getData() as $key => $value) {
$row[$key] = $value;
}
$row['size'] = $this->_varDirectory->stat($this->_varDirectory->getRelativePath($filename))['size'];
$row['id'] = $row['time'] . '_' . $row['type'];
return $row;
}
示例6: getCertPath
/**
* Get path to PayPal certificate file, if file does not exist try to create it
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getCertPath()
{
if (!$this->getContent()) {
throw new \Magento\Framework\Exception\LocalizedException(__('The PayPal certificate does not exist.'));
}
$certFileName = sprintf('cert_%s_%s.pem', $this->getWebsiteId(), strtotime($this->getUpdatedAt()));
$certFile = self::BASEPATH_PAYPAL_CERT . $certFileName;
if (!$this->varDirectory->isExist($certFile)) {
$this->_createCertFile($certFile);
}
return $this->varDirectory->getAbsolutePath($certFile);
}
示例7: _generateRow
/**
* Get backup-specific data from model for each row
*
* @param string $filename
* @return array
*/
protected function _generateRow($filename)
{
$row = parent::_generateRow($filename);
foreach ($this->_backup->load($row['basename'], $this->_varDirectory->getAbsolutePath($this->_path))->getData() as $key => $value) {
$row[$key] = $value;
}
$row['size'] = $this->_varDirectory->stat($this->_varDirectory->getRelativePath($filename))['size'];
if (isset($row['display_name']) && $row['display_name'] == '') {
$row['display_name'] = 'WebSetupWizard';
}
$row['id'] = $row['time'] . '_' . $row['type'] . (isset($row['display_name']) ? $row['display_name'] : '');
return $row;
}
示例8: unpackDb
/**
* @param string $dbCode
* @throws LocalizedException
*/
protected function unpackDb($dbCode)
{
$this->archive->unpack($this->directory->getAbsolutePath($this->getDbArchiveFilePath($dbCode)), $this->directory->getAbsolutePath($this->database->getDbPath($dbCode)));
if (!$this->directory->isExist($this->database->getDbPath($dbCode))) {
throw new LocalizedException(__('Cannot unpack db file.'));
}
}
示例9: saveFileToTmpDir
/**
* Checking file for save and save it to tmp dir
*
* @param string $fileId
*
* @return string[]
*
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function saveFileToTmpDir($fileId)
{
$baseTmpPath = $this->getBaseTmpPath();
$uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
$uploader->setAllowedExtensions($this->getAllowedExtensions());
$uploader->setAllowRenameFiles(true);
$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));
if (!$result) {
throw new \Magento\Framework\Exception\LocalizedException(__('File can not be saved to the destination folder.'));
}
/**
* Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
*/
$result['tmp_name'] = str_replace('\\', '/', $result['tmp_name']);
$result['path'] = str_replace('\\', '/', $result['path']);
$result['url'] = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $this->getFilePath($baseTmpPath, $result['file']);
$result['name'] = $result['file'];
if (isset($result['file'])) {
try {
$relativePath = rtrim($baseTmpPath, '/') . '/' . ltrim($result['file'], '/');
$this->coreFileStorageDatabase->saveFile($relativePath);
} catch (\Exception $e) {
$this->logger->critical($e);
throw new \Magento\Framework\Exception\LocalizedException(__('Something went wrong while saving the file(s).'));
}
}
return $result;
}
示例10: preProcess
/**
* Perform necessary preprocessing and materialization when the specified asset is requested
*
* Returns an array of two elements:
* - directory where the file is supposed to be found
* - relative path to the file
*
* returns false if source file was not found
*
* @param LocalInterface $asset
* @return array|bool
*/
private function preProcess(LocalInterface $asset)
{
$sourceFile = $this->findSourceFile($asset);
$dir = $this->rootDir->getAbsolutePath();
$path = '';
if ($sourceFile) {
$path = basename($sourceFile);
$dir = dirname($sourceFile);
}
$chain = $this->createChain($asset, $dir, $path);
$this->preProcessorPool->process($chain);
$chain->assertValid();
if ($chain->isChanged()) {
$dir = $this->varDir->getAbsolutePath();
$path = DirectoryList::TMP_MATERIALIZATION_DIR . '/source/' . $chain->getTargetAssetPath();
$this->varDir->writeFile($path, $chain->getContent());
}
if (empty($path)) {
$result = false;
} else {
$result = [$dir, $path];
}
return $result;
}
示例11: saveImage
/**
* Save new image and remove old image.
*
* @param $file string new file
* @param $old string old file
*
* @return string file name
* @throws LocalizedException
*/
public function saveImage($file, $old)
{
$uploadDir = $this->_mediaDirectory->getAbsolutePath(self::UPLOAD_POST_IMAGE_DIR);
try {
$uploader = $this->_uploaderFactory->create(['fileId' => $file]);
$uploader->setAllowedExtensions(self::TYPES_ALLOWED);
$uploader->setAllowRenameFiles(true);
$uploader->addValidateCallback('size', $this, 'validateMaxSize');
$result = $uploader->save($uploadDir);
} catch (\Exception $e) {
throw new LocalizedException(__($e->getMessage()));
}
if ($old) {
$this->removeImage($old);
}
return $result['file'];
}
示例12: getUniqueFileName
/**
* Check whether file to move exists. Getting unique name
*
* @param string $file
* @param bool $forTmp
* @return string
*/
protected function getUniqueFileName($file, $forTmp = false)
{
if ($this->fileStorageDb->checkDbUsage()) {
$destFile = $this->fileStorageDb->getUniqueFilename($this->mediaConfig->getBaseMediaUrlAddition(), $file);
} else {
$destinationFile = $forTmp ? $this->mediaDirectory->getAbsolutePath($this->mediaConfig->getTmpMediaPath($file)) : $this->mediaDirectory->getAbsolutePath($this->mediaConfig->getMediaPath($file));
$destFile = dirname($file) . '/' . \Magento\MediaStorage\Model\File\Uploader::getNewFileName($destinationFile);
}
return $destFile;
}
示例13: _moveFile
/**
* Move files from TMP folder into destination folder
*
* @param string $tmpPath
* @param string $destPath
* @return bool
*/
protected function _moveFile($tmpPath, $destPath)
{
if ($this->_directory->isFile($tmpPath)) {
$tmpRealPath = $this->_directory->getDriver()->getRealPath($this->_directory->getAbsolutePath($tmpPath));
$destinationRealPath = $this->_directory->getDriver()->getRealPath($this->_directory->getAbsolutePath($destPath));
$isSameFile = $tmpRealPath === $destinationRealPath;
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $destPath);
} else {
return false;
}
}
示例14: checkAndCreate
/**
* Check thumbnail and create it if need.
*
* @return bool
*/
public function checkAndCreate()
{
if ($this->_mediaDirectory->isFile($this->_cacheDir . $this->_post->getImageUrl())) {
return true;
}
if (!$this->_mediaDirectory->isFile(Upload::UPLOAD_POST_IMAGE_DIR . $this->_post->getImageUrl())) {
return false;
}
$image = $this->_imageFactory->create(array('file' => $this->_mediaDirectory->getAbsolutePath(Upload::UPLOAD_POST_IMAGE_DIR . $this->_post->getImageUrl())));
$image->setWH(75, 75);
$image->resize();
$image->save(DirectoryList::PUB . DIRECTORY_SEPARATOR . DirectoryList::MEDIA . DIRECTORY_SEPARATOR . $this->_cacheDir . $this->_post->getImageUrl());
return true;
}
示例15: getDestinationDirectory
/**
* Retrieve destination directory for given content type
*
* @param string $contentType
* @return string
* @throws \InvalidArgumentException
*/
protected function getDestinationDirectory($contentType)
{
switch ($contentType) {
case 'link_file':
$directory = $this->mediaDirectory->getAbsolutePath($this->linkConfig->getBaseTmpPath());
break;
case 'link_sample_file':
$directory = $this->mediaDirectory->getAbsolutePath($this->linkConfig->getBaseSampleTmpPath());
break;
case 'sample':
$directory = $this->mediaDirectory->getAbsolutePath($this->sampleConfig->getBaseTmpPath());
break;
default:
throw new \InvalidArgumentException('Invalid downloadable file content type.');
}
return $directory;
}