Skip to content

Commit 9304078

Browse files
committed
Revert "Replace Porpaginas with self-owned code"
This reverts commit 45fe740. This is required to keep compatibility with GraphQLite. While this is technically a breaking change, the 6.0 version has low pulls and this interface is mostly internal. The original commit was there to remove a deprecation warning. We still have no feedback from porpaginas project. I believe that porpaginas will be updated once PHP effectively introduces the breaking change on the interface.
1 parent 511941c commit 9304078

File tree

9 files changed

+51
-111
lines changed

9 files changed

+51
-111
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"doctrine/dbal": "^3.6",
2525
"psr/log": "^1 || ^2 || ^3",
2626
"doctrine/inflector": "^1.4.3 || ^2",
27+
"beberlei/porpaginas": "~1.0",
2728
"mouf/classname-mapper": "~1.0",
2829
"doctrine/cache": "^1.6",
2930
"greenlion/php-sql-parser": "^4.3.0",

src/AlterableResultIterator.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
namespace TheCodingMachine\TDBM;
66

7+
use Porpaginas\Arrays\ArrayPage;
8+
use Porpaginas\Iterator;
9+
use Porpaginas\Result;
10+
711
/**
812
* This class acts as a wrapper around a result iterator.
913
* It can be used to add or remove results from a ResultIterator (or any kind a traversable collection).
1014
*
1115
* Note: in the case of TDBM, this is useful to manage many to one relationships
1216
*/
13-
class AlterableResultIterator implements ResultInterface, \ArrayAccess, \JsonSerializable
17+
class AlterableResultIterator implements Result, \ArrayAccess, \JsonSerializable
1418
{
1519
/**
1620
* @var \Traversable|null
@@ -198,10 +202,16 @@ public function offsetUnset($offset): void
198202
throw new TDBMInvalidOperationException('You can unset values in a TDBM result set, even in an alterable one. Use the delete method instead.');
199203
}
200204

201-
public function take(int $offset, int $limit): PageInterface
205+
/**
206+
* @param int $offset
207+
* @param int $limit
208+
*
209+
* @return \Porpaginas\Page
210+
*/
211+
public function take($offset, $limit)
202212
{
203213
// TODO: replace this with a class implementing the map method.
204-
return new PageArray(array_slice($this->toArray(), $offset, $limit), $offset, $limit, count($this->toArray()));
214+
return new ArrayPage(array_slice($this->toArray(), $offset, $limit), $offset, $limit, count($this->toArray()));
205215
}
206216

207217
/**

src/PageArray.php

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/PageInterface.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/PageIterator.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Statement;
88
use Mouf\Database\MagicQuery;
9+
use Porpaginas\Page;
910
use Psr\Log\LoggerInterface;
1011
use Psr\Log\NullLogger;
1112

@@ -30,7 +31,7 @@
3031
/**
3132
* Iterator used to retrieve results.
3233
*/
33-
class PageIterator implements PageInterface, \ArrayAccess, \JsonSerializable
34+
class PageIterator implements Page, \ArrayAccess, \JsonSerializable
3435
{
3536
/** @var Statement */
3637
protected $statement;
@@ -132,33 +133,46 @@ public function getIterator(): \Traversable
132133
return $this->innerResultIterator;
133134
}
134135

135-
public function getCurrentOffset(): int
136+
/**
137+
* @return int
138+
*/
139+
public function getCurrentOffset()
136140
{
137141
return $this->offset;
138142
}
139143

140-
public function getCurrentPage(): int
144+
/**
145+
* @return int
146+
*/
147+
public function getCurrentPage()
141148
{
142149
return (int) floor($this->offset / $this->limit) + 1;
143150
}
144151

145-
public function getCurrentLimit(): int
152+
/**
153+
* @return int
154+
*/
155+
public function getCurrentLimit()
146156
{
147157
return $this->limit;
148158
}
149159

150160
/**
151161
* Return the number of results on the current page of the {@link Result}.
162+
*
163+
* @return int
152164
*/
153-
public function count(): int
165+
public function count()
154166
{
155167
return $this->getIterator()->count();
156168
}
157169

158170
/**
159171
* Return the number of ALL results in the paginatable of {@link Result}.
172+
*
173+
* @return int
160174
*/
161-
public function totalCount(): int
175+
public function totalCount()
162176
{
163177
return $this->parentResult->count();
164178
}

src/ResultInterface.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/ResultIterator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Doctrine\DBAL\Statement;
1111
use Mouf\Database\MagicQuery;
1212
use TheCodingMachine\TDBM\QueryFactory\QueryFactory;
13+
use Porpaginas\Result;
1314
use Psr\Log\LoggerInterface;
1415
use TheCodingMachine\TDBM\Utils\DbalUtils;
1516
use Traversable;
@@ -40,7 +41,7 @@
4041
/**
4142
* Iterator used to retrieve results.
4243
*/
43-
class ResultIterator implements ResultInterface, \ArrayAccess, \JsonSerializable
44+
class ResultIterator implements Result, \ArrayAccess, \JsonSerializable
4445
{
4546
/** @var Statement */
4647
protected $statement;
@@ -175,7 +176,13 @@ public function getIterator(): \Traversable
175176
return $this->innerResultIterator;
176177
}
177178

178-
public function take(int $offset, int $limit): PageIterator
179+
/**
180+
* @param int $offset
181+
* @param int $limit
182+
*
183+
* @return PageIterator
184+
*/
185+
public function take($offset, $limit)
179186
{
180187
if ($this->totalCount === 0) {
181188
return PageIterator::createEmpyIterator($this);

tests/Dao/TestCountryDao.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace TheCodingMachine\TDBM\Dao;
66

7-
use TheCodingMachine\TDBM\ResultInterface;
7+
use Porpaginas\Result;
88
use TheCodingMachine\TDBM\Test\Dao\Bean\CountryBean;
99
use TheCodingMachine\TDBM\Test\Dao\Generated\CountryBaseDao;
1010

@@ -14,7 +14,7 @@
1414
class TestCountryDao extends CountryBaseDao
1515
{
1616
/**
17-
* @return CountryBean[]|ResultInterface
17+
* @return CountryBean[]|Result
1818
*/
1919
public function getCountriesByUserCount()
2020
{
@@ -30,7 +30,7 @@ public function getCountriesByUserCount()
3030
}
3131

3232
/**
33-
* @return CountryBean[]|ResultInterface
33+
* @return CountryBean[]|Result
3434
*/
3535
public function getCountriesUsingUnion()
3636
{
@@ -48,7 +48,7 @@ public function getCountriesUsingUnion()
4848
}
4949

5050
/**
51-
* @return CountryBean[]|ResultInterface
51+
* @return CountryBean[]|Result
5252
*/
5353
public function getCountriesUsingSimpleQuery()
5454
{
@@ -62,7 +62,7 @@ public function getCountriesUsingSimpleQuery()
6262
}
6363

6464
/**
65-
* @return CountryBean[]|ResultInterface
65+
* @return CountryBean[]|Result
6666
*/
6767
public function getCountriesUsingDistinctQuery()
6868
{

tests/TDBMServiceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function testRawSqlFilterCountriesByUserCount(): void
248248
GROUP BY country.id
249249
HAVING COUNT(users.id) > 1;
250250
SQL;
251-
/** @var Test\Dao\Bean\CountryBean[]|ResultInterface $beans */
251+
/** @var Test\Dao\Bean\CountryBean[]|\Porpaginas\Result $beans */
252252
$beans = $this->tdbmService->findObjectsFromRawSql('country', $sql, [], null, Test\Dao\Bean\CountryBean::class, null, CountryResultIterator::class);
253253

254254
$count = 0;
@@ -271,7 +271,7 @@ public function testRawSqlOrderCountriesByUserCount(): void
271271
ORDER BY COUNT(users.id);
272272
SQL;
273273

274-
/** @var Test\Dao\Bean\CountryBean[]|ResultInterface $beans */
274+
/** @var Test\Dao\Bean\CountryBean[]|\Porpaginas\Result $beans */
275275
$beans = $this->tdbmService->findObjectsFromRawSql('country', $sql, [], null, Test\Dao\Bean\CountryBean::class, null, CountryResultIterator::class);
276276

277277
$count = 0;
@@ -300,7 +300,7 @@ public function testRawSqlOrderUsersByCustomRoleOrder(): void
300300
ORDER BY MAX(IF(roles.name = 'Admins', 3, IF(roles.name = 'Writers', 2, IF(roles.name = 'Singers', 1, 0)))) DESC
301301
SQL;
302302

303-
/** @var Test\Dao\Bean\UserBean[]|ResultInterface $beans */
303+
/** @var Test\Dao\Bean\UserBean[]|\Porpaginas\Result $beans */
304304
$beans = $this->tdbmService->findObjectsFromRawSql('contact', $sql, [], null, Test\Dao\Bean\UserBean::class, null, UserResultIterator::class);
305305

306306
function getCustomOrder(Test\Dao\Bean\UserBean $contact)

0 commit comments

Comments
 (0)