Ejemplo n.º 1
0
 public function export(TableView $view, $template = null, array $options = array())
 {
     $out = tempnam('/tmp', 'export-out-');
     $data = $view->getData();
     $file = new \SplFileObject($out, 'w');
     $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
     $row = array();
     foreach ($data['thead'] as $th) {
         $row[] = $th['title'];
     }
     $file->fputcsv($row);
     foreach ($data['tbody'] as $tr) {
         $row = array();
         foreach ($tr['data'] as $td) {
             $row[] = $td['value'];
         }
         $file->fputcsv($row);
     }
     $now = new \DateTime();
     $filename = preg_replace(array('/\\[now\\]/', '/\\[caption\\]/'), array($now->format('Y-m-d H\\hi'), $data['caption']), 'Export');
     return new Export($file->getFileInfo(), $this->getContentType(), $filename, $this->getFileExtension());
 }
<?php

$file = __FILE__;
$s = new SplFileObject($file);
var_dump($fi = $s->getFileInfo(), (string) $fi);
$d = new SplFileInfo(__DIR__);
echo "\n";
var_dump($fi = $d->getFileInfo(), (string) $fi);
$d = new SplFileInfo(__DIR__ . "/");
echo "\n";
var_dump($fi = $d->getFileInfo(), (string) $fi);