-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.php
68 lines (60 loc) · 1.79 KB
/
Model.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* This file is part of the Grido (http://grido.bugyik.cz)
*
* Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
*
* For the full copyright and license information, please view
* the file LICENSE.md that was distributed with this source code.
*/
namespace Grido\DataSources;
/**
* Model of data source.
*
* @package Grido
* @subpackage DataSources
* @author Petr Bugyík
*
* @property-read IDataSource $dataSource
*/
class Model extends \Nette\Object
{
/** @var array */
public $callback = array();
/** @var IDataSource */
protected $dataSource;
/**
* @param mixed $model
* @throws \InvalidArgumentException
*/
public function __construct($model)
{
if ($model instanceof \DibiFluent) {
$dataSource = new DibiFluent($model);
} elseif ($model instanceof \Nette\Database\Table\Selection) {
$dataSource = new NetteDatabase($model);
} elseif ($model instanceof \Doctrine\ORM\QueryBuilder) {
$dataSource = new Doctrine($model);
} elseif (is_array($model)) {
$dataSource = new ArraySource($model);
} elseif ($model instanceof IDataSource) {
$dataSource = $model;
} else {
throw new \InvalidArgumentException('Model must implement \Grido\DataSources\IDataSource.');
}
$this->dataSource = $dataSource;
}
/**
* @return \IDataSource
*/
public function getDataSource()
{
return $this->dataSource;
}
public function __call($method, $args)
{
return isset($this->callback[$method])
? callback($this->callback[$method])->invokeArgs(array($this->dataSource, $args))
: call_user_func_array(array($this->dataSource, $method), $args);
}
}