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

PHP Directory\WriteInterface类代码示例

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

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



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

示例1: setUp

 protected function setUp()
 {
     $this->stream = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\File\\WriteInterface');
     $this->dir = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
     $this->dir->expects($this->any())->method('openFile')->with(self::DEBUG_FILE, 'a')->will($this->returnValue($this->stream));
     $filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
     $filesystem->expects($this->any())->method('getDirectoryWrite')->will($this->returnValue($this->dir));
     $this->object = new File($filesystem, self::DEBUG_FILE);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:9,代码来源:FileTest.php


示例2: tearDown

    /**
     * Clear state file
     */
    protected function tearDown()
    {
        $this->filesystem->expects($this->any())->method('getDirectoryWrite')->willReturn($this->writeInterface);
        $this->writeInterface->expects($this->any())->method('openFile')->willReturnSelf($this->absolutePath);

        $this->state->clearState();
    }
开发者ID:rafaelstz,项目名称:magento2,代码行数:10,代码来源:StateTest.php


示例3: getCsvFile

 /**
  * Returns CSV file
  *
  * @return array
  * @throws LocalizedException
  */
 public function getCsvFile()
 {
     $component = $this->filter->getComponent();
     $name = md5(microtime());
     $file = 'export/' . $component->getName() . $name . '.csv';
     $this->filter->prepareComponent($component);
     $this->filter->applySelectionOnTargetProvider();
     $dataProvider = $component->getContext()->getDataProvider();
     $fields = $this->metadataProvider->getFields($component);
     $options = $this->metadataProvider->getOptions();
     $this->directory->create('export');
     $stream = $this->directory->openFile($file, 'w+');
     $stream->lock();
     $stream->writeCsv($this->metadataProvider->getHeaders($component));
     $i = 1;
     $searchCriteria = $dataProvider->getSearchCriteria()->setCurrentPage($i)->setPageSize($this->pageSize);
     $totalCount = (int) $dataProvider->getSearchResult()->getTotalCount();
     while ($totalCount > 0) {
         $items = $dataProvider->getSearchResult()->getItems();
         foreach ($items as $item) {
             $this->metadataProvider->convertDate($item, $component->getName());
             $stream->writeCsv($this->metadataProvider->getRowData($item, $fields, $options));
         }
         $searchCriteria->setCurrentPage(++$i);
         $totalCount = $totalCount - $this->pageSize;
     }
     $stream->unlock();
     $stream->close();
     return ['type' => 'filename', 'value' => $file, 'rm' => true];
 }
开发者ID:uibar,项目名称:lavinia2,代码行数:36,代码来源:ConvertToCsv.php


示例4: createFile

 /**
  * Write down contents to a temporary file and return its absolute path
  *
  * @param string $relativePath
  * @param string $contents
  * @return string
  */
 public function createFile($relativePath, $contents)
 {
     $filePath = $this->config->getLessMaterializationRelativePath() . '/' . $relativePath;
     if (!$this->tmpDirectory->isExist($filePath)) {
         $this->tmpDirectory->writeFile($filePath, $contents);
     }
     return $this->tmpDirectory->getAbsolutePath($filePath);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:Temporary.php


示例5: testPublish

 public function testPublish()
 {
     $this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false));
     $materializationStrategy = $this->getMock('Magento\\Framework\\App\\View\\Asset\\MaterializationStrategy\\StrategyInterface', [], [], '', false);
     $this->rootDirWrite->expects($this->once())->method('getRelativePath')->with('/root/some/file.ext')->will($this->returnValue('some/file.ext'));
     $this->materializationStrategyFactory->expects($this->once())->method('create')->with($this->getAsset())->will($this->returnValue($materializationStrategy));
     $materializationStrategy->expects($this->once())->method('publishFile')->with($this->rootDirWrite, $this->staticDirWrite, 'some/file.ext', 'some/file.ext')->will($this->returnValue(true));
     $this->assertTrue($this->object->publish($this->getAsset()));
 }
开发者ID:IlyaGluschenko,项目名称:protection,代码行数:9,代码来源:PublisherTest.php


