Skip to content

Commit

Permalink
Merge pull request #235 from ThaDafinser/develop
Browse files Browse the repository at this point in the history
`zend-mvc` 2.7 compability
  • Loading branch information
ThaDafinser committed Apr 21, 2016
2 parents b20faf7 + 58eee24 commit 939817c
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 140 deletions.
12 changes: 7 additions & 5 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 @@ -46,8 +47,8 @@
"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-text": "~2.5",
"zendframework/zend-json": "~2.5"
},

"suggest" : {
Expand All @@ -60,7 +61,8 @@
"phpoffice/phpexcel": "^1.8",
"tecnickcom/tcpdf": "^6.2",

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

"autoload": {
Expand Down
58 changes: 39 additions & 19 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
return [

use ZfcDatagrid\Datagrid;
use ZfcDatagrid\Renderer;
use ZfcDatagrid\Service;
use Zend\ServiceManager\Factory\InvokableFactory;

return [
'ZfcDatagrid' => [

'settings' => [
Expand Down Expand Up @@ -198,38 +203,53 @@

'service_manager' => [

'invokables' => [
'factories' => [
Service\DatagridManager::class => Service\DatagridManagerFactory::class,
Datagrid::class => Service\DatagridFactory::class,

'zfcDatagrid_dbAdapter' => Service\ZendDbAdapterFactory::class,

// HTML renderer
'zfcDatagrid.renderer.bootstrapTable' => 'ZfcDatagrid\Renderer\BootstrapTable\Renderer',
'zfcDatagrid.renderer.jqgrid' => 'ZfcDatagrid\Renderer\JqGrid\Renderer',
Renderer\BootstrapTable\Renderer::class => InvokableFactory::class,
Renderer\JqGrid\Renderer::class => InvokableFactory::class,

// CLI renderer
'zfcDatagrid.renderer.zendTable' => 'ZfcDatagrid\Renderer\ZendTable\Renderer',
Renderer\ZendTable\Renderer::class => InvokableFactory::class,

// Export renderer
'zfcDatagrid.renderer.printHtml' => 'ZfcDatagrid\Renderer\PrintHtml\Renderer',
'zfcDatagrid.renderer.PHPExcel' => 'ZfcDatagrid\Renderer\PHPExcel\Renderer',
'zfcDatagrid.renderer.TCPDF' => 'ZfcDatagrid\Renderer\TCPDF\Renderer',
'zfcDatagrid.renderer.csv' => 'ZfcDatagrid\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,
],

'factories' => [
'ZfcDatagridManager' => 'ZfcDatagrid\Service\DatagridManagerFactory',
'ZfcDatagrid\Datagrid' => 'ZfcDatagrid\Service\DatagridFactory',
'aliases' => [
'zfcDatagrid' => Datagrid::class,
'ZfcDatagridManager' => Service\DatagridManager::class,

'zfcDatagrid_dbAdapter' => 'ZfcDatagrid\Service\ZendDbAdapterFactory',
],
// HTML renderer
'zfcDatagrid.renderer.bootstrapTable' => Renderer\BootstrapTable\Renderer::class,
'zfcDatagrid.renderer.jqgrid' => Renderer\JqGrid\Renderer::class,

'aliases' => [
'zfcDatagrid' => 'ZfcDatagrid\Datagrid',
// CLI renderer
'zfcDatagrid.renderer.zendTable' => Renderer\ZendTable\Renderer::class,

// Export renderer
'zfcDatagrid.renderer.printHtml' => Renderer\PrintHtml\Renderer::class,
'zfcDatagrid.renderer.PHPExcel' => Renderer\PHPExcel\Renderer::class,
'zfcDatagrid.renderer.TCPDF' => Renderer\TCPDF\Renderer::class,
'zfcDatagrid.renderer.csv' => Renderer\Csv\Renderer::class,
],
],

'view_helpers' => [
'invokables' => [
'bootstrapTableRow' => 'ZfcDatagrid\Renderer\BootstrapTable\View\Helper\TableRow',
'jqgridColumns' => 'ZfcDatagrid\Renderer\JqGrid\View\Helper\Columns',
'aliases' => [
'bootstrapTableRow' => Renderer\BootstrapTable\View\Helper\TableRow::class,
'jqgridColumns' => Renderer\JqGrid\View\Helper\Columns::class,
],
'factories' => [
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
54 changes: 25 additions & 29 deletions src/ZfcDatagrid/Column/Formatter/GenerateLink.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace ZfcDatagrid\Column\Formatter;

use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\Renderer\RendererInterface;
use ZfcDatagrid\Column\AbstractColumn;

class GenerateLink extends AbstractFormatter implements ServiceManagerAwareInterface
class GenerateLink extends AbstractFormatter
{
/** @var array */
protected $validRenderers = [
Expand All @@ -19,20 +19,26 @@ class GenerateLink extends AbstractFormatter implements ServiceManagerAwareInter
protected $routeParams;
/** @var string|null */
protected $routeKey;
/** @var ServiceManager */
protected $serviceManager;
/** @var \Zend\View\Renderer\PhpRenderer */
protected $viewRenderer;

/**
* @param ServiceManager $sm
* @param $route
* @param null $key
* @param array $params
* @param ServiceLocatorInterface|RendererInterface $viewRenderer
* @param $route
* @param null $key
* @param array $params
*/
public function __construct(ServiceManager $sm, $route, $key = null, $params = [])
public function __construct($viewRenderer, $route, $key = null, $params = [])
{
$this->setServiceManager($sm);
/**
* old fallback that should be removed in 2.0
* TODO remove in 2.0
*/
if (!$viewRenderer instanceof RendererInterface) {
$viewRenderer = $viewRenderer->get('ViewRenderer');
}

$this->setViewRenderer($viewRenderer);
$this->setRoute($route);
$this->setRouteParams($params);
$this->setRouteKey($key);
Expand Down Expand Up @@ -61,32 +67,22 @@ public function getFormattedValue(AbstractColumn $column)
}

/**
* Set service manager
* @param ServiceManager $serviceManager
*/
public function setServiceManager(ServiceManager $serviceManager)
{
$this->serviceManager = $serviceManager;
}

/**
* @return ServiceManager
* @return \Zend\View\Renderer\PhpRenderer
*/
public function getServiceManager()
public function getViewRenderer()
{
return $this->serviceManager;
return $this->viewRenderer;
}

/**
* @return \Zend\View\Renderer\PhpRenderer
* @param \Zend\View\Renderer\PhpRenderer $viewRenderer
* @return self
*/
public function getViewRenderer()
public function setViewRenderer($viewRenderer)
{
if (! $this->viewRenderer) {
$this->viewRenderer = $this->getServiceManager()->get('ViewRenderer');
}
$this->viewRenderer = $viewRenderer;

return $this->viewRenderer;
return $this;
}

/**
Expand Down
29 changes: 21 additions & 8 deletions src/ZfcDatagrid/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
use Zend\I18n\Translator\Translator;
use Zend\Mvc\MvcEvent;
use Zend\Paginator\Paginator;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Zend\Session\Container as SessionContainer;
use Zend\Stdlib\ResponseInterface;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;
use ZfcDatagrid\Column\Style;

class Datagrid implements ServiceLocatorAwareInterface
class Datagrid
{
use ServiceLocatorAwareTrait;

Expand Down Expand Up @@ -205,6 +204,12 @@ class Datagrid implements ServiceLocatorAwareInterface
*/
protected $forceRenderer;

/**
*
* @var Renderer\AbstractRenderer
*/
private $rendererService;

/**
* @var array
*/
Expand Down Expand Up @@ -868,11 +873,8 @@ public function getRendererName()
public function getRenderer()
{
if (null === $this->renderer) {
$rendererName = 'zfcDatagrid.renderer.' . $this->getRendererName();

if ($this->getServiceLocator()->has($rendererName) === true) {
/* @var $renderer \ZfcDatagrid\Renderer\AbstractRenderer */
$renderer = $this->getServiceLocator()->get($rendererName);
if (isset($this->rendererService)) {
$renderer = $this->rendererService;
if (! $renderer instanceof Renderer\AbstractRenderer) {
throw new \Exception('Renderer service must implement "ZfcDatagrid\Renderer\AbstractRenderer"');
}
Expand All @@ -894,7 +896,7 @@ public function getRenderer()

$this->renderer = $renderer;
} else {
throw new \Exception(sprintf('Renderer service was not found, please register it: "%s"', $rendererName));
throw new \Exception(sprintf('Renderer service was not found, please register it: "zfcDatagrid.renderer.%s"', $this->getRendererName()));
}
}

Expand Down Expand Up @@ -1183,4 +1185,15 @@ public function isHtmlInitReponse()

return false;
}

/**
* @param Renderer\AbstractRenderer $rendererService
* @return self
*/
public function setRendererService(Renderer\AbstractRenderer $rendererService)
{
$this->rendererService = $rendererService;

return $this;
}
}
30 changes: 19 additions & 11 deletions src/ZfcDatagrid/Renderer/BootstrapTable/View/Helper/TableRow.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
<?php
namespace ZfcDatagrid\Renderer\BootstrapTable\View\Helper;

use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Zend\View\Helper\AbstractHelper;
use ZfcDatagrid\Column;
use ZfcDatagrid\Column\Action\AbstractAction;

/**
* View Helper
*/
class TableRow extends AbstractHelper implements ServiceLocatorAwareInterface
class TableRow extends AbstractHelper
{
use ServiceLocatorAwareTrait;
/** @var \Zend\I18n\Translator\Translator|null|false */
private $translator;

/**
* @param false|null|\Zend\I18n\Translator\Translator $translator
* @return self
*/
public function setTranslator($translator)
{
$this->translator = $translator;

return $this;
}

/**
*
* @param string $name
* @param string $message
* @return string
*/
private function translate($name)
private function translate($message)
{
if ($this->getServiceLocator()->has('translator') === true) {
return $this->getServiceLocator()
->get('translator')
->translate($name);
if (null === $this->translator) {
return $message;
}

return $name;
return $this->translator->translate($message);
}

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

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

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

return $tableRow;
}
}
Loading

0 comments on commit 939817c

Please sign in to comment.