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


PHP Reader::createFromFileObject方法代码示例

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


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

示例1: render

 protected function render()
 {
     $fileObject = new \SplFileObject($this->getPath());
     $reader = Reader::createFromFileObject($fileObject);
     $reader->setFlags(\SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
     return $reader;
 }
开发者ID:GreenHackers,项目名称:geo-endpoint,代码行数:7,代码来源:AbstractReader.php

示例2: postCsv

 /**
  * @param \Seat\Web\Http\Validation\CsvImport $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postCsv(CsvImport $request)
 {
     $csv = Reader::createFromFileObject($request->file('csv')->openFile());
     // Keep tabs on the amount of keys that have
     // been inserted, and how many have been
     // considered erroneous
     $updated = 0;
     $errored = 0;
     // Loop the CSV, validating the lines
     // and inserting into the database
     foreach ($csv as $k => $data) {
         // Assign the $data to readable names
         $key_id = $data[0];
         $v_code = $data[1];
         // Validate the keys. We check that we dont
         // already have this key in the database to ensure
         // that we dont mess up the ownership by accident.
         $validator = Validator::make(['key_id' => $key_id, 'v_code' => $v_code], ['key_id' => 'required|numeric|unique:eve_api_keys,key_id', 'v_code' => 'required|size:64|alpha_num']);
         // Ensure the format was ok
         if ($validator->fails()) {
             $errored++;
             continue;
         }
         // Add the API Key
         ApiKey::create(['key_id' => $key_id, 'v_code' => $v_code, 'user_id' => auth()->user()->id, 'enabled' => true]);
         $updated++;
     }
     return redirect()->back()->with('success', 'Import complete! Success: ' . $updated . '. Error: ' . $errored);
 }
开发者ID:eveseat,项目名称:web,代码行数:34,代码来源:ImportController.php

示例3: setUp

 public function setUp()
 {
     $csv = new SplTempFileObject();
     foreach ($this->expected as $row) {
         $csv->fputcsv($row);
     }
     $this->csv = Reader::createFromFileObject($csv);
 }
开发者ID:arvenil,项目名称:csv,代码行数:8,代码来源:CsvTest.php

示例4: process

 public function process($filename)
 {
     // @todo inject factory function to get Reader
     $reader = Reader::createFromFileObject(new SplFileObject($filename));
     // Filter out empty rows
     $nbColumns = count($reader->fetchOne());
     $reader->addFilter(function ($row) use($nbColumns) {
         return count($row) == $nbColumns;
     });
     if ($this->offset) {
         $reader->setOffset($this->offset);
     }
     if ($this->limit) {
         $reader->setLimit($this->limit);
     }
     return new ArrayIterator($reader->fetchAssoc());
 }
开发者ID:gjorgiev,项目名称:platform,代码行数:17,代码来源:CSV.php

示例5: testFetchColEmptyCol

 public function testFetchColEmptyCol()
 {
     $raw = [['john', 'doe'], ['lara', 'croft', 'lara.croft@example.com']];
     $file = new SplTempFileObject();
     foreach ($raw as $row) {
         $file->fputcsv($row);
     }
     $csv = Reader::createFromFileObject($file);
     $res = $csv->fetchColumn(2);
     $this->assertInternalType('array', $res);
     $this->assertCount(2, $res);
     $this->assertNull($res[0][2]);
 }
开发者ID:arvenil,项目名称:csv,代码行数:13,代码来源:ReaderTest.php

示例6: createReader

 /**
  * Create CSV reader instance
  *
  * @param SplFileObject $file
  *
  * @return static
  */
 protected static function createReader(SplFileObject $file)
 {
     return Reader::createFromFileObject($file);
 }
开发者ID:RootStudio,项目名称:Perch-Locator,代码行数:11,代码来源:RootLocator_ImporterFactory.class.php

示例7: SplFileObject

    /*
     * la checkbox se è falsa non viene inviata
     *
     * ci sono soluzioni migliori?
     */
    if (!$request->request->has('finale')) {
        $finale = 0;
    } else {
        $finale = 1;
    }
    /*
     * inserisco una nuova riga csv
     */
    $writer->insertOne([$request->request->get('giorno'), $request->request->get('gara'), $finale]);
}
/*
 * il ritorno sono tutte le righe del csv ordinate per giorno
 *
 * Vedere esercizio 03
 */
$reader = Reader::createFromFileObject(new SplFileObject('file.csv'));
$results = iterator_to_array($reader->fetchAssoc(0), false);
use Symfony\Component\HttpFoundation\JsonResponse as Response;
use Illuminate\Support\Collection;
$collezione = new Collection($results);
$collezione->sortBy(function ($item, $key) {
    $data = \Carbon\Carbon::createFromFormat('d/m/y', $item['giorno']);
    return $data->timestamp;
});
$response = new Response($collezione);
$response->send();
开发者ID:gab88slash,项目名称:php-laravel-lectures,代码行数:31,代码来源:index.php


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