Skip to content

Commit

Permalink
Fezendo correções nas assinturas dos métodos para o callback.
Browse files Browse the repository at this point in the history
Corrigindo a visibilidade do método createPdf que deve ser public para ser acessivel via callback do streaming.
  • Loading branch information
Ítalo Lelis de Vietro committed Mar 26, 2014
1 parent de37b08 commit 70fa676
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/Umbrella/SimpleReport/Api/FieldDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FieldDefinition
private $fieldCaption;
private $callback;

function __construct($fieldName, $fieldCaption, $fieldType = FieldType::STRING, $callback = null, $fieldSize = null, $fieldWidth = null)
function __construct($fieldName, $fieldCaption, $fieldType = FieldType::STRING, $fieldSize = null, $fieldWidth = null, $callback = null)
{
$this->fieldName = $fieldName;
$this->fieldType = $fieldType;
Expand Down Expand Up @@ -130,9 +130,10 @@ public function executeCallback($value)
{
$callback = $this->callback;

if (!is_callable($callback)) {
if (!$callback instanceof \Closure) {
throw new \InvalidArgumentException('The callback must be a callable');
}

return $callback($value);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Umbrella/SimpleReport/Api/FieldSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function __construct()
parent::__construct(array());
}

public function addField($fieldName, $fieldCaption, $fieldType, $callback = null, $fieldSize = null, $fieldWidth = null)
public function addField($fieldName, $fieldCaption, $fieldType, $fieldSize = null, $fieldWidth = null, $callback = null)
{
$fieldDefinition = new FieldDefinition($fieldName, $fieldCaption, $fieldType, $callback, $fieldSize, $fieldWidth);
$fieldDefinition = new FieldDefinition($fieldName, $fieldCaption, $fieldType, $fieldSize, $fieldWidth, $callback);
$fieldDefinition->setFieldOrder($this->count());
parent::append($fieldDefinition);
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Umbrella/SimpleReport/BaseRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function getValue(IDatasource $datasource, FieldDefinition $fieldDescr
$fieldTypeInstance = $this->configuration->getFieldTypeInstance($fieldTypeName, $rendererPrefix);
$unformattedFieldValue = $datasource->getFieldValue($fieldDescription);
$formattedFieldValue = $fieldTypeInstance->render($unformattedFieldValue);
if ($fieldDescription->getCallback()) {
if (null !== $fieldDescription->getCallback()) {
$formattedFieldValue = $fieldDescription->executeCallBack($formattedFieldValue);
}
return $formattedFieldValue;
Expand Down
4 changes: 2 additions & 2 deletions src/Umbrella/SimpleReport/Renderer/WkPdfRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ protected function createAndFormatDate($format = 'd/m/Y')
}

/**
* Converte um HTML em PDF
* Converte um HTML em PDF. Esse método deve ser publico pois quando é feito o streaming ele precisa ser acessível.
* @param string $htmlFile O conteúdo HTML para ser convertido
*/
protected function createPdf($htmlFile)
public function createPdf($htmlFile)
{
\wkhtmltox_convert('pdf', array(
'out' => $this->output,
Expand Down
23 changes: 11 additions & 12 deletions test/simpletablereport/SimpleWkPdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function getData()
{
return array
(
array('id' => 1, 'nome' => 'Kelson'),
array('id' => 2, 'nome' => 'KelsonCM'),
array('id' => 3, 'nome' => ''),
array('id' => 4, 'nome' => null),
array('id' => 5, 'nome' => 'null', 'nome2' => '#error'),
array('id' => 6, 'nome2' => '#error')
array('id' => 1, 'nome' => 'Kelson', 'data' => '2014-03-26'),
array('id' => 2, 'nome' => 'KelsonCM', 'data' => '2014-03-26'),
array('id' => 3, 'nome' => '', 'data' => '2014-03-26'),
array('id' => 4, 'nome' => null, 'data' => '2014-03-26'),
array('id' => 5, 'nome' => 'null', 'nome2' => '#error', 'data' => '2014-03-26'),
array('id' => 6, 'nome2' => '#error', 'data' => '2014-03-26')
);
}

Expand All @@ -55,11 +55,10 @@ public function getFieldset()
return $fieldSet
->addField('id', '#', FieldType::INTEGER)
->addField('nome', 'Nome', FieldType::STRING)
->addField('razao', 'Razao', FieldType::FLOAT)
->addField('salario', 'Salario', FieldType::DECIMAL)
->addField('nascimento', 'Nascimento', FieldType::DATE)
->addField('almoco', 'Almoco', FieldType::TIME)
->addField('casamento', 'Casamento', FieldType::TIMESTAMP);
->addField('almoco', 'Almoco', FieldType::TIME, null, null, function($value) {
$date = new DateTime($value);
return $date->format('d-m-Y');
});
}

/**
Expand Down Expand Up @@ -95,7 +94,7 @@ public function testFooter()
$html = new \Umbrella\SimpleReport\Renderer\HtmlRenderer($datasource, $template);
$renderer = new WkPdfRenderer($datasource, $template, $html);
$renderer->setOutput('/tmp/teste-footer.pdf');

$renderer->setUseFooter(true)
->setFooterPathTemplate('/var/www/simpletablereport/test/footer.html')
->setFooterPath('/tmp/teste-footer')
Expand Down

0 comments on commit 70fa676

Please sign in to comment.