Skip to content

Commit

Permalink
Main changes in ZfcDatagrid\Datagrid for better code completion in IDE
Browse files Browse the repository at this point in the history
 added missing methods in `ZfcDatagrid\DataSource\DataSourceInterface`
 added php-doc in `ZfcDatagrid\DataSource\AbstractDataSource`
  • Loading branch information
kokspflanze committed Apr 16, 2015
1 parent bb39563 commit bffe30a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/ZfcDatagrid/DataSource/AbstractDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public function addSortCondition(Column\AbstractColumn $column, $sortDirection =
];
}

/**
* @param array $sortConditions
*/
public function setSortConditions(array $sortConditions)
{
$this->sortConditions = $sortConditions;
Expand All @@ -89,6 +92,10 @@ public function addFilter(Filter $filter)
$this->filters[] = $filter;
}

/**
*
* @param array $filters
*/
public function setFilters(array $filters)
{
$this->filters = $filters;
Expand All @@ -103,6 +110,9 @@ public function getFilters()
return $this->filters;
}

/**
* @param PaginatorAdapterInterface $paginator
*/
public function setPaginatorAdapter(PaginatorAdapterInterface $paginator)
{
$this->paginatorAdapter = $paginator;
Expand Down
30 changes: 30 additions & 0 deletions src/ZfcDatagrid/DataSource/DataSourceInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
namespace ZfcDatagrid\DataSource;

use ZfcDatagrid\Column;
use ZfcDatagrid\Filter;

interface DataSourceInterface
{
/**
Expand All @@ -27,4 +30,31 @@ public function getData();
* - with filters statements
*/
public function execute();

/**
* Set the columns
*
* @param array $columns
*/
public function setColumns(array $columns);

/**
* Set sort conditions
*
* @param Column\AbstractColumn $column
* @param string $sortDirection
*/
public function addSortCondition(Column\AbstractColumn $column, $sortDirection = 'ASC');

/**
*
* @param array $filters
*/
public function addFilter(Filter $filter);

/**
*
* @return \Zend\Paginator\Adapter\AdapterInterface
*/
public function getPaginatorAdapter();
}
24 changes: 16 additions & 8 deletions src/ZfcDatagrid/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Datagrid implements ServiceLocatorAwareInterface
/**
* View or Response
*
* @var \Zend\Http\Response\Stream \Zend\View\Model\ViewModel
* @var \Zend\Http\Response\Stream|\Zend\View\Model\ViewModel
*/
protected $response;

Expand Down Expand Up @@ -647,7 +647,7 @@ private function createColumn($config)
} elseif (class_exists('ZfcDatagrid\\Column\\' . $colType, true)) {
$class = 'ZfcDatagrid\\Column\\' . $colType;
} else {
throw new \InvalidArgumentException('Column type: "' . $colType . '" not found!');
throw new \InvalidArgumentException(sprintf('Column type: "%s" not found!', $colType));
}

if ('ZfcDatagrid\\Column\\Select' == $class) {
Expand Down Expand Up @@ -930,7 +930,7 @@ public function getRenderer()

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

Expand Down Expand Up @@ -1015,13 +1015,14 @@ public function loadData()
} elseif ($data instanceof ArrayIterator) {
$data = $data->getArrayCopy();
} else {
$add = '';
if (is_object($data)) {
$add = get_class($data);
} else {
$add = '[no object]';
}
throw new \Exception('The paginator returned an unknow result: ' . $add . ' (allowed: \ArrayIterator or a plain php array)');
throw new \Exception(
sprintf('The paginator returned an unknown result: %s (allowed: \ArrayIterator or a plain php array)', $add)
);
}
}
}
Expand All @@ -1038,8 +1039,15 @@ public function loadData()
];
$success = $this->getCache()->setItem($this->getCacheId(), $cacheData);
if ($success !== true) {
/** @var \Zend\Cache\Storage\Adapter\FilesystemOptions $options */
$options = $this->getCache()->getOptions();
throw new \Exception('Could not save the datagrid cache. Does the directory "' . $options->getCacheDir() . '" exists and is writeable? CacheId: ' . $this->getCacheId());
throw new \Exception(
sprintf(
'Could not save the datagrid cache. Does the directory "%s" exists and is writeable? CacheId: %s',
$options->getCacheDir(),
$this->getCacheId()
)
);
}
}

Expand Down Expand Up @@ -1141,7 +1149,7 @@ public function setToolbarTemplate($name)
* Get the toolbar template name
* Return null if nothing custom set
*
* @return string null
* @return string|null
*/
public function getToolbarTemplate()
{
Expand Down Expand Up @@ -1197,7 +1205,7 @@ public function getViewModel()

/**
*
* @return Ambigous <\Zend\Stdlib\ResponseInterface, \Zend\Http\Response\Stream, \Zend\View\Model\ViewModel>
* @return \Zend\Stdlib\ResponseInterface|\Zend\Http\Response\Stream|\Zend\View\Model\ViewModel
*/
public function getResponse()
{
Expand Down

0 comments on commit bffe30a

Please sign in to comment.