示例6: testMergeMtimeUnchanged

 public function testMergeMtimeUnchanged()
 {
     $this->targetDir->expects($this->once())->method('isExist')->with('merged/result.txt.dat')->will($this->returnValue(true));
     $this->targetDir->expects($this->once())->method('readFile')->with('merged/result.txt.dat')->will($this->returnValue('11'));
     $assets = $this->getAssetsToMerge();
     $this->mergerMock->expects($this->never())->method('merge');
     $this->targetDir->expects($this->never())->method('writeFile');
     $this->checksum->merge($assets, $this->resultAsset);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:9,代码来源:ChecksumTest.php


示例7: minify

 /**
  * Minify template file
  *
  * @param string $file
  * @return void
  */
 public function minify($file)
 {
     $file = $this->rootDirectory->getRelativePath($file);
     $content = preg_replace('#(?<!]]>)\\s+</#', '</', preg_replace('#((?:<\\?php\\s+(?!echo|print|if|elseif|else)[^\\?]*)\\?>)\\s+#', '$1 ', preg_replace('#(?<!' . implode('|', $this->inlineHtmlTags) . ')\\> \\<#', '><', preg_replace('#(?ix)(?>[^\\S ]\\s*|\\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:textarea|pre|script)\\b))*+)' . '(?:<(?>textarea|pre|script)\\b|\\z))#', ' ', preg_replace('#(?<!:|\\\\|\'|")//(?!\\s*\\<\\!\\[)(?!\\s*]]\\>)[^\\n\\r]*#', '', preg_replace('#(?<!:)//[^\\n\\r]*(\\s\\?\\>)#', '$1', preg_replace('#//[^\\n\\r]*(\\<\\?php)[^\\n\\r]*(\\s\\?\\>)[^\\n\\r]*#', '', $this->rootDirectory->readFile($file))))))));
     if (!$this->htmlDirectory->isExist()) {
         $this->htmlDirectory->create();
     }
     $this->htmlDirectory->writeFile($file, rtrim($content));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:Minifier.php


示例8: log

 /**
  * {@inheritdoc}
  */
 public function log($str)
 {
     $str = '## ' . date('Y-m-d H:i:s') . "\r\n" . $str;
     $stream = $this->dir->openFile($this->debugFile, 'a');
     $stream->lock();
     $stream->write($str);
     $stream->unlock();
     $stream->close();
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:12,代码来源:File.php


示例9: execute

 /**
  * Flash ISM_BaseRunner cache
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $dir = $this->_mediaDirectory->getAbsolutePath(Upload::UPLOAD_POST_IMAGE_DIR . 'cache/');
     if (is_dir($dir)) {
         $dir = $this->_mediaDirectory->getDriver()->readDirectory($dir);
         foreach ($dir as $file) {
             $this->_mediaDirectory->delete(Upload::UPLOAD_POST_IMAGE_DIR . 'cache/' . basename($file));
         }
     }
 }
开发者ID:swnsma,项目名称:practice,代码行数:16,代码来源:FlushAllCache.php


示例10: _generateRow

 /**
  * Get backup-specific data from model for each row
  *
  * @param string $filename
  * @return array
  */
 protected function _generateRow($filename)
 {
     $row = parent::_generateRow($filename);
     foreach ($this->_backup->load($row['basename'], $this->_varDirectory->getAbsolutePath($this->_path))->getData() as $key => $value) {
         $row[$key] = $value;
     }
     $row['size'] = $this->_varDirectory->stat($this->_varDirectory->getRelativePath($filename))['size'];
     $row['id'] = $row['time'] . '_' . $row['type'];
     return $row;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:Collection.php


示例11: testMergeCss

 public function testMergeCss()
 {
     $this->resultAsset->expects($this->exactly(3))->method('getPath')->will($this->returnValue('foo/result'));
     $this->resultAsset->expects($this->any())->method('getContentType')->will($this->returnValue('css'));
     $assets = $this->prepareAssetsToMerge(['one', 'two']);
     $this->cssUrlResolver->expects($this->exactly(2))->method('relocateRelativeUrls')->will($this->onConsecutiveCalls('1', '2'));
     $this->cssUrlResolver->expects($this->once())->method('aggregateImportDirectives')->with('12')->will($this->returnValue('1020'));
     $this->writeDir->expects($this->once())->method('writeFile')->with('foo/result', '1020');
     $this->object->merge($assets, $this->resultAsset);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:DirectTest.php


示例12: getFile

 /**
  * Get file handler by process ID
  *
  * @param string $processId
  * @return File
  */
 public function getFile($processId)
 {
     if (!isset($this->_fileHandlers[$processId])) {
         $this->_varDirectory->create('locks');
         $fileName = 'locks/index_process_' . $processId . '.lock';
         $stream = $this->_varDirectory->openFile($fileName, 'w+');
         $stream->write(date('r'));
         $this->_fileHandlers[$processId] = $this->_fileFactory->create(array('streamHandler' => $stream));
     }
     return $this->_fileHandlers[$processId];
 }
开发者ID:aiesh,项目名称:magento2,代码行数:17,代码来源:Storage.php


示例13: testCreateRequireJsAssetDevMode

 public function testCreateRequireJsAssetDevMode()
 {
     $this->config->expects($this->once())->method('getConfigFileRelativePath')->will($this->returnValue('requirejs/file.js'));
     $this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dir));
     $this->assetRepo->expects($this->once())->method('createArbitrary')->with('requirejs/file.js', '')->will($this->returnValue($this->asset));
     $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
     $this->dir->expects($this->never())->method('isExist');
     $data = 'requirejs config data';
     $this->config->expects($this->once())->method('getConfig')->will($this->returnValue($data));
     $this->dir->expects($this->once())->method('writeFile')->with('requirejs/file.js', $data);
     $this->assertSame($this->asset, $this->object->createRequireJsConfigAsset());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:FileManagerTest.php


示例14: isProcessLocked

 /**
  * Check whether generation process has already locked
  *
  * @return bool
  * @throws FileSystemException
  */
 private function isProcessLocked()
 {
     if ($this->tmpDirectory->isExist($this->lockFilePath)) {
         $lockTime = (int) $this->tmpDirectory->readFile($this->lockFilePath);
         if (time() - $lockTime >= self::MAX_LOCK_TIME) {
             $this->tmpDirectory->delete($this->lockFilePath);
             return false;
         }
         return true;
     }
     return false;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:LockerProcess.php


示例15: testBeforeSave

 public function testBeforeSave()
 {
     $value = 'filename.jpg';
     $tmpMediaPath = 'tmp/image/' . $value;
     $this->imageBackend->setScope('store');
     $this->imageBackend->setScopeId(1);
     $this->imageBackend->setValue([['url' => 'http://magento2.com/pub/media/tmp/image/' . $value, 'file' => $value, 'size' => 234234]]);
     $this->imageConfig->expects($this->exactly(2))->method('getTmpMediaPath')->with($value)->willReturn($tmpMediaPath);
     $this->mediaDirectory->expects($this->once())->method('copyFile')->with($tmpMediaPath, 'image/store/1/' . $value)->willReturn(true);
     $this->mediaDirectory->expects($this->once())->method('delete')->with($tmpMediaPath);
     $this->imageBackend->beforeSave();
     $this->assertEquals('store/1/filename.jpg', $this->imageBackend->getValue());
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:13,代码来源:ImageTest.php


示例16: save

 /**
  * Save config in cache file
  *
  * @return void
  */
 public function save()
 {
     /** @var Write $file */
     $file = $this->rootDirectory->openFile($this->rootDirectory->getRelativePath($this->cacheFilePath), 'w');
     try {
         $file->lock();
         $file->write(json_encode($this->config));
         $file->unlock();
         $file->close();
     } catch (FileSystemException $e) {
         $file->close();
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:Config.php


示例17: testBeforeSave

 public function testBeforeSave()
 {
     $value = 'filename.jpg';
     $tmpMediaPath = 'tmp/design/file/' . $value;
     $this->fileBackend->setScope('store');
     $this->fileBackend->setScopeId(1);
     $this->fileBackend->setValue([['url' => 'http://magento2.com/pub/media/tmp/image/' . $value, 'file' => $value, 'size' => 234234]]);
     $this->fileBackend->setFieldConfig(['upload_dir' => ['value' => 'value', 'config' => 'system/filesystem/media']]);
     $this->mediaDirectory->expects($this->once())->method('copyFile')->with($tmpMediaPath, '/' . $value)->willReturn(true);
     $this->mediaDirectory->expects($this->once())->method('delete')->with($tmpMediaPath);
     $this->fileBackend->beforeSave();
     $this->assertEquals('filename.jpg', $this->fileBackend->getValue());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:FileTest.php


示例18: _generateRow

 /**
  * Get backup-specific data from model for each row
  *
  * @param string $filename
  * @return array
  */
 protected function _generateRow($filename)
 {
     $row = parent::_generateRow($filename);
     foreach ($this->_backup->load($row['basename'], $this->_varDirectory->getAbsolutePath($this->_path))->getData() as $key => $value) {
         $row[$key] = $value;
     }
     $row['size'] = $this->_varDirectory->stat($this->_varDirectory->getRelativePath($filename))['size'];
     if (isset($row['display_name']) && $row['display_name'] == '') {
         $row['display_name'] = 'WebSetupWizard';
     }
     $row['id'] = $row['time'] . '_' . $row['type'] . (isset($row['display_name']) ? $row['display_name'] : '');
     return $row;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:19,代码来源:Collection.php


示例19: preProcess

    /**
     * Perform necessary preprocessing and materialization when the specified asset is requested
     *
     * Returns an array of two elements:
     * - directory where the file is supposed to be found
     * - relative path to the file
     *
     * returns false if source file was not found
     *
     * @param LocalInterface $asset
     * @return array|bool
     */
    private function preProcess(LocalInterface $asset)
    {
        $sourceFile = $this->findSourceFile($asset);
        $dir = $this->rootDir->getAbsolutePath();
        $path = '';
        if ($sourceFile) {
            $path = basename($sourceFile);
            $dir = dirname($sourceFile);
        }

        $chain = $this->createChain($asset, $dir, $path);
        $this->preProcessorPool->process($chain);
        $chain->assertValid();
        if ($chain->isChanged()) {
            $dir = $this->varDir->getAbsolutePath();
            $path = DirectoryList::TMP_MATERIALIZATION_DIR . '/source/' . $chain->getTargetAssetPath();
            $this->varDir->writeFile($path, $chain->getContent());
        }
        if (empty($path)) {
            $result = false;
        } else {
            $result = [$dir, $path];
        }
        return $result;
    }
开发者ID:rafaelstz,项目名称:magento2,代码行数:37,代码来源:Source.php


示例20: saveFileToTmpDir

 /**
  * Checking file for save and save it to tmp dir
  *
  * @param string $fileId
  *
  * @return string[]
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function saveFileToTmpDir($fileId)
 {
     $baseTmpPath = $this->getBaseTmpPath();
     $uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
     $uploader->setAllowedExtensions($this->getAllowedExtensions());
     $uploader->setAllowRenameFiles(true);
     $result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));
     if (!$result) {
         throw new \Magento\Framework\Exception\LocalizedException(__('File can not be saved to the destination folder.'));
     }
     /**
      * Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
      */
     $result['tmp_name'] = str_replace('\\', '/', $result['tmp_name']);
     $result['path'] = str_replace('\\', '/', $result['path']);
     $result['url'] = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $this->getFilePath($baseTmpPath, $result['file']);
     $result['name'] = $result['file'];
     if (isset($result['file'])) {
         try {
             $relativePath = rtrim($baseTmpPath, '/') . '/' . ltrim($result['file'], '/');
             $this->coreFileStorageDatabase->saveFile($relativePath);
         } catch (\Exception $e) {
             $this->logger->critical($e);
             throw new \Magento\Framework\Exception\LocalizedException(__('Something went wrong while saving the file(s).'));
         }
     }
     return $result;
 }
开发者ID:ant-workaholic,项目名称:Store-locator,代码行数:37,代码来源:ImageUploader.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP Indexer\IndexerRegistry类代码示例发布时间:2022-05-23
下一篇:
PHP Directory\Write类代码示例发布时间: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