本文整理汇总了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;
}
示例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);
}
示例3: setUp
public function setUp()
{
$csv = new SplTempFileObject();
foreach ($this->expected as $row) {
$csv->fputcsv($row);
}
$this->csv = Reader::createFromFileObject($csv);
}
示例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());
}
示例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]);
}
示例6: createReader
/**
* Create CSV reader instance
*
* @param SplFileObject $file
*
* @return static
*/
protected static function createReader(SplFileObject $file)
{
return Reader::createFromFileObject($file);
}
示例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();