Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into rfc/escaper
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 48 changed files with 576 additions and 980 deletions.
46 changes: 0 additions & 46 deletions src/Adapter.php

This file was deleted.

33 changes: 33 additions & 0 deletions src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Paginator
*/

namespace Zend\Paginator\Adapter;

use Countable;

/**
* Interface for pagination adapters.
*
* @category Zend
* @package Paginator
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface AdapterInterface extends Countable
{
/**
* Returns an collection of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
public function getItems($offset, $itemCountPerPage);
}
27 changes: 6 additions & 21 deletions src/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Paginator
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Paginator
*/

/**
* @namespace
*/
namespace Zend\Paginator\Adapter;
use Zend\Paginator\Adapter;

/**
* @uses \Zend\Paginator\Adapter
* @category Zend
* @package Paginator
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class ArrayAdapter implements Adapter
class ArrayAdapter implements AdapterInterface
{
/**
* ArrayAdapter
Expand Down
104 changes: 42 additions & 62 deletions src/Adapter/DbSelect.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,24 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Paginator
*/

/**
* @namespace
*/
namespace Zend\Paginator\Adapter;

use Zend\Db\Select,
Zend\Db,
Zend\Paginator\Adapter,
Zend\Paginator\Adapter\Exception;
use Zend\Db\Sql;

/**
* @uses \Zend\Db\Db
* @uses \Zend\Db\Expr
* @uses \Zend\Db\Select
* @uses \Zend\Paginator\Adapter
* @uses Zend\Paginator\Adapter\Exception
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class DbSelect implements Adapter
class DbSelect implements AdapterInterface
{
/**
* Name of the row count column
Expand All @@ -51,14 +30,14 @@ class DbSelect implements Adapter
/**
* The COUNT query
*
* @var \Zend\Db\Select
* @var \Zend\Db\Sql\Select
*/
protected $_countSelect = null;

/**
* Database query
*
* @var \Zend\Db\Select
* @var \Zend\Db\Sql\Select
*/
protected $_select = null;

Expand All @@ -72,9 +51,9 @@ class DbSelect implements Adapter
/**
* Constructor.
*
* @param \Zend\Db\Select $select The select query
* @param \Zend\Db\Sql\Select $select The select query
*/
public function __construct(Select $select)
public function __construct(Sql\Select $select)
{
$this->_select = $select;
}
Expand All @@ -89,19 +68,19 @@ public function __construct(Select $select)
* Users are therefore encouraged to profile their queries to find
* the solution that best meets their needs.
*
* @param \Zend\Db\Select|integer $totalRowCount Total row count integer
* @param \Zend\Db\Sql\Select|integer $rowCount Total row count integer
* or query
* @return \Zend\Paginator\Adapter\DbSelect $this
* @throws \Zend\Paginator\Adapter\Exception
* @throws Exception\InvalidArgumentException
* @return DbSelect
*/
public function setRowCount($rowCount)
{
if ($rowCount instanceof Select) {
$columns = $rowCount->getPart(Select::COLUMNS);
if ($rowCount instanceof Sql\Select) {
$columns = $rowCount->getPart(Sql\Select::COLUMNS);

$countColumnPart = $columns[0][1];

if ($countColumnPart instanceof Db\Expr) {
if ($countColumnPart instanceof Sql\ExpressionInterface) {
$countColumnPart = $countColumnPart->__toString();
}

Expand All @@ -127,7 +106,7 @@ public function setRowCount($rowCount)
/**
* Returns an array of items for a page.
*
* @param integer $offset Page offset
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
* @return array
*/
Expand Down Expand Up @@ -161,7 +140,7 @@ public function count()
* In that use-case I'm expecting problems when either GROUP BY or DISTINCT
* has one column.
*
* @return \Zend\Db\Select
* @return \Zend\Db\Sql\Select
*/
public function getCountSelect()
{
Expand All @@ -181,23 +160,23 @@ public function getCountSelect()
$countColumn = $db->quoteIdentifier($db->foldCase(self::ROW_COUNT_COLUMN));
$countPart = 'COUNT(1) AS ';
$groupPart = null;
$unionParts = $rowCount->getPart(Select::UNION);
$unionParts = $rowCount->getPart(Sql\Select::UNION);

/**
* If we're dealing with a UNION query, execute the UNION as a subquery
* to the COUNT query.
*/
if (!empty($unionParts)) {
$expression = new Db\Expr($countPart . $countColumn);
$rowCount = $db
->select()
->bind($rowCount->getBind())
->from($rowCount, $expression);
$expression = new Sql\Expression($countPart . $countColumn);
$rowCount = $db
->select()
->bind($rowCount->getBind())
->from($rowCount, $expression);
} else {
$columnParts = $rowCount->getPart(Select::COLUMNS);
$groupParts = $rowCount->getPart(Select::GROUP);
$havingParts = $rowCount->getPart(Select::HAVING);
$isDistinct = $rowCount->getPart(Select::DISTINCT);
$columnParts = $rowCount->getPart(Sql\Select::COLUMNS);
$groupParts = $rowCount->getPart(Sql\Select::GROUP);
$havingParts = $rowCount->getPart(Sql\Select::HAVING);
$isDistinct = $rowCount->getPart(Sql\Select::DISTINCT);

/**
* If there is more than one column AND it's a DISTINCT query, more
Expand All @@ -209,7 +188,7 @@ public function getCountSelect()
} else if ($isDistinct) {
$part = $columnParts[0];

if ($part[1] !== Select::SQL_WILDCARD && !($part[1] instanceof Db\Expr)) {
if ($part[1] !== Sql\Select::SQL_WILDCARD && !($part[1] instanceof Sql\ExpressionInterface)) {
$column = $db->quoteIdentifier($part[1], true);

if (!empty($part[0])) {
Expand All @@ -218,8 +197,9 @@ public function getCountSelect()

$groupPart = $column;
}
} else if (!empty($groupParts) && $groupParts[0] !== Select::SQL_WILDCARD &&
!($groupParts[0] instanceof Db\Expr)) {
} else if (!empty($groupParts) && $groupParts[0] !== Sql\Select::SQL_WILDCARD &&
!($groupParts[0] instanceof Sql\ExpressionInterface)
) {
$groupPart = $db->quoteIdentifier($groupParts[0], true);
}

Expand All @@ -235,15 +215,15 @@ public function getCountSelect()
/**
* Create the COUNT part of the query
*/
$expression = new Db\Expr($countPart . $countColumn);

$rowCount->reset(Select::COLUMNS)
->reset(Select::ORDER)
->reset(Select::LIMIT_OFFSET)
->reset(Select::GROUP)
->reset(Select::DISTINCT)
->reset(Select::HAVING)
->columns($expression);
$expression = new Sql\Expression($countPart . $countColumn);

$rowCount->reset(Sql\Select::COLUMNS)
->reset(Sql\Select::ORDER)
->reset(Sql\Select::LIMIT_OFFSET)
->reset(Sql\Select::GROUP)
->reset(Sql\Select::DISTINCT)
->reset(Sql\Select::HAVING)
->columns($expression);
}

$this->_countSelect = $rowCount;
Expand Down
26 changes: 6 additions & 20 deletions src/Adapter/DbTableSelect.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Paginator
*/

/**
* @namespace
*/
namespace Zend\Paginator\Adapter;

/**
* @uses \Zend\Paginator\Adapter\DbSelect
* @category Zend
* @package Zend_Paginator
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
Expand All @@ -33,7 +19,7 @@
class DbTableSelect extends DbSelect
{
/**
* Returns a Zend_Db_Table_Rowset_Abstract of items for a page.
* Returns a Zend\Db\Table\AbstractRowset of items for a page.
*
* @param integer $offset Page offset
* @param integer $itemCountPerPage Number of items per page
Expand Down

0 comments on commit 2310cd0

Please sign in to comment.