Skip to content

Commit

Permalink
readded ServiceLocatorAwareTrait in ZfcDataGrid\Datagrid [remove part…
Browse files Browse the repository at this point in the history
…s of the BC]

added  TableRowFactory + ColumnsFactory for the ViewHelpers [so config cache should now work]
also removed the other closure and added InvokableFactory in config
update composer.json min zend-mvc 2.7 + zend-servicemanger 2.7 [moved to require]
updated unittests
  • Loading branch information
kokspflanze committed Mar 29, 2016
1 parent 49f23d3 commit 5f8451d
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 45 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
"require": {
"php": "~5.5|~7.0",

"zendframework/zend-mvc": "~2.5",
"zendframework/zend-mvc": "~2.7",
"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-cache": "~2.5",
"zendframework/zend-servicemanager": "~2.7"
},

"require-dev": {
Expand All @@ -45,7 +46,6 @@
"zendframework/zend-console": "~2.5",
"zendframework/zend-db": "~2.5",
"zendframework/zend-i18n": "~2.5",
"zendframework/zend-servicemanager": "~2.5",
"zendframework/zend-text": "~2.5",
"zendframework/zend-json": "~2.5"
},
Expand Down
51 changes: 10 additions & 41 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use ZfcDatagrid\Datagrid;
use ZfcDatagrid\Renderer;
use ZfcDatagrid\Service;
use Zend\ServiceManager\Factory\InvokableFactory;

return [
'ZfcDatagrid' => [
Expand Down Expand Up @@ -209,31 +210,17 @@
'zfcDatagrid_dbAdapter' => Service\ZendDbAdapterFactory::class,

// HTML renderer
Renderer\BootstrapTable\Renderer::class => function() {
return new Renderer\BootstrapTable\Renderer();
},
Renderer\JqGrid\Renderer::class => function() {
return new Renderer\JqGrid\Renderer();
},
Renderer\BootstrapTable\Renderer::class => InvokableFactory::class,
Renderer\JqGrid\Renderer::class => InvokableFactory::class,

// CLI renderer
Renderer\ZendTable\Renderer::class => function() {
return new Renderer\ZendTable\Renderer();
},
Renderer\ZendTable\Renderer::class => InvokableFactory::class,

// Export renderer
Renderer\PrintHtml\Renderer::class => function() {
return new Renderer\PrintHtml\Renderer();
},
Renderer\PHPExcel\Renderer::class => function() {
return new Renderer\PHPExcel\Renderer();
},
Renderer\TCPDF\Renderer::class => function() {
return new Renderer\TCPDF\Renderer();
},
Renderer\Csv\Renderer::class => function() {
return new Renderer\Csv\Renderer();
},
Renderer\PrintHtml\Renderer::class => InvokableFactory::class,
Renderer\PHPExcel\Renderer::class => InvokableFactory::class,
Renderer\TCPDF\Renderer::class => InvokableFactory::class,
Renderer\Csv\Renderer::class => InvokableFactory::class,
],

'aliases' => [
Expand Down Expand Up @@ -261,26 +248,8 @@
'jqgridColumns' => Renderer\JqGrid\View\Helper\Columns::class,
],
'factories' => [
Renderer\BootstrapTable\View\Helper\TableRow::class => function($sm) {
/** @var $sm \Zend\ServiceManager\ServiceLocatorInterface */
$tableRow = new Renderer\BootstrapTable\View\Helper\TableRow();
if($sm->has('translator')){
/** @noinspection PhpParamsInspection */
$tableRow->setTranslator($sm->get('translator'));
}

return $tableRow;
},
Renderer\JqGrid\View\Helper\Columns::class => function($sm) {
/** @var $sm \Zend\ServiceManager\ServiceLocatorInterface */
$tableRow = new Renderer\JqGrid\View\Helper\Columns();
if($sm->has('translator')){
/** @noinspection PhpParamsInspection */
$tableRow->setTranslator($sm->get('translator'));
}

return $tableRow;
},
Renderer\BootstrapTable\View\Helper\TableRow::class => Renderer\BootstrapTable\View\Helper\TableRowFactory::class,
Renderer\JqGrid\View\Helper\Columns::class => Renderer\JqGrid\View\Helper\ColumnsFactory::class,
],
],

Expand Down
3 changes: 3 additions & 0 deletions src/ZfcDatagrid/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Zend\I18n\Translator\Translator;
use Zend\Mvc\MvcEvent;
use Zend\Paginator\Paginator;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Zend\Session\Container as SessionContainer;
use Zend\Stdlib\ResponseInterface;
use Zend\View\Model\JsonModel;
Expand All @@ -19,6 +20,8 @@

class Datagrid
{
use ServiceLocatorAwareTrait;

/**
*
* @var array
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php


namespace ZfcDatagrid\Renderer\BootstrapTable\View\Helper;


use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class TableRowFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @return TableRow
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$tableRow = new TableRow();
if($serviceLocator->has('translator')){
/** @noinspection PhpParamsInspection */
$tableRow->setTranslator($serviceLocator->get('translator'));
}

return $tableRow;
}

}
27 changes: 27 additions & 0 deletions src/ZfcDatagrid/Renderer/JqGrid/View/Helper/ColumnsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php


namespace ZfcDatagrid\Renderer\JqGrid\View\Helper;


use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class ColumnsFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @return Columns
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$tableRow = new Columns();
if($serviceLocator->has('translator')){
/** @noinspection PhpParamsInspection */
$tableRow->setTranslator($serviceLocator->get('translator'));
}

return $tableRow;
}

}
1 change: 1 addition & 0 deletions src/ZfcDatagrid/Service/AbstractDatagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class AbstractDatagrid extends Datagrid implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $sm)
{
$this->setServiceLocator($sm);
$config = $sm->get('config');

if (! isset($config['ZfcDatagrid'])) {
Expand Down
1 change: 1 addition & 0 deletions src/ZfcDatagrid/Service/DatagridFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function createService(ServiceLocatorInterface $sm)
$application = $sm->get('application');

$grid = new Datagrid();
$grid->setServiceLocator($sm);
$grid->setOptions($config['ZfcDatagrid']);
$grid->setMvcEvent($application->getMvcEvent());
if ($sm->has('translator') === true) {
Expand Down
2 changes: 2 additions & 0 deletions tests/ZfcDatagridTest/Column/Formatter/GenerateLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ public function testConstructorFallBackVersion()

public function testGetFormattedValue()
{
/** @var \ZfcDatagrid\Column\AbstractColumn $col */
$col = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn');
$col->setUniqueId('foo');

$phpRenderer = $this->getMockBuilder('Zend\View\Renderer\PhpRenderer')
->disableOriginalConstructor()
->setMethods(['url'])
->getMock();

$phpRenderer->expects($this->any())
Expand Down
5 changes: 4 additions & 1 deletion tests/ZfcDatagridTest/DatagridTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ public function testAddColumn()
{
$this->assertEquals([], $this->grid->getColumns());

$col = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn');
$col = $this->getMockBuilder('ZfcDatagrid\Column\AbstractColumn')
->setMethods(['getUniqueId'])
->getMock();

$col->expects($this->any())
->method('getUniqueId')
->will($this->returnValue('myUniqueId'));
Expand Down

0 comments on commit 5f8451d

Please sign in to comment.