當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。