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


PHP WriteInterface::openFile方法代码示例

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


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

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

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

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

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

示例5: getXmlFile

 /**
  * Returns XML file
  *
  * @return array
  * @throws LocalizedException
  */
 public function getXmlFile()
 {
     $component = $this->filter->getComponent();
     $name = md5(microtime());
     $file = 'export/' . $component->getName() . $name . '.xml';
     $this->filter->prepareComponent($component);
     $this->filter->applySelectionOnTargetProvider();
     $component->getContext()->getDataProvider()->setLimit(0, 0);
     /** @var SearchResultInterface $searchResult */
     $searchResult = $component->getContext()->getDataProvider()->getSearchResult();
     /** @var DocumentInterface[] $searchResultItems */
     $searchResultItems = $searchResult->getItems();
     $this->prepareItems($component->getName(), $searchResultItems);
     /** @var SearchResultIterator $searchResultIterator */
     $searchResultIterator = $this->iteratorFactory->create(['items' => $searchResultItems]);
     /** @var Excel $excel */
     $excel = $this->excelFactory->create(['iterator' => $searchResultIterator, 'rowCallback' => [$this, 'getRowData']]);
     $this->directory->create('export');
     $stream = $this->directory->openFile($file, 'w+');
     $stream->lock();
     $excel->setDataHeader($this->metadataProvider->getHeaders($component));
     $excel->write($stream, $component->getName() . '.xml');
     $stream->unlock();
     $stream->close();
     return ['type' => 'filename', 'value' => $file, 'rm' => true];
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:32,代码来源:ConvertToXml.php

示例6: _processDatabaseFile

 /**
  * Check file in database storage if needed and place it on file system
  *
  * @param string $filePath
  * @return bool
  */
 protected function _processDatabaseFile($filePath)
 {
     if (!$this->_fileStorageDatabase->checkDbUsage()) {
         return false;
     }
     $relativePath = $this->_fileStorageDatabase->getMediaRelativePath($filePath);
     $file = $this->_storageDatabaseFactory->create()->loadByFilename($relativePath);
     if (!$file->getId()) {
         return false;
     }
     $stream = $this->_rootDir->openFile($filePath, 'w+');
     $stream->lock();
     $stream->write($filePath, $file->getContent());
     $stream->unlock();
     $stream->close();
     return true;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:23,代码来源:Download.php

示例7: synchronize

 /**
  * Synchronize file
  *
  * @param string $relativeFileName
  * @return void
  * @throws \LogicException
  */
 public function synchronize($relativeFileName)
 {
     /** @var $storage \Magento\MediaStorage\Model\File\Storage\Database */
     $storage = $this->storageFactory->create();
     try {
         $storage->loadByFilename($relativeFileName);
     } catch (\Exception $e) {
     }
     if ($storage->getId()) {
         /** @var Write $file */
         $file = $this->mediaDirectory->openFile($relativeFileName, 'w');
         try {
             $file->lock();
             $file->write($storage->getContent());
             $file->unlock();
             $file->close();
         } catch (FileSystemException $e) {
             $file->close();
         }
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:28,代码来源:Synchronization.php

示例8: 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();
     $searchResult = $component->getContext()->getDataProvider()->getSearchResult();
     $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));
     foreach ($searchResult->getItems() as $document) {
         $stream->writeCsv($this->metadataProvider->getRowData($document, $fields, $options));
     }
     $stream->unlock();
     $stream->close();
     return ['type' => 'filename', 'value' => $file, 'rm' => true];
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:27,代码来源:ConvertToCsv.php

示例9: getExcelFile

 /**
  * Retrieve a file container array by grid data as MS Excel 2003 XML Document
  *
  * Return array with keys type and value
  *
  * @param string $sheetName
  * @return array
  */
 public function getExcelFile($sheetName = '')
 {
     $collection = $this->_getRowCollection();
     $convert = new \Magento\Framework\Convert\Excel($collection->getIterator(), array($this, 'getRowRecord'));
     $name = md5(microtime());
     $file = $this->_path . '/' . $name . '.xml';
     $this->_directory->create($this->_path);
     $stream = $this->_directory->openFile($file, 'w+');
     $stream->lock();
     $convert->setDataHeader($this->_getExportHeaders());
     if ($this->getCountTotals()) {
         $convert->setDataFooter($this->_getExportTotals());
     }
     $convert->write($stream, $sheetName);
     $stream->unlock();
     $stream->close();
     return array('type' => 'filename', 'value' => $file, 'rm' => true);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:26,代码来源:Export.php

示例10: parseCsv

 /**
  * Parse CSV file and collect report rows
  *
  * @param string $localCsv Path to CSV file
  * @param string $format CSV format(column names)
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function parseCsv($localCsv, $format = 'new')
 {
     $this->_rows = [];
     $sectionColumns = $this->_csvColumns[$format]['section_columns'];
     $rowMap = $this->_csvColumns[$format]['rowmap'];
     $flippedSectionColumns = array_flip($sectionColumns);
     $stream = $this->_tmpDirectory->openFile($localCsv);
     while ($line = $stream->readCsv()) {
         if (empty($line)) {
             // The line was empty, so skip it.
             continue;
         }
         $lineType = $line[0];
         switch ($lineType) {
             case 'RH':
                 // Report header.
                 $lastModified = new \DateTime($line[1]);
                 $this->setReportLastModified($lastModified->format('Y-m-d H:i:s'));
                 //$this->setAccountId($columns[2]); -- probably we'll just take that from the section header...
                 break;
             case 'FH':
                 // File header.
                 // Nothing interesting here, move along
                 break;
             case 'SH':
                 // Section header.
                 $this->setAccountId($line[3]);
                 $this->loadByAccountAndDate();
                 break;
             case 'CH':
                 // Section columns.
                 // In case ever the column order is changed, we will have the items recorded properly
                 // anyway. We have named, not numbered columns.
                 for ($i = 1; $i < count($line); $i++) {
                     $sectionColumns[$line[$i]] = $i;
                 }
                 $flippedSectionColumns = array_flip($sectionColumns);
                 break;
             case 'SB':
                 // Section body.
                 $bodyItem = [];
                 for ($i = 1; $i < count($line); $i++) {
                     $bodyItem[$rowMap[$flippedSectionColumns[$i]]] = $line[$i];
                 }
                 $this->_rows[] = $bodyItem;
                 break;
             case 'SC':
                 // Section records count.
             // Section records count.
             case 'RC':
                 // Report records count.
             // Report records count.
             case 'SF':
                 // Section footer.
             // Section footer.
             case 'FF':
                 // File footer.
             // File footer.
             case 'RF':
                 // Report footer.
                 // Nothing to see here, move along
                 break;
             default:
                 break;
         }
     }
     return $this;
 }
开发者ID:nja78,项目名称:magento2,代码行数:76,代码来源:Settlement.php

示例11: _openFile

 /**
  * Open test file
  */
 protected function _openFile()
 {
     $this->_model = $this->_objectManager->create('Magento\\Index\\Model\\Process\\File', array('streamHandler' => $this->_varDirectory->openFile(self::FILE_PATH, 'w+')));
 }
开发者ID:aiesh,项目名称:magento2,代码行数:7,代码来源:FileTest.php


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