Skip to content

Commit

Permalink
Merge pull request #5 from fr3nch13/dev
Browse files Browse the repository at this point in the history
Ok, I think I got the View stuff ironed out.
  • Loading branch information
fr3nch13 committed Sep 7, 2023
2 parents 65d780a + 14485ea commit d450162
Show file tree
Hide file tree
Showing 19 changed files with 330 additions and 163 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --colors -p -s --extensions=php ./src ./templates ./tests",
"cs-checkstyle": "php -d memory_limit=-1 ./vendor/bin/phpcs --report=checkstyle --extensions=php ./src ./templates ./tests",
"cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --colors --extensions=php ./src ./templates ./tests",
"phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan --no-progress -vvv --xdebug",
"phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan --no-progress -vvv",
"phpstan-github": "php -d memory_limit=-1 ./vendor/bin/phpstan --no-progress -vvv --error-format=github",
"test": "php -d memory_limit=-1 ./vendor/bin/phpunit --colors=always --testdox",
"coverage": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit --log-junit tmp/coverage/unitreport.xml --coverage-html tmp/coverage --testdox",
Expand Down
25 changes: 21 additions & 4 deletions src/View/CsvView.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
*/
class CsvView extends ExcelBaseView
{
/**
* @var string The path to look for the layout.
*/
protected $layoutPath = 'csv';

/**
* @var string The sub directory to look for the template.
*/
protected $subDir = 'csv';

/**
* Mime-type this view class renders as.
*
* @return string The JSON content type.
*/
public static function contentType(): string
{
return 'text/csv';
}

/**
* Initialize method
*
Expand All @@ -21,10 +41,7 @@ public function initialize(): void
{
parent::initialize();

$this->setLayout('Fr3nch13/Excel.csv/default');
$this->setSubDir('csv');

$this->getResponse()->setTypeMap('csv', ['text/csv; charset=UTF-8']);
$this->getResponse()->setTypeMap('csv', [$this->contentType()]);
$this->setResponse($this->getResponse()->withType('csv'));
}
}
15 changes: 12 additions & 3 deletions src/View/ExcelBaseView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@
declare(strict_types=1);

/**
* ExcelView
* ExcelBaseView
*/

namespace Fr3nch13\Excel\View;

/**
* Excel View
* Excel Base View
*
* @property \Fr3nch13\Excel\View\Helper\ExcelHelper $Excel
*/
class ExcelBaseView extends \App\View\AppView
{
/**
* @var string The path to look for the layout.
*/
protected $layoutPath = '';

/**
* @var string The sub directory to look for the template.
*/
protected $subDir = '';

/**
* Initialize method
*
Expand All @@ -25,7 +35,6 @@ public function initialize(): void
$this->loadHelper('Excel', [
'className' => \Fr3nch13\Excel\View\Helper\ExcelHelper::class,
]);
$this->setLayout('Fr3nch13/Excel.default');
}

/**
Expand Down
30 changes: 0 additions & 30 deletions src/View/ExcelView.php

This file was deleted.

24 changes: 22 additions & 2 deletions src/View/PdfView.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
*/
class PdfView extends ExcelBaseView
{
/**
* @var string The path to look for the layout.
*/
protected $layoutPath = 'pdf';

/**
* @var string The sub directory to look for the template.
*/
protected $subDir = 'pdf';

/**
* Mime-type this view class renders as.
*
* @return string The JSON content type.
*/
public static function contentType(): string
{
return 'application/pdf';
}

/**
* Initialize method
*
Expand All @@ -21,10 +41,10 @@ public function initialize(): void
{
parent::initialize();

$this->setLayout('Fr3nch13/Excel.pdf/default');
$this->setLayoutPath('pdf');
$this->setSubDir('pdf');

$this->getResponse()->setTypeMap('pdf', ['application/pdf']);
$this->getResponse()->setTypeMap('pdf', [$this->contentType()]);
$this->setResponse($this->getResponse()->withType('pdf'));
}
}
47 changes: 47 additions & 0 deletions src/View/XlsxView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);

/**
* XlsxView
*/

namespace Fr3nch13\Excel\View;

/**
* Xlsx View
*/
class XlsxView extends ExcelBaseView
{
/**
* @var string The path to look for the layout.
*/
protected $layoutPath = 'xlsx';

/**
* @var string The sub directory to look for the template.
*/
protected $subDir = 'xlsx';

/**
* Mime-type this view class renders as.
*
* @return string The JSON content type.
*/
public static function contentType(): string
{
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
}

/**
* Initialize method
*
* @return void
*/
public function initialize(): void
{
parent::initialize();

$this->getResponse()->setTypeMap('xlsx', [$this->contentType()]);
$this->setResponse($this->getResponse()->withType('xlsx'));
}
}
45 changes: 45 additions & 0 deletions templates/Tests/csv/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/**
* @var \Fr3nch13\Excel\View\CsvView $this
*/

$properties = [];

if (!$this->fetch('page-title')) {
$this->assign('page-title', __('Tests'));
}
if (!$this->fetch('page-subtitle')) {
$this->assign('page-subtitle', __('All'));
}

$properties['title'] = __('{0} - {1}', [
$this->fetch('page-title'),
$this->fetch('page-subtitle'),
]);

$rows = [];
for ($i = 0; $i++; $i < 10) {
$rows[$i] = [
$i,
__('Name {0}', [$i]),
__('Desc {0}', [$i]),
];
}

$headers = [
'id' => __('UID'),
'name' => __('Name'),
'slug' => __('Slug'),
'active' => __('Active'),
'created' => __('Created'),
];

echo $this->element('Fr3nch13/Excel.csv-index', [
'options' => [],
'properties' => $properties,
'headers' => $headers,
'rows' => $rows,
]);
45 changes: 45 additions & 0 deletions templates/Tests/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/**
* @var \Fr3nch13\Excel\View\ExcelBaseView $this
*/

$this->extend('/base');

if (!$this->fetch('page-title')) {
$this->assign('page-title', __('Phpstans'));
}
if (!$this->fetch('page-subtitle')) {
$this->assign('page-subtitle', __('All'));
}

$headers = ['ID', 'Name', 'Desc'];
$rows = [];
for ($i = 0; $i++; $i < 10) {
$rows[$i] = [
$i,
__('Name {0}', [$i]),
__('Desc {0}', [$i]),
];
}

$this->start('page-content');
?>
<section class="page-content">
<div class="box">
<!-- /.box-header -->
<div class="box-body">
<?php
?>
<table>
<?php
echo $this->Html->tableHeaders($headers);
echo $this->Html->tableCells($rows);
?>
</table>
</div>
</div>
</section>
<?php $this->end(); /* page-content */
38 changes: 38 additions & 0 deletions templates/Tests/pdf/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* @var \Fr3nch13\Excel\View\PdfView $this
*/

$properties = [];

if (!$this->fetch('page-title')) {
$this->assign('page-title', __('Tests'));
}
if (!$this->fetch('page-subtitle')) {
$this->assign('page-subtitle', __('All'));
}

$properties['title'] = __('{0} - {1}', [
$this->fetch('page-title'),
$this->fetch('page-subtitle'),
]);

$headers = ['ID', 'Name', 'Desc'];
$rows = [];
for ($i = 0; $i++; $i < 10) {
$rows[$i] = [
$i,
__('Name {0}', [$i]),
__('Desc {0}', [$i]),
];
}

echo $this->element('Fr3nch13/Excel.pdf-index', [
'options' => [],
'properties' => $properties,
'headers' => $headers,
'rows' => $rows,
]);
38 changes: 38 additions & 0 deletions templates/Tests/xlsx/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* @var \Fr3nch13\Excel\View\XlsxView $this
*/

$properties = [];

if (!$this->fetch('page-title')) {
$this->assign('page-title', __('Tests'));
}
if (!$this->fetch('page-subtitle')) {
$this->assign('page-subtitle', __('All'));
}

$properties['title'] = __('{0} - {1}', [
$this->fetch('page-title'),
$this->fetch('page-subtitle'),
]);

$headers = ['ID', 'Name', 'Desc'];
$rows = [];
for ($i = 0; $i++; $i < 10) {
$rows[$i] = [
$i,
__('Name {0}', [$i]),
__('Desc {0}', [$i]),
];
}

echo $this->element('Fr3nch13/Excel.xlsx-index', [
'options' => [],
'properties' => $properties,
'headers' => $headers,
'rows' => $rows,
]);
12 changes: 0 additions & 12 deletions templates/csv/test.php

This file was deleted.

2 changes: 1 addition & 1 deletion templates/element/xlsx-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

/**
* @var \Fr3nch13\Excel\View\ExcelView $this
* @var \Fr3nch13\Excel\View\XlsxView $this
*/

$properties = $properties ?? [];
Expand Down

0 comments on commit d450162

Please sign in to comment.