當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。