本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\Write::isExist方法的典型用法代码示例。如果您正苦于以下问题:PHP Write::isExist方法的具体用法?PHP Write::isExist怎么用?PHP Write::isExist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\Write
的用法示例。
在下文中一共展示了Write::isExist方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: getThumbnailPath
/**
* Get thumbnail path in current directory by image name
*
* @param string $imageName
* @return string
* @throws \InvalidArgumentException
*/
public function getThumbnailPath($imageName)
{
$imagePath = $this->getCurrentPath() . '/' . $imageName;
if (!$this->mediaDirectoryWrite->isExist($imagePath) || 0 !== strpos($imagePath, $this->getStorageRoot())) {
throw new \InvalidArgumentException('The image not found.');
}
return $this->getThumbnailDirectory($imagePath) . '/' . pathinfo($imageName, PATHINFO_BASENAME);
}
示例4: _deleteFilesRecursively
/**
* Delete all files in a directory recursively
*
* @param string $targetDir
* @return void
*/
protected function _deleteFilesRecursively($targetDir)
{
if ($this->_directory->isExist($targetDir)) {
foreach ($this->_directory->read($targetDir) as $path) {
$this->_directory->delete($path);
}
}
}
示例5: loadPackagesForUpdateFromCache
/**
* Load composer packages available for update from cache
*
* @return bool|string
*/
private function loadPackagesForUpdateFromCache()
{
if ($this->directory->isExist($this->pathToCacheFile) && $this->directory->isReadable($this->pathToCacheFile)) {
try {
$data = $this->directory->readFile($this->pathToCacheFile);
return json_decode($data, true);
} catch (\Magento\Framework\Exception\FileSystemException $e) {
}
}
return false;
}
示例6: getDirsCollection
/**
* Get directory collection
*
* @param string $currentPath
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getDirsCollection($currentPath)
{
if (!$this->mediaWriteDirectory->isExist($currentPath)) {
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot find a directory with this name.'));
}
$paths = $this->mediaWriteDirectory->search('.*', $currentPath);
$directories = [];
foreach ($paths as $path) {
if ($this->mediaWriteDirectory->isDirectory($path)) {
$directories[] = $path;
}
}
return $directories;
}
示例7: _addSitemapToRobotsTxt
/**
* Add sitemap file to robots.txt
*
* @param string $sitemapFileName
* @return void
*/
protected function _addSitemapToRobotsTxt($sitemapFileName)
{
$robotsSitemapLine = 'Sitemap: ' . $this->getSitemapUrl($this->getSitemapPath(), $sitemapFileName);
$filename = 'robots.txt';
$content = '';
if ($this->_directory->isExist($filename)) {
$content = $this->_directory->readFile($filename);
}
if (strpos($content, $robotsSitemapLine) === false) {
if (!empty($content)) {
$content .= $this->_findNewLinesDelimiter($content);
}
$content .= $robotsSitemapLine;
}
$this->_directory->writeFile($filename, $content);
}
示例8: compactValue
/**
* Export attribute value to entity model
*
* @param array|string $value
* @return $this
*/
public function compactValue($value)
{
if ($this->getIsAjaxRequest()) {
return $this;
}
$attribute = $this->getAttribute();
$original = $this->getEntity()->getData($attribute->getAttributeCode());
$toDelete = false;
if ($original) {
if (!$attribute->getIsRequired() && !empty($value['delete'])) {
$toDelete = true;
}
if (!empty($value['tmp_name'])) {
$toDelete = true;
}
}
$destinationFolder = $attribute->getEntity()->getEntityTypeCode();
// unlink entity file
if ($toDelete) {
$this->getEntity()->setData($attribute->getAttributeCode(), '');
$file = $destinationFolder . $original;
if ($this->_directory->isExist($file)) {
$this->_directory->delete($file);
}
}
if (!empty($value['tmp_name'])) {
try {
$uploader = new \Magento\Framework\File\Uploader($value);
$uploader->setFilesDispersion(true);
$uploader->setFilenamesCaseSensitivity(false);
$uploader->setAllowRenameFiles(true);
$uploader->save($this->_directory->getAbsolutePath($destinationFolder), $value['name']);
$fileName = $uploader->getUploadedFileName();
$this->getEntity()->setData($attribute->getAttributeCode(), $fileName);
} catch (\Exception $e) {
$this->_logger->logException($e);
}
}
return $this;
}
示例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: _isUpdateNeeded
/**
* Check whether minified file should be created
*
* @param string $minifiedFile path relative to pub/view_cache
* @return bool
*/
protected function _isUpdateNeeded($minifiedFile)
{
return !$this->pubViewCacheDir->isExist($minifiedFile);
}