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


PHP Writer::createFromFileObject方法代码示例

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


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

示例1: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  * @throws RedirectException
  */
 public function handle($request, Closure $next)
 {
     $response = $next($request);
     $source = $request->get('source', 'api_data');
     $filename = $request->get('filename', 'export_' . date('Y-m-d_Hi'));
     if ($request->get('download') && array_key_exists($source, $response->original->getData())) {
         switch ($request->get('download')) {
             case 'json':
                 return response()->json($response->original->getData()[$source], 200, ['Content-Disposition' => 'attachment; filename="' . $filename . '.json"']);
             case 'csv':
                 $writer = Writer::createFromFileObject(new \SplTempFileObject());
                 $writer->setDelimiter(',');
                 $writer->setNewline("\r\n");
                 $writer->setEncodingFrom("utf-8");
                 $headers = ['Content-Type' => 'text/csv', 'Content-Disposition' => 'attachment; filename="' . $filename . '.csv"'];
                 $csv_headers_set = false;
                 foreach ($response->original->getData()[$source] as $data) {
                     if (!$csv_headers_set) {
                         $writer->insertOne(array_keys($this->getArrayRepresentation($data)));
                         $csv_headers_set = true;
                     }
                     $writer->insertOne($this->processData($this->getArrayRepresentation($data)));
                 }
                 return response()->make($writer, 200, $headers);
             default:
                 throw RedirectException::make('/')->setError('Unrecognised type to download');
         }
     }
     return $response;
 }
开发者ID:paybreak,项目名称:basket,代码行数:38,代码来源:Download.php

示例2: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->writeSection($output, 'Po to Csv converter');
     $this->cwd = getcwd() . DIRECTORY_SEPARATOR;
     $output->writeln('<info>Using CWD</info> ' . $this->cwd);
     $poFiles = $this->getInputPoFiles($input, $output);
     $outputFolder = $this->getOutputFolder($input, $output);
     $useDefaults = $input->getOption('use-defaults');
     if ($useDefaults) {
         $output->writeln('<info>Po files</info>:');
         $this->writeList($output, $poFiles);
         $output->writeln(['', '<info>Output folder</info>: ' . $outputFolder]);
     }
     $poHandles = [];
     foreach ($poFiles as $poFile) {
         $key = basename($poFile, '.po');
         $output->writeln('<info>loading ' . $key . '</info>...');
         $poHandles[$key] = Translations::fromPoFile($poFile);
     }
     $output->writeln('<info>merging po files</info>...');
     $csvArray = [];
     foreach ($poHandles as $language => $poHandle) {
         foreach ($poHandle as $translation) {
             $original = trim($translation->original);
             $translation = trim($translation->translation);
             if (!isset($csvArray[$original])) {
                 $csvArray[$original] = [$language => $translation];
             } elseif (!isset($csvArray[$original][$language])) {
                 $csvArray[$original][$language] = $translation;
             } elseif ($csvArray[$original][$language] != $translation) {
                 $csvArray[$original][$language] = $this->handleConflict($input, $output, $original, $csvArray[$original][$language], $translation);
             }
         }
     }
     $output->writeln('<info>writing csv</info>...');
     $writer = Writer::createFromFileObject(new SplTempFileObject());
     $writer->setDelimiter(';');
     $header = ['original'];
     $header = array_merge($header, array_keys($poHandles));
     $writer->insertOne($header);
     foreach ($csvArray as $original => $item) {
         $row = [];
         foreach ($header as $column) {
             if ($column === 'original') {
                 $row[] = $original;
             } else {
                 $row[] = isset($item[$column]) ? $item[$column] : null;
             }
         }
         $writer->insertOne($row);
     }
     $outputFile = $outputFolder . DIRECTORY_SEPARATOR . 'translations.csv';
     file_put_contents($outputFile, $writer->__toString());
     $output->writeln('<info>done. output file is</info> ' . $outputFile);
 }
开发者ID:roopet,项目名称:potato,代码行数:55,代码来源:PoToCsvCommand.php

