PSR12
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
@@ -11,33 +12,38 @@ namespace Domframework;
|
||||
*/
|
||||
class Outputcsv extends Output
|
||||
{
|
||||
/** Don't allow to output in CSV if the functions are not available in PHP */
|
||||
function __construct ()
|
||||
{
|
||||
if (!function_exists ("fputcsv"))
|
||||
throw new \Exception ("CSV support not available in PHP !", 500);
|
||||
}
|
||||
/** Don't allow to output in CSV if the functions are not available in PHP */
|
||||
public function __construct()
|
||||
{
|
||||
if (!function_exists("fputcsv")) {
|
||||
throw new \Exception("CSV support not available in PHP !", 500);
|
||||
}
|
||||
}
|
||||
|
||||
/** Display in CSV the data provided
|
||||
@param mixed $data The data to be displayed */
|
||||
public function out ($data)
|
||||
{
|
||||
if (!is_array ($data))
|
||||
$data = array ($data);
|
||||
@header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
@header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
|
||||
@header('Last-Modified: '.gmdate ('D, d M Y H:i:s').' GMT');
|
||||
@header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
@header('Pragma: no-cache');
|
||||
@header ("Content-Type: text/csv");
|
||||
// TODO : return $csv
|
||||
$out = fopen ('php://output', 'w');
|
||||
if (! is_array ($data[0]))
|
||||
$data = array ($data);
|
||||
foreach ($data as $vals)
|
||||
fputcsv ($out, $vals);
|
||||
fclose ($out);
|
||||
if (!defined ("PHPUNIT"))
|
||||
exit;
|
||||
}
|
||||
/** Display in CSV the data provided
|
||||
@param mixed $data The data to be displayed */
|
||||
public function out($data)
|
||||
{
|
||||
if (!is_array($data)) {
|
||||
$data = array($data);
|
||||
}
|
||||
@header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
@header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
|
||||
@header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
@header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
@header('Pragma: no-cache');
|
||||
@header("Content-Type: text/csv");
|
||||
// TODO : return $csv
|
||||
$out = fopen('php://output', 'w');
|
||||
if (! is_array($data[0])) {
|
||||
$data = array($data);
|
||||
}
|
||||
foreach ($data as $vals) {
|
||||
fputcsv($out, $vals);
|
||||
}
|
||||
fclose($out);
|
||||
if (!defined("PHPUNIT")) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user