本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\WriteInterface::isFile方法的典型用法代码示例。如果您正苦于以下问题:PHP WriteInterface::isFile方法的具体用法?PHP WriteInterface::isFile怎么用?PHP WriteInterface::isFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\WriteInterface
的用法示例。
在下文中一共展示了WriteInterface::isFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _hideBackupsForApache
/**
* Create .htaccess file and deny backups directory access from web
*
* @return void
*/
protected function _hideBackupsForApache()
{
$filename = '.htaccess';
if (!$this->_varDirectory->isFile($filename)) {
$this->_varDirectory->writeFile($filename, 'deny from all');
}
}
示例2: _deleteExpiredImagesForWebsite
/**
* Delete Expired Captcha Images for specific website
*
* @param \Magento\Captcha\Helper\Data $helper
* @param \Magento\Store\Model\Website|null $website
* @param \Magento\Store\Model\Store|null $store
* @return void
*/
protected function _deleteExpiredImagesForWebsite(\Magento\Captcha\Helper\Data $helper, \Magento\Store\Model\Website $website = null, \Magento\Store\Model\Store $store = null)
{
$expire = time() - $helper->getConfig('timeout', $store) * 60;
$imageDirectory = $this->_mediaDirectory->getRelativePath($helper->getImgDir($website));
foreach ($this->_mediaDirectory->read($imageDirectory) as $filePath) {
if ($this->_mediaDirectory->isFile($filePath) && pathinfo($filePath, PATHINFO_EXTENSION) == 'png' && $this->_mediaDirectory->stat($filePath)['mtime'] < $expire) {
$this->_mediaDirectory->delete($filePath);
}
}
}
示例3: ensureFileInFilesystem
/**
* Check if file exist in filesystem and try to re-create it from database record if negative.
* @param string $file
* @return bool|int
*/
public function ensureFileInFilesystem($file)
{
$result = true;
if (!$this->_mediaDirectory->isFile($file)) {
$result = $this->_coreFileStorageDatabase->saveFileToFilesystem($file);
}
return $result;
}
示例4: _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)) {
return $this->_directory->copyFile($tmpPath, $destPath);
} else {
return false;
}
}
示例5: execute
/**
* Download sample file action
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$fileName = $this->getRequest()->getParam('filename') . '.csv';
$filePath = self::SAMPLE_FILES_DIRECTORY . $fileName;
if (!$this->fileDirectory->isFile($filePath)) {
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$this->messageManager->addError(__('There is no sample file for this entity.'));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/import');
return $resultRedirect;
}
$fileSize = isset($this->fileDirectory->stat($filePath)['size']) ? $this->fileDirectory->stat($filePath)['size'] : null;
$this->fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $fileSize);
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
$resultRaw->setContents($this->fileDirectory->readFile($filePath));
return $resultRaw;
}
示例6: _initFilesystem
/**
* Directory structure initializing
*
* @return void
*/
protected function _initFilesystem()
{
$this->_mediaDirectory->create($this->_path);
$this->_mediaDirectory->create($this->_quotePath);
$this->_mediaDirectory->create($this->_orderPath);
// Directory listing and hotlink secure
$path = $this->_path . '/.htaccess';
if (!$this->_mediaDirectory->isFile($path)) {
$this->_mediaDirectory->writeFile($path, "Order deny,allow\nDeny from all");
}
}
示例7: _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;
}
}
示例8: addImage
/**
* Add image to media gallery and return new filename
*
* @param \Magento\Catalog\Model\Product $product
* @param string $file file path of image in file system
* @param string|string[] $mediaAttribute code of attribute with type 'media_image',
* leave blank if image should be only in gallery
* @param boolean $move if true, it will move source file
* @param boolean $exclude mark image as disabled in product page view
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function addImage(\Magento\Catalog\Model\Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true)
{
$file = $this->mediaDirectory->getRelativePath($file);
if (!$this->mediaDirectory->isFile($file)) {
throw new LocalizedException(__('The image does not exist.'));
}
$pathinfo = pathinfo($file);
$imgExtensions = ['jpg', 'jpeg', 'gif', 'png'];
if (!isset($pathinfo['extension']) || !in_array(strtolower($pathinfo['extension']), $imgExtensions)) {
throw new LocalizedException(__('Please correct the image file type.'));
}
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($pathinfo['basename']);
$dispretionPath = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
$fileName = $dispretionPath . '/' . $fileName;
$fileName = $this->getNotDuplicatedFilename($fileName, $dispretionPath);
$destinationFile = $this->mediaConfig->getTmpMediaPath($fileName);
try {
/** @var $storageHelper \Magento\MediaStorage\Helper\File\Storage\Database */
$storageHelper = $this->fileStorageDb;
if ($move) {
$this->mediaDirectory->renameFile($file, $destinationFile);
//If this is used, filesystem should be configured properly
$storageHelper->saveFile($this->mediaConfig->getTmpMediaShortUrl($fileName));
} else {
$this->mediaDirectory->copyFile($file, $destinationFile);
$storageHelper->saveFile($this->mediaConfig->getTmpMediaShortUrl($fileName));
$this->mediaDirectory->changePermissions($destinationFile, DriverInterface::WRITEABLE_FILE_MODE);
}
} catch (\Exception $e) {
throw new LocalizedException(__('We couldn\'t move this file: %1.', $e->getMessage()));
}
$fileName = str_replace('\\', '/', $fileName);
$attrCode = $this->getAttribute()->getAttributeCode();
$mediaGalleryData = $product->getData($attrCode);
$position = 0;
if (!is_array($mediaGalleryData)) {
$mediaGalleryData = ['images' => []];
}
foreach ($mediaGalleryData['images'] as &$image) {
if (isset($image['position']) && $image['position'] > $position) {
$position = $image['position'];
}
}
$position++;
$mediaGalleryData['images'][] = ['file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude];
$product->setData($attrCode, $mediaGalleryData);
if ($mediaAttribute !== null) {
$this->setMediaAttribute($product, $mediaAttribute, $fileName);
}
return $fileName;
}
示例9: 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;
}
示例10: _copyImage
/**
* Copy image and return new filename.
*
* @param string $file
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _copyImage($file)
{
try {
$destinationFile = $this->_getUniqueFileName($file);
if (!$this->_mediaDirectory->isFile($this->_mediaConfig->getMediaPath($file))) {
throw new \Exception();
}
if ($this->_fileStorageDb->checkDbUsage()) {
$this->_fileStorageDb->copyFile($this->_mediaDirectory->getAbsolutePath($this->_mediaConfig->getMediaShortUrl($file)), $this->_mediaConfig->getMediaShortUrl($destinationFile));
$this->_mediaDirectory->delete($this->_mediaConfig->getMediaPath($destinationFile));
} else {
$this->_mediaDirectory->copyFile($this->_mediaConfig->getMediaPath($file), $this->_mediaConfig->getMediaPath($destinationFile));
}
return str_replace('\\', '/', $destinationFile);
} catch (\Exception $e) {
$file = $this->_mediaConfig->getMediaPath($file);
throw new LocalizedException(__('We couldn\'t copy file %1. Please delete media with non-existing images and try again.', $file));
}
}
示例11: open
/**
* Open backup file (write or read mode)
*
* @param bool $write
* @return $this
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Backup\Exception\NotEnoughPermissions
*/
public function open($write = false)
{
if ($this->getPath() === null) {
throw new \Magento\Framework\Exception\InputException(__('The backup file path was not specified.'));
}
if ($write && $this->varDirectory->isFile($this->_getFilePath())) {
$this->varDirectory->delete($this->_getFilePath());
}
if (!$write && !$this->varDirectory->isFile($this->_getFilePath())) {
throw new \Magento\Framework\Exception\InputException(__('The backup file "%1" does not exist.', $this->getFileName()));
}
$mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb';
try {
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $varDirectory */
$varDirectory = $this->_filesystem->getDirectoryWrite(DirectoryList::VAR_DIR, DriverPool::ZLIB);
$this->_stream = $varDirectory->openFile($this->_getFilePath(), $mode);
} catch (\Magento\Framework\Exception\FileSystemException $e) {
throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions(__('Sorry, but we cannot read from or write to backup file "%1".', $this->getFileName()));
}
return $this;
}
示例12: insertLogo
/**
* Insert logo to pdf page
*
* @param \Zend_Pdf_Page &$page
* @param null $store
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function insertLogo(&$page, $store = null)
{
$this->y = $this->y ? $this->y : 815;
$image = $this->_scopeConfig->getValue('sales/identity/logo', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
if ($image) {
$imagePath = '/sales/store/logo/' . $image;
if ($this->_mediaDirectory->isFile($imagePath)) {
$image = \Zend_Pdf_Image::imageWithPath($this->_mediaDirectory->getAbsolutePath($imagePath));
$top = 830;
//top border of the page
$widthLimit = 270;
//half of the page width
$heightLimit = 270;
//assuming the image is not a "skyscraper"
$width = $image->getPixelWidth();
$height = $image->getPixelHeight();
//preserving aspect ratio (proportions)
$ratio = $width / $height;
if ($ratio > 1 && $width > $widthLimit) {
$width = $widthLimit;
$height = $width / $ratio;
} elseif ($ratio < 1 && $height > $heightLimit) {
$height = $heightLimit;
$width = $height * $ratio;
} elseif ($ratio == 1 && $height > $heightLimit) {
$height = $heightLimit;
$width = $widthLimit;
}
$y1 = $top - $height;
$y2 = $top;
$x1 = 25;
$x2 = $x1 + $width;
//coordinates after transformation are rounded by Zend
$page->drawImage($image, $x1, $y1, $x2, $y2);
$this->y = $y1 - 10;
}
}
}
示例13: _isCanProcessed
/**
* @param string $relativePath
* @return bool
*/
protected function _isCanProcessed($relativePath)
{
$filePath = $this->_rootDir->getAbsolutePath($relativePath);
return (!$this->_rootDir->isFile($relativePath) || !$this->_rootDir->isReadable($relativePath)) && !$this->_processDatabaseFile($filePath);
}
示例14: importFileExists
/**
* Checks imported file exists.
*
* @param string $filename
* @return bool
*/
public function importFileExists($filename)
{
return $this->varDirectory->isFile($this->getFilePath($filename));
}
示例15: _isCanProcessed
/**
* @param string $relativePath
* @return bool
*/
protected function _isCanProcessed($relativePath)
{
$filePath = $this->_rootDir->getAbsolutePath($relativePath);
return strpos($this->_rootDir->getDriver()->getRealPath($filePath), $relativePath) !== false && $this->_rootDir->isFile($relativePath) && $this->_rootDir->isReadable($relativePath) || $this->_processDatabaseFile($filePath, $relativePath);
}