Skip to content

Commit

Permalink
B3 it twig3.1 (#1079)
Browse files Browse the repository at this point in the history
* ~ twig to 3.0

* Update Tests for Twig 3.0 stuff

* add 7.4 to travis tests

* interface compatibility

---------

Co-authored-by: Hans Mackowiak <h.mackowiak@b3-it.de>
  • Loading branch information
npotier and Hanmac authored Feb 10, 2023
1 parent cb28229 commit 583cd0b
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 117 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 7.2
- 7.3
- 7.4

matrix:
include:
Expand All @@ -12,13 +13,19 @@ matrix:
- php: 7.2
env: |
SYMFONY_VERSION=^4.0
- php: 7.4
env: |
SYMFONY_VERSION=^3.0
- php: 7.4
env: |
SYMFONY_VERSION=^4.0
before_install:
- echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- |
if [ "${SYMFONY_VERSION}" != "" ]; then
packages="form dependency-injection config http-foundation http-kernel options-resolver security-guard serializer"
devpackages="framework-bundle browser-kit templating expression-language"
devpackages="framework-bundle security-bundle twig-bundle expression-language"
for package in $packages
do
composer require --no-update symfony/"$package"=${SYMFONY_VERSION};
Expand Down
2 changes: 1 addition & 1 deletion Grid/Export/DSVExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct($title, $fileName = 'export', $params = [], $charset
parent::__construct($title, $fileName, $params, $charset);
}

public function computeData($grid)
public function computeData(Grid $grid)
{
$data = $this->getFlatGridData($grid);

Expand Down
2 changes: 1 addition & 1 deletion Grid/Export/ExcelExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ExcelExport extends Export

protected $mimeType = 'application/vnd.ms-excel';

public function computeData($grid)
public function computeData(Grid $grid)
{
$data = $this->getGridData($grid);

Expand Down
4 changes: 2 additions & 2 deletions Grid/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getContainer()
*
* @return Response
*/
public function getResponse()
public function getResponse() : \Symfony\Component\HttpFoundation\Response
{
// Response
$kernelCharset = $this->container->getParameter('kernel.charset');
Expand Down Expand Up @@ -512,7 +512,7 @@ public function setTitle($title)
*
* @return string
*/
public function getTitle()
public function getTitle() : string
{
return $this->title;
}
Expand Down
9 changes: 6 additions & 3 deletions Grid/Export/ExportInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,31 @@

namespace APY\DataGridBundle\Grid\Export;

use APY\DataGridBundle\Grid\Grid;
use Symfony\Component\HttpFoundation\Response;

interface ExportInterface
{
/**
* function call by the grid to fill the content of the export.
*
* @param Grid $grid The grid
*/
public function computeData($grid);
public function computeData(Grid $grid);

/**
* Get the export Response.
*
* @return Response
*/
public function getResponse();
public function getResponse(): Response;

/**
* Get the export title.
*
* @return string
*/
public function getTitle();
public function getTitle(): string;

/**
* Get the export role.
Expand Down
2 changes: 1 addition & 1 deletion Grid/Export/JSONExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class JSONExport extends Export
{
protected $fileExtension = 'json';

public function computeData($grid)
public function computeData(Grid $grid)
{
$this->content = json_encode($this->getGridData($grid));
}
Expand Down
2 changes: 1 addition & 1 deletion Grid/Export/PHPExcel5Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct($tilte, $fileName = 'export', $params = [], $charset
parent::__construct($tilte, $fileName, $params, $charset);
}

public function computeData($grid)
public function computeData(Grid $grid)
{
$data = $this->getFlatGridData($grid);

Expand Down
2 changes: 1 addition & 1 deletion Grid/Export/XMLExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class XMLExport extends Export

protected $mimeType = 'application/xml';

public function computeData($grid)
public function computeData(Grid $grid)
{
$xmlEncoder = new XmlEncoder();
$xmlEncoder->setRootNodeName('grid');
Expand Down
32 changes: 24 additions & 8 deletions Grid/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use APY\DataGridBundle\Grid\Column\ActionsColumn;
use APY\DataGridBundle\Grid\Column\Column;
use APY\DataGridBundle\Grid\Column\MassActionColumn;
use APY\DataGridBundle\Grid\Export\Export;
use APY\DataGridBundle\Grid\Export\ExportInterface;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Source\Source;
Expand Down Expand Up @@ -334,6 +335,11 @@ public function __construct($container, $id = '', GridConfigInterface $config =

$this->id = $id;

// even id is set, do create hash early
if (!empty($this->id)) {
$this->createHash();
}

$this->columns = new Columns($this->securityContext);

$this->routeParameters = $this->request->attributes->all();
Expand Down Expand Up @@ -1100,6 +1106,7 @@ protected function getFromRequest($key)
if (isset($this->requestData[$key])) {
return $this->requestData[$key];
}
return null;
}

/**
Expand All @@ -1114,6 +1121,7 @@ protected function get($key)
if (isset($this->sessionData[$key])) {
return $this->sessionData[$key];
}
return null;
}

/**
Expand Down Expand Up @@ -1394,7 +1402,7 @@ public function getRowActions()
/**
* Sets template for export.
*
* @param \Twig_Template|string $template
* @param TemplateWrapper|string $template
*
* @throws \Exception
*
Expand All @@ -1418,7 +1426,7 @@ public function setTemplate($template)
/**
* Returns template.
*
* @return \Twig_Template|string
* @return string
*/
public function getTemplate()
{
Expand Down Expand Up @@ -1454,19 +1462,19 @@ public function getExports()
/**
* Returns the export response.
*
* @return Export[]
* @return Response
*/
public function getExportResponse()
public function getExportResponse(): Response
{
return $this->exportResponse;
}

/**
* Returns the mass action response.
*
* @return Export[]
* @return Response
*/
public function getMassActionResponse()
public function getMassActionResponse(): Response
{
return $this->massActionResponse;
}
Expand Down Expand Up @@ -2124,7 +2132,7 @@ public function __clone()
* @param string|array $param2 The view name or an array of parameters to pass to the view
* @param Response $response A response instance
*
* @return Response A Response instance
* @return Response|array A Response instance
*/
public function getGridResponse($param1 = null, $param2 = null, Response $response = null)
{
Expand Down Expand Up @@ -2154,7 +2162,15 @@ public function getGridResponse($param1 = null, $param2 = null, Response $respon
if ($view === null) {
return $parameters;
} else {
return new Response($this->container->get('twig')->render($view, $parameters, $response));
$content = $this->container->get('twig')->render($view, $parameters);

if (null === $response) {
$response = new Response();
}

$response->setContent($content);

return $response;
}
}
}
Expand Down
34 changes: 19 additions & 15 deletions Grid/GridManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@

namespace APY\DataGridBundle\Grid;

use Countable;
use IteratorAggregate;
use RuntimeException;
use SplObjectStorage;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

class GridManager implements \IteratorAggregate, \Countable
class GridManager implements IteratorAggregate, Countable
{
protected $container;

Expand All @@ -34,15 +38,15 @@ class GridManager implements \IteratorAggregate, \Countable
public function __construct($container)
{
$this->container = $container;
$this->grids = new \SplObjectStorage();
$this->grids = new SplObjectStorage();
}

public function getIterator()
{
return $this->grids;
}

public function count()
public function count(): int
{
return $this->grids->count();
}
Expand All @@ -52,7 +56,7 @@ public function count()
*
* @return Grid
*/
public function createGrid($id = null)
public function createGrid($id = null): Grid
{
$grid = $this->container->get('grid');

Expand All @@ -65,10 +69,10 @@ public function createGrid($id = null)
return $grid;
}

public function isReadyForRedirect()
public function isReadyForRedirect(): bool
{
if ($this->grids->count() == 0) {
throw new \RuntimeException(self::NO_GRID_EX_MSG);
throw new RuntimeException(self::NO_GRID_EX_MSG);
}

$checkHash = [];
Expand All @@ -90,7 +94,7 @@ public function isReadyForRedirect()
}

if (in_array($grid->getHash(), $checkHash)) {
throw new \RuntimeException(self::SAME_GRID_HASH_EX_MSG);
throw new RuntimeException(self::SAME_GRID_HASH_EX_MSG);
}

$checkHash[] = $grid->getHash();
Expand All @@ -101,10 +105,10 @@ public function isReadyForRedirect()
return $isReadyForRedirect;
}

public function isReadyForExport()
public function isReadyForExport(): bool
{
if ($this->grids->count() == 0) {
throw new \RuntimeException(self::NO_GRID_EX_MSG);
throw new RuntimeException(self::NO_GRID_EX_MSG);
}

$checkHash = [];
Expand All @@ -114,7 +118,7 @@ public function isReadyForExport()
$grid = $this->grids->current();

if (in_array($grid->getHash(), $checkHash)) {
throw new \RuntimeException(self::SAME_GRID_HASH_EX_MSG);
throw new RuntimeException(self::SAME_GRID_HASH_EX_MSG);
}

$checkHash[] = $grid->getHash();
Expand All @@ -131,7 +135,7 @@ public function isReadyForExport()
return false;
}

public function isMassActionRedirect()
public function isMassActionRedirect(): bool
{
$this->grids->rewind();
while ($this->grids->valid()) {
Expand All @@ -152,11 +156,11 @@ public function isMassActionRedirect()
/**
* Renders a view.
*
* @param string|array $param1 The view name or an array of parameters to pass to the view
* @param string|array $param2 The view name or an array of parameters to pass to the view
* @param Response $response A response instance
* @param string|array $param1 The view name or an array of parameters to pass to the view
* @param string|array $param2 The view name or an array of parameters to pass to the view
* @param Response|null $response A response instance
*
* @return Response A Response instance
* @return Response|array A Response instance
*/
public function getGridManagerResponse($param1 = null, $param2 = null, Response $response = null)
{
Expand Down
2 changes: 2 additions & 0 deletions Grid/GridRegistryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace APY\DataGridBundle\Grid;

use APY\DataGridBundle\Grid\Column\Column;
use APY\DataGridBundle\Grid\Export\Export;
use APY\DataGridBundle\Grid\Source\Source;

/**
* The central registry of the Grid component.
Expand Down
Loading

0 comments on commit 583cd0b

Please sign in to comment.