示例3: handle

 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(MergeManager $mergeManager, FileManager $fileManager)
 {
     $columns = ['PID', 'entity type', 'title', 'document type', 'URL', 'enabled', 'notes', 'format', 'reference', 'order'];
     $items = $mergeManager->fetchAll();
     $writer = Writer::createFromFileObject(new SplTempFileObject());
     $writer->insertOne($columns);
     $count = 0;
     foreach ($items as $item) {
         $row = [$item->object_number, $item->entity_type, $item->object->title, $item->url, $item->enabled, $item->format, $item->representation_order, $item->reference];
         $writer->insertOne($row);
         $count++;
     }
     $output = (string) $writer;
     $timestamp = Carbon::now();
     $fileName = sprintf("import_%s.csv", $timestamp->format('dmY_His'));
     $fileManager->saveFile($fileName, $output);
     $merger = new Merger();
     $merger->filename = $fileName;
     $merger->documents = $count;
     $merger->save();
     $context = new \ZMQContext();
     $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher');
     $socket->connect("tcp://localhost:5555");
     $socket->send('test');
 }
开发者ID:netsensei,项目名称:resin,代码行数:30,代码来源:Merge.php

示例4: table

 /**
  * Overload render for array data output
  *
  * @param \FrenchFrogs\Table\Table\Table $table
  * @return array
  */
 public function table(Table\Table $table)
 {
     // INitilisation du CSV
     $csv = Writer::createFromFileObject(new \SplTempFileObject());
     // gestion des colonne
     $header = $columns = [];
     foreach ($table->getColumns() as $index => $column) {
         // Seule les colonnes Exportable peuvent être exporté
         if ($column instanceof Exportable) {
             $columns[$index] = $column;
             $header[$index] = $column->getLabel();
         }
     }
     // insertion du header
     $csv->insertOne(array_values($header));
     //@todo mettre en place un streaming pour économiser la memoire
     // insertion des lignes
     foreach ($table->getRows() as $row) {
         $line = [];
         foreach (array_keys($header) as $index) {
             $line[] = $columns[$index]->getValue($row);
         }
         $csv->insertOne($line);
     }
     $csv->output($table->getFilename());
     exit;
 }
开发者ID:frenchfrogs,项目名称:framework,代码行数:33,代码来源:Csv.php

示例5: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $experiments = Experiment::active()->get();
     $goals = array_unique(Goal::active()->orderBy('name')->lists('name'));
     $columns = array_merge(['Experiment', 'Visitors', 'Engagement'], array_map('ucfirst', $goals));
     $writer = Writer::createFromFileObject(new SplTempFileObject());
     $writer->insertOne($columns);
     foreach ($experiments as $experiment) {
         $engagement = $experiment->visitors ? $experiment->engagement / $experiment->visitors * 100 : 0;
         $row = [$experiment->name, $experiment->visitors, number_format($engagement, 2) . " % (" . $experiment->engagement . ")"];
         $results = $experiment->goals()->lists('count', 'name');
         foreach ($goals as $column) {
             $count = array_get($results, $column, 0);
             $percentage = $experiment->visitors ? $count / $experiment->visitors * 100 : 0;
             $row[] = number_format($percentage, 2) . " % ({$count})";
         }
         $writer->insertOne($row);
     }
     $output = (string) $writer;
     if ($file = $this->argument('file')) {
         $this->info("Creating {$file}");
         File::put($file, $output);
     } else {
         $this->line($output);
     }
 }
开发者ID:nosun,项目名称:laravel-ab,代码行数:31,代码来源:ExportCommand.php

示例6: exportSelected

 public function exportSelected()
 {
     $selected_students = Input::get('studentId');
     if (is_array($selected_students)) {
         //Setup CSV
         $csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
         $column_flag = false;
         $student = [];
         foreach ($selected_students as $student_id) {
             $student_data = Students::with('course')->find($student_id);
             //Personal data
             $student['firstname'] = $student_data['firstname'];
             $student['surname'] = $student_data['surname'];
             $student['email'] = $student_data['email'];
             //Course data
             $student['university'] = $student_data->course['university'];
             $student['course_name'] = $student_data->course['course_name'];
             //Check whether column headers have been set (not ideal for large datasets)
             if ($column_flag === false) {
                 $csv->insertOne(\Schema::getColumnListing('student'));
                 $column_flag = true;
             }
             //Add student record to file
             $csv->insertOne($student);
         }
     } else {
         return "NO STUDENTS SELECTED";
     }
     //is_array($selected_students)
     $csv->output("selected_student_records.csv");
 }
开发者ID:ZeroGodForce,项目名称:RMP_Challenge_Me,代码行数:31,代码来源:ExportController.php

