• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Directory\Write类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

    public function setUpDirectoryWriteInstallation()
    {
        // CONFIG
        $this->directoryWriteMock
            ->expects($this->at(0))
            ->method('isExist')
            ->will($this->returnValue(true));
        $this->directoryWriteMock
            ->expects($this->at(1))
            ->method('isDirectory')
            ->will($this->returnValue(true));
        $this->directoryWriteMock
            ->expects($this->at(2))
            ->method('isReadable')
            ->will($this->returnValue(true));
        $this->directoryWriteMock
            ->expects($this->at(3))
            ->method('isWritable')
            ->will($this->returnValue(true));

        // VAR
        $this->directoryWriteMock
            ->expects($this->at(4))
            ->method('isExist')
            ->will($this->returnValue(false));

        // MEDIA
        $this->directoryWriteMock
            ->expects($this->at(5))
            ->method('isExist')
            ->will($this->returnValue(true));
        $this->directoryWriteMock
            ->expects($this->at(6))
            ->method('isDirectory')
            ->will($this->returnValue(false));

        // STATIC_VIEW
        $this->directoryWriteMock
            ->expects($this->at(7))
            ->method('isExist')
            ->will($this->returnValue(true));
        $this->directoryWriteMock
            ->expects($this->at(8))
            ->method('isDirectory')
            ->will($this->returnValue(true));
        $this->directoryWriteMock
            ->expects($this->at(9))
            ->method('isReadable')
            ->will($this->returnValue(true));
        $this->directoryWriteMock
            ->expects($this->at(10))
            ->method('isWritable')
            ->will($this->returnValue(false));
    }
开发者ID:rafaelstz,项目名称:magento2,代码行数:54,代码来源:FilePermissionsTest.php


示例11: testGetCurrentUrl

 public function testGetCurrentUrl()
 {
     $storeId = 1;
     $baseUrl = 'http://localhost';
     $relativePath = '/../wysiwyg';
     $this->imagesHelper->setStoreId($storeId);
     $this->storeMock->expects($this->once())->method('getBaseUrl')->with(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA)->willReturn($baseUrl);
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
     $this->directoryWriteMock->expects($this->any())->method('getRelativePath')->willReturn($relativePath);
     $this->assertEquals($baseUrl . $relativePath . '/', $this->imagesHelper->getCurrentUrl());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:11,代码来源:ImagesTest.php


示例12: setUp

 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->_filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
     $this->_driverMock = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\DriverInterface', [], '', false, false, true, ['getRealPath']);
     $this->_driverMock->expects($this->any())->method('getRealPath')->will($this->returnArgument(0));
     $this->_directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', ['delete', 'getDriver'], [], '', false);
     $this->_directoryMock->expects($this->any())->method('getDriver')->will($this->returnValue($this->_driverMock));
     $this->_filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', ['getDirectoryWrite'], [], '', false);
     $this->_filesystemMock->expects($this->any())->method('getDirectoryWrite')->with(DirectoryList::MEDIA)->will($this->returnValue($this->_directoryMock));
     $this->_adapterFactoryMock = $this->getMock('Magento\\Framework\\Image\\AdapterFactory', [], [], '', false);
     $this->_imageHelperMock = $this->getMock('Magento\\Cms\\Helper\\Wysiwyg\\Images', ['getStorageRoot'], [], '', false);
     $this->_imageHelperMock->expects($this->any())->method('getStorageRoot')->will($this->returnValue(self::STORAGE_ROOT_DIR));
     $this->_resizeParameters = ['width' => 100, 'height' => 50];
     $this->_storageCollectionFactoryMock = $this->getMock('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage\\CollectionFactory', [], [], '', false);
     $this->_storageFileFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\FileFactory', [], [], '', false);
     $this->_storageDatabaseFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\DatabaseFactory', [], [], '', false);
     $this->_directoryDatabaseFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\Directory\\DatabaseFactory', [], [], '', false);
     $this->_uploaderFactoryMock = $this->getMockBuilder('Magento\\MediaStorage\\Model\\File\\UploaderFactory')->disableOriginalConstructor()->getMock();
     $this->_sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', [], [], '', false);
     $this->_backendUrlMock = $this->getMock('Magento\\Backend\\Model\\Url', [], [], '', false);
     $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->_model = $objectManagerHelper->getObject('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage', ['session' => $this->_sessionMock, 'backendUrl' => $this->_backendUrlMock, 'cmsWysiwygImages' => $this->_imageHelperMock, 'coreFileStorageDb' => $this->getMock('Magento\\MediaStorage\\Helper\\File\\Storage\\Database', [], [], '', false), 'filesystem' => $this->_filesystemMock, 'imageFactory' => $this->_adapterFactoryMock, 'assetRepo' => $this->getMock('Magento\\Framework\\View\\Asset\\Repository', [], [], '', false), 'storageCollectionFactory' => $this->_storageCollectionFactoryMock, 'storageFileFactory' => $this->_storageFileFactoryMock, 'storageDatabaseFactory' => $this->_storageDatabaseFactoryMock, 'directoryDatabaseFactory' => $this->_directoryDatabaseFactoryMock, 'uploaderFactory' => $this->_uploaderFactoryMock, 'resizeParameters' => $this->_resizeParameters]);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:27,代码来源:StorageTest.php


示例13: testGetThumbnailPathNotFound

 /**
  * @test
  * @return void
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The image not found
  */
 public function testGetThumbnailPathNotFound()
 {
     $image = 'notFoundImage.png';
     $root = '/image';
     $sourceNode = '/not/a/root';
     $node = base64_encode($sourceNode);
     $this->request->expects($this->at(0))->method('getParam')->willReturnMap([[\Magento\Theme\Helper\Storage::PARAM_THEME_ID, null, 6], [\Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE, null, \Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE], [\Magento\Theme\Helper\Storage::PARAM_NODE, null, $node]]);
     $this->urlDecoder->expects($this->once())->method('decode')->with($node)->willReturnCallback(function ($path) {
         return base64_decode($path);
     });
     $this->directoryWrite->expects($this->once())->method('isDirectory')->with($root . $sourceNode)->willReturn(true);
     $this->directoryWrite->expects($this->once())->method('getRelativePath')->with($root . $sourceNode)->willReturn($sourceNode);
     $this->directoryWrite->expects($this->once())->method('isExist')->with($sourceNode . '/' . $image);
     $this->helper->getThumbnailPath($image);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:21,代码来源:StorageTest.php


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


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


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


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


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


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


示例20: _afterSave

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Directory\WriteInterface类代码示例发布时间:2022-05-23
下一篇:
PHP Directory\ReadInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap