本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\WriteInterface类的典型用法代码示例。如果您正苦于以下问题:PHP WriteInterface类的具体用法?PHP WriteInterface怎么用?PHP WriteInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WriteInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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();
}
示例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];
}
示例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);
}
示例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()));
}
示例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);
}
示例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));
}
示例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();
}
示例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));
}
}
}
示例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;
}
示例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);
}
示例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];
}
示例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());
}
示例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;
}
示例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());
}