示例7: run

 public function run()
 {
     $commandResult = $this->runCommandPrompt();
     $salaryCalendar = SalaryCalendar::get($commandResult['startDate'], $commandResult['endDate'], $commandResult['year']);
     $csvWriter = Writer::createFromFileObject(new \SplTempFileObject());
     $writer = new CsvFileWriter($csvWriter, $salaryCalendar->calculatePayDays());
     $writer->write($commandResult['path'] . DIRECTORY_SEPARATOR . $commandResult['name']);
 }
开发者ID:Oxyaction,项目名称:salary-calendar,代码行数:8,代码来源:Application.php

示例8: export

 public function export()
 {
     $data = $this->formatData();
     $keys = array_keys($data[0]);
     $csv = Writer::createFromFileObject(new SplTempFileObject());
     $csv->insertOne($keys);
     $csv->insertAll($data);
     $csv->output($this->getFileName());
 }
开发者ID:arytest,项目名称:Translation,代码行数:9,代码来源:TranslationsExporter.php

示例9: export

 public function export()
 {
     $data = $this->formatData();
     $keys = array_keys($data[0]);
     $csv = Writer::createFromFileObject(new SplTempFileObject());
     $csv->insertOne($keys);
     $csv->insertAll($data);
     return (string) $csv;
 }
开发者ID:mikemand,项目名称:Translation,代码行数:9,代码来源:TranslationsExporter.php

示例10: exportToFile

 /**
  * Exports $result to $file.
  */
 public function exportToFile(array $result, $file)
 {
     $writer = Writer::createFromFileObject(new SplTempFileObject());
     foreach ($result['result'] as $row) {
         unset($row['_id']);
         $writer->insertOne($row);
     }
     file_put_contents($file, $writer->__toString());
 }
开发者ID:RonRademaker,项目名称:MongoAggregations,代码行数:12,代码来源:CSVExport.php

示例11: export

 public static function export($table, $dbConnection = 'default')
 {
     $data = DB::connection($dbConnection)->table($table)->get();
     $csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
     $csv->insertOne(\Schema::getColumnListing($table));
     foreach ($data as $row) {
         $csv->insertOne((array) $row);
     }
     $csv->output($table . '-' . date('YmdHi') . '.csv');
 }
开发者ID:shaikhAli,项目名称:genericcrud,代码行数:10,代码来源:Exporter.php

示例12: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $size = (int) $this->argument('size');
     $documents = factory('App\\Models\\Document', $size)->make()->toArray();
     $headers = array_keys($documents[0]);
     $csv = Writer::createFromFileObject(new SplTempFileObject());
     $csv->insertOne($headers);
     $csv->insertAll($documents);
     Storage::put('testdata/test-' . $size . '.csv', $csv);
 }
开发者ID:petercoles,项目名称:Cluster-Manager-Example-Laravel,代码行数:15,代码来源:TestData.php

示例13: encode

 public function encode(array $content)
 {
     $writer = Writer::createFromFileObject(new \SplTempFileObject());
     $writer->setDelimiter($this->delimiter);
     $writer->setNewline($this->newline);
     $writer->setEnclosure($this->enclosure);
     $writer->setEscape($this->escapeChar);
     $writer->insertAll($content);
     return (string) $writer;
 }
开发者ID:allmarkedup,项目名称:dayglo,代码行数:10,代码来源:CsvParser.php

示例14: create

 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     $people = bbStock::all();
     $csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
     $csv->insertOne(\Schema::getColumnListing('bbstock'));
     foreach ($people as $person) {
         $csv->insertOne($person->toArray());
     }
     $csv->output('bbstock.csv');
 }
开发者ID:satmari,项目名称:bbstock,代码行数:15,代码来源:exportController.php

示例15: writer

 /**
  * @param \Madewithlove\Export\Csv\Transformer $transformer
  *
  * @return \League\Csv\Writer
  */
 private function writer(Transformer $transformer = null)
 {
     $writer = Writer::createFromFileObject(new SplTempFileObject());
     if ($transformer instanceof WithHeaders) {
         $writer->insertOne($transformer->getHeaders());
     }
     if ($transformer instanceof Transformer) {
         $writer->addFormatter([$transformer, 'transform']);
     }
     return $writer;
 }
开发者ID:madewithlove,项目名称:export,代码行数:16,代码来源:LeagueCsv.php


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