forked from gardenofconcepts/GOCPaginationBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactory.php
30 lines (24 loc) · 829 Bytes
/
Factory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
namespace GOC\PaginationBundle;
use Symfony\Component\DependencyInjection\Container;
class Factory
{
private $container, $class, $classOdm;
public function __construct(Container $container, $class, $classOdm)
{
$this->container = $container;
$this->class = $class;
$this->classOdm = $classOdm;
}
public function create($query, $items = 50, $page = null)
{
if ($page == null) {
$page = $this->container->get('request')->attributes->get('page')-1;
if ($page < 0) {
throw Exception::unknownPageNumber();
}
}
$class = $query instanceof \Doctrine\ODM\MongoDB\Query\Builder ? $this->classOdm : $this->class;
return new $class($this->container, $query, (int)$items, (int)$page);
}
}