当前位置: 首页>>代码示例>>PHP>>正文


PHP Write::isExist方法代码示例

本文整理汇总了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;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:37,代码来源:GenerationDirectoryAccess.php

示例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;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:32,代码来源:Storage.php

示例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);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:Storage.php

示例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);
         }
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:14,代码来源:CopyService.php

示例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;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:UpdatePackagesCache.php

示例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;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:Storage.php

示例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);
 }
开发者ID:nja78,项目名称:magento2,代码行数:22,代码来源:Sitemap.php

示例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;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:46,代码来源:File.php

示例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;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:31,代码来源:Images.php

示例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);
 }
开发者ID:Mohitsahu123,项目名称:mtf,代码行数:10,代码来源:Lite.php


注:本文中的Magento\Framework\Filesystem\Directory\Write::isExist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。