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


PHP Directory\Write类代码示例

本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\Write的典型用法代码示例。如果您正苦于以下问题:PHP Write类的具体用法?PHP Write怎么用?PHP Write使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Write类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: handleEnable

 /**
  * @param \Magento\Framework\Filesystem\Directory\Write $flagDir
  * @param OutputInterface $output
  * @param null $onOption
  */
 protected function handleEnable(\Magento\Framework\Filesystem\Directory\Write $flagDir, OutputInterface $output, $onOption = null)
 {
     $flagDir->touch(MaintenanceMode::FLAG_FILENAME);
     $output->writeln(self::ENABLED_MESSAGE);
     if (!is_null($onOption)) {
         // Write IPs to exclusion file
         $flagDir->writeFile(MaintenanceMode::IP_FILENAME, $onOption);
         $output->writeln(self::WROTE_IP_MESSAGE);
     }
 }
开发者ID:brentwpeterson,项目名称:n98-magerun2,代码行数:15,代码来源:MaintenanceCommand.php

示例3: __construct

 /**
  * Open file and detect column names
  *
  * There must be column names in the first line
  *
  * @param string $file
  * @param \Magento\Framework\Filesystem\Directory\Write $directory
  * @param string $delimiter
  * @param string $enclosure
  * @throws \LogicException
  */
 public function __construct($file, \Magento\Framework\Filesystem\Directory\Write $directory, $delimiter = ',', $enclosure = '"')
 {
     try {
         $this->_file = $directory->openFile($directory->getRelativePath($file), 'r');
     } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
         throw new \LogicException("Unable to open file: '{$file}'");
     }
     $this->_delimiter = $delimiter;
     $this->_enclosure = $enclosure;
     parent::__construct($this->_getNextRow());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:22,代码来源:Csv.php

示例4: setUp

 /**
  * Set up
  */
 public function setUp()
 {
     $this->context = $this->getMock('Magento\\Framework\\App\\Helper\\Context', [], [], '', false);
     $this->timezone = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\Timezone', ['date', 'getConfigTimezone', 'diff', 'format'], [], '', false);
     $this->varDirectory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', ['getRelativePath', 'readFile', 'isFile', 'stat'], [], '', false);
     $this->filesystem = $this->getMock('Magento\\Framework\\Filesystem', ['getDirectoryWrite'], [], '', false);
     $this->varDirectory->expects($this->any())->method('getRelativePath')->willReturn('path');
     $this->varDirectory->expects($this->any())->method('readFile')->willReturn('contents');
     $this->varDirectory->expects($this->any())->method('isFile')->willReturn(true);
     $this->varDirectory->expects($this->any())->method('stat')->willReturn(100);
     $this->filesystem->expects($this->any())->method('getDirectoryWrite')->willReturn($this->varDirectory);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->report = $this->objectManagerHelper->getObject('Magento\\ImportExport\\Helper\\Report', ['context' => $this->context, 'timeZone' => $this->timezone, 'filesystem' => $this->filesystem]);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:ReportTest.php

示例5: testCreateSymlinkTargetDirectoryExists

 public function testCreateSymlinkTargetDirectoryExists()
 {
     $targetDir = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\WriteInterface')->getMock();
     $targetDir->driver = $this->driver;
     $sourcePath = 'source/path/file';
     $destinationDirectory = 'destination/path';
     $destinationFile = $destinationDirectory . '/' . 'file';
     $this->assertIsFileExpectation($sourcePath);
     $this->driver->expects($this->once())->method('getParentDirectory')->with($destinationFile)->willReturn($destinationDirectory);
     $targetDir->expects($this->once())->method('isExist')->with($destinationDirectory)->willReturn(true);
     $targetDir->expects($this->once())->method('getAbsolutePath')->with($destinationFile)->willReturn($this->getAbsolutePath($destinationFile));
     $this->driver->expects($this->once())->method('symlink')->with($this->getAbsolutePath($sourcePath), $this->getAbsolutePath($destinationFile), $targetDir->driver)->willReturn(true);
     $this->assertTrue($this->write->createSymlink($sourcePath, $destinationFile, $targetDir));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:WriteTest.php

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

示例7: testDeleteDirectory

 /**
  * cover \Magento\Theme\Model\Wysiwyg\Storage::deleteDirectory
  */
 public function testDeleteDirectory()
 {
     $directoryPath = $this->_storageRoot . '/../root';
     $this->_helperStorage->expects($this->atLeastOnce())->method('getStorageRoot')->will($this->returnValue($this->_storageRoot));
     $this->directoryWrite->expects($this->once())->method('delete')->with($directoryPath);
     $this->_storageModel->deleteDirectory($directoryPath);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:StorageTest.php

示例8: 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

示例9: deleteDirectory

 /**
  * Delete directory
  *
  * @param string $path
  * @return bool
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function deleteDirectory($path)
 {
     $rootCmp = rtrim($this->_helper->getStorageRoot(), '/');
     $pathCmp = rtrim($path, '/');
     if ($rootCmp == $pathCmp) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t delete root directory %1 right now.', $path));
     }
     return $this->mediaWriteDirectory->delete($path);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:Storage.php

示例10: afterSave

 /**
  * Check and process robots file
  *
  * @return $this
  */
 public function afterSave()
 {
     if ($this->getValue()) {
         $this->_directory->writeFile($this->_file, $this->getValue());
     }
     return parent::afterSave();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:Robots.php

示例11: execute

 /**
  * @param \Magento\Framework\Event\Observer $observer
  */
 public function execute(Observer $observer)
 {
     $value = $this->_helper->getRobotsConfig('content');
     $this->_directory->writeFile($this->_fileRobot, $value);
     $value = $this->_helper->getHtaccessConfig('content');
     $this->_directory->writeFile($this->_fileHtaccess, $value);
 }
开发者ID:mageplaza,项目名称:magento-2-seo-extension,代码行数:10,代码来源:SeoObserver.php

示例12: testGenerateSwatchVariations

 public function testGenerateSwatchVariations()
 {
     $this->mediaDirectoryMock->expects($this->atLeastOnce())->method('getAbsolutePath')->willReturn('attribute/swatch/e/a/earth.png');
     $image = $this->getMock('\\Magento\\Framework\\Image', ['resize', 'save', 'keepTransparency', 'constrainOnly', 'keepFrame', 'keepAspectRatio', 'backgroundColor', 'quality'], [], '', false);
     $this->imageFactoryMock->expects($this->any())->method('create')->willReturn($image);
     $this->generateImageConfig();
     $image->expects($this->any())->method('resize')->will($this->returnSelf());
     $this->mediaHelperObject->generateSwatchVariations('/e/a/earth.png');
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:9,代码来源:MediaTest.php

示例13: beforeDispatch

 /**
  * Clear temporary directories
  *
  * @param \Magento\Install\Controller\Index\Index $subject
  * @param \Magento\Framework\App\RequestInterface $request
  *
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeDispatch(\Magento\Install\Controller\Index\Index $subject, \Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->appState->isInstalled()) {
         foreach ($this->varDirectory->read() as $dir) {
             if ($this->varDirectory->isDirectory($dir)) {
                 try {
                     $this->varDirectory->delete($dir);
                 } catch (FilesystemException $exception) {
                     $this->logger->log($exception->getMessage());
                 }
             }
         }
     }
 }
开发者ID:aiesh,项目名称:magento2,代码行数:23,代码来源:Dir.php

示例14: replaceTmpEncryptKey

 /**
  * @param string $key
  * @return $this
  */
 public function replaceTmpEncryptKey($key)
 {
     $localXml = $this->_configDirectory->readFile($this->_localConfigFile);
     $localXml = str_replace(self::TMP_ENCRYPT_KEY_VALUE, $key, $localXml);
     $this->_configDirectory->writeFile($this->_localConfigFile, $localXml);
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:Config.php

示例15: testRewind

 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage wrongColumnsNumber
  */
 public function testRewind()
 {
     $this->_directoryMock->expects($this->any())->method('openFile')->will($this->returnValue(new \Magento\Framework\Filesystem\File\Read(__DIR__ . '/_files/test.csv', new \Magento\Framework\Filesystem\Driver\File())));
     $model = new \Magento\ImportExport\Model\Import\Source\Csv(__DIR__ . '/_files/test.csv', $this->_directoryMock);
     $this->assertSame(-1, $model->key());
     $model->next();
     $this->assertSame(0, $model->key());
     $model->next();
     $this->assertSame(1, $model->key());
     $model->rewind();
     $this->assertSame(0, $model->key());
     $model->next();
     $model->next();
     $this->assertSame(2, $model->key());
     $model->current();
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:CsvTest.php


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