Skip to content

Commit

Permalink
zf3 support (#241)
Browse files Browse the repository at this point in the history
* Update Renderer.php

* Update PrepareData.php

* - unittests update, removed deprecated method `getMock` (#238)

- also removed deprecated method setExpectedException
- run cs fix
- update composer for cs-fix

* - run cs fix
- update composer doctrine
- datagrid should now work with zf2 and zf3

* added unit tests for nightly
  • Loading branch information
kokspflanze authored and ThaDafinser committed Aug 5, 2016
1 parent 58eee24 commit ae36f05
Show file tree
Hide file tree
Showing 46 changed files with 442 additions and 205 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ php:
- 5.6
- 7
- hhvm
- nightly

allow_failures:
- php: nightly

env:
matrix:
Expand Down
25 changes: 12 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,21 @@
"require": {
"php": "~5.5|~7.0",

"zendframework/zend-mvc": "~2.7",
"zendframework/zend-mvc": "~2.7|~3.0",
"zendframework/zend-modulemanager": "~2.5",
"zendframework/zend-session": "~2.5",
"zendframework/zend-view": "~2.5",
"zendframework/zend-http": "~2.5",
"zendframework/zend-paginator": "~2.5",
"zendframework/zend-cache": "~2.5",
"zendframework/zend-servicemanager": "~2.7"
"zendframework/zend-servicemanager": "~2.7|~3.0"
},

"require-dev": {
"phpunit/phpunit": "^4.8|^5.2",
"fabpot/php-cs-fixer": "^1.11",

"doctrine/orm": ">=2.5,<2.7",
"doctrine/dbal": ">=2.5,<2.7",
"doctrine/doctrine-orm-module": "^0.9",
"friendsofphp/php-cs-fixer": "^1.11",
"doctrine/doctrine-orm-module": "dev-master as 1.2",
"doctrine/doctrine-module": "dev-master",

"zendframework/zend-console": "~2.5",
"zendframework/zend-db": "~2.5",
Expand All @@ -53,21 +51,22 @@

"suggest" : {
"ext-intl": "*",

"doctrine/orm": ">=2.5,<2.7",
"doctrine/dbal": ">=2.5,<2.7",
"doctrine/doctrine-orm-module": "^0.9",
"doctrine/doctrine-orm-module": "for doctrine support",

"phpoffice/phpexcel": "^1.8",
"tecnickcom/tcpdf": "^6.2",

"zendframework/zend-text": "~2.5",
"zendframework/zend-json": "to support date ranges"
},

"autoload": {
"psr-0": {
"ZfcDatagrid\\": "src/",
"ZfcDatagrid\\": "src/"
}
},
"autoload-dev": {
"psr-0": {
"ZfcDatagridTest\\": "tests/"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ZfcDatagrid/Column/Action/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function getLabel()
}

/**
*
* @return string
* @throws \Exception
*/
protected function getHtmlType()
{
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Column/Style/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* general or based on a value
*
*/

namespace ZfcDatagrid\Column\Style;

class Color extends AbstractColor
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Column/Type/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/**
* Image type
*/

namespace ZfcDatagrid\Column\Type;

use InvalidArgumentException;
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* or if we use the "safe" variant by Doctrine2
*
*/

namespace ZfcDatagrid\DataSource\Doctrine2;

use Doctrine\ORM\QueryBuilder;
Expand Down
33 changes: 30 additions & 3 deletions src/ZfcDatagrid/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
use ArrayIterator;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\QueryBuilder;
use Interop\Container\ContainerInterface;
use Zend\Cache;
use Zend\Console\Request as ConsoleRequest;
use Zend\Db\Sql\Select as ZendSelect;
use Zend\Http\PhpEnvironment\Request as HttpRequest;
use Zend\I18n\Translator\Translator;
use Zend\Mvc\MvcEvent;
use Zend\Paginator\Paginator;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Session\Container as SessionContainer;
use Zend\Stdlib\ResponseInterface;
use Zend\View\Model\JsonModel;
Expand All @@ -20,8 +21,6 @@

class Datagrid
{
use ServiceLocatorAwareTrait;

/**
*
* @var array
Expand Down Expand Up @@ -221,6 +220,11 @@ class Datagrid
'sortDefault',
];

/**
* @var ServiceLocatorInterface
*/
protected $serviceLocator = null;

/**
* Init method is called automatically with the service creation
*/
Expand Down Expand Up @@ -1196,4 +1200,27 @@ public function setRendererService(Renderer\AbstractRenderer $rendererService)

return $this;
}

/**
* Set service locator
*
* @param ContainerInterface $serviceLocator
* @return mixed
*/
public function setServiceLocator(ContainerInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;

return $this;
}

/**
* Get service locator
*
* @return ContainerInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
}
4 changes: 3 additions & 1 deletion src/ZfcDatagrid/PrepareData.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ public function prepare()
*/
if (is_array($row[$col->getUniqueId()])) {
array_walk_recursive($row[$col->getUniqueId()], function (&$value) {
$value = trim($value);
if (!is_object($value)) {
$value = trim($value);
}
});
} elseif (!is_object($row[$col->getUniqueId()])) {
$row[$col->getUniqueId()] = trim($row[$col->getUniqueId()]);
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Renderer/AbstractExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Methods which can be used in (all) export renderer
*
*/

namespace ZfcDatagrid\Renderer;

use ZfcDatagrid\Column;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
<?php
namespace ZfcDatagrid\Renderer\BootstrapTable\View\Helper;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class TableRowFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface|AbstractPluginManager $serviceLocator
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return TableRow
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$tableRow = new TableRow();
if ($serviceLocator->getServiceLocator()->has('translator')) {
/** @noinspection PhpParamsInspection */
$tableRow->setTranslator($serviceLocator->getServiceLocator()->get('translator'));
if ($container->has('translator')) {
$tableRow->setTranslator($container->get('translator'));
}

return $tableRow;
}

/**
* @param ServiceLocatorInterface|AbstractPluginManager $serviceLocator
* @return TableRow
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator->getServiceLocator(), TableRow::class);
}
}
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Renderer/Csv/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Render datagrid as CSV
*
*/

namespace ZfcDatagrid\Renderer\Csv;

use Zend\Http\Headers;
Expand Down
21 changes: 16 additions & 5 deletions src/ZfcDatagrid/Renderer/JqGrid/View/Helper/ColumnsFactory.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
<?php
namespace ZfcDatagrid\Renderer\JqGrid\View\Helper;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class ColumnsFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface|AbstractPluginManager $serviceLocator
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return Columns
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$tableRow = new Columns();
if ($serviceLocator->getServiceLocator()->has('translator')) {
/** @noinspection PhpParamsInspection */
$tableRow->setTranslator($serviceLocator->getServiceLocator()->get('translator'));
if ($container->has('translator')) {
$tableRow->setTranslator($container->get('translator'));
}

return $tableRow;
}

/**
* @param ServiceLocatorInterface|AbstractPluginManager $serviceLocator
* @return Columns
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator->getServiceLocator(), Columns::class);
}
}
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/**
* Output as an excel file
*/

namespace ZfcDatagrid\Renderer\PHPExcel;

use PHPExcel;
Expand Down
5 changes: 2 additions & 3 deletions src/ZfcDatagrid/Renderer/TCPDF/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/**
* Output as a PDF file
*/

namespace ZfcDatagrid\Renderer\TCPDF;

use TCPDF;
Expand Down Expand Up @@ -314,10 +313,10 @@ protected function printTableRow(array $row, $rowHeight)
if ($file !== false) {
list($width, $height) = $this->calcImageSize($file, $col->getWidth() - 2, $rowHeight - 2);

$pdf->Image('@' . $file, $x + 1, $y + 1, $width, $height, '', '', 'L', false);
$pdf->Image('@' . $file, $x + 1, $y + 1, $width, $height, '', '', 'L', true);
}
} else {
$pdf->Image($link, $x + 1, $y + 1, 0, $resizeHeight, '', '', 'L', false);
$pdf->Image($link, $x + 1, $y + 1, 0, $resizeHeight, '', '', 'L', true);
}
} catch (\Exception $e) {
// if tcpdf couldnt find a image, continue and log it
Expand Down
33 changes: 23 additions & 10 deletions src/ZfcDatagrid/Service/AbstractDatagrid.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace ZfcDatagrid\Service;

use Interop\Container\ContainerInterface;
use InvalidArgumentException;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
Expand All @@ -9,33 +10,45 @@
abstract class AbstractDatagrid extends Datagrid implements FactoryInterface
{
/**
*
* @return Datagrid
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return $this
*/
public function createService(ServiceLocatorInterface $sm)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$this->setServiceLocator($sm);
$config = $sm->get('config');
$this->setServiceLocator($container);
$config = $container->get('config');

if (! isset($config['ZfcDatagrid'])) {
throw new InvalidArgumentException('Config key "ZfcDatagrid" is missing');
}

/* @var $application \Zend\Mvc\Application */
$application = $sm->get('application');
$application = $container->get('application');

parent::setOptions($config['ZfcDatagrid']);
parent::setMvcEvent($application->getMvcEvent());
if ($sm->has('translator') === true) {
parent::setTranslator($sm->get('translator'));

if ($container->has('translator') === true) {
parent::setTranslator($container->get('translator'));
}
/** @noinspection PhpParamsInspection */
parent::setRendererService($sm->get('zfcDatagrid.renderer.' . parent::getRendererName()));

parent::setRendererService($container->get('zfcDatagrid.renderer.' . parent::getRendererName()));
parent::init();

return $this;
}

/**
* @param ServiceLocatorInterface $serviceLocator
* @return Datagrid
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, Datagrid::class);
}

/**
* Call initGrid on rendering
*/
Expand Down
Loading

0 comments on commit ae36f05

Please sign in to comment.