1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Grido\DataSources;
13
14 15 16 17 18 19 20 21 22
23 class Model extends \Nette\Object
24 {
25
26 public $callback = array();
27
28
29 protected $dataSource;
30
31 32 33 34
35 public function __construct($model)
36 {
37 if ($model instanceof \DibiFluent) {
38 $dataSource = new DibiFluent($model);
39 } elseif ($model instanceof \Nette\Database\Table\Selection) {
40 $dataSource = new NetteDatabase($model);
41 } elseif ($model instanceof \Doctrine\ORM\QueryBuilder) {
42 $dataSource = new Doctrine($model);
43 } elseif (is_array($model)) {
44 $dataSource = new ArraySource($model);
45 } elseif ($model instanceof IDataSource) {
46 $dataSource = $model;
47 } else {
48 throw new \InvalidArgumentException('Model must implement \Grido\DataSources\IDataSource.');
49 }
50
51 $this->dataSource = $dataSource;
52 }
53
54 55 56
57 public function getDataSource()
58 {
59 return $this->dataSource;
60 }
61
62 public function __call($method, $args)
63 {
64 return isset($this->callback[$method])
65 ? callback($this->callback[$method])->invokeArgs(array($this->dataSource, $args))
66 : call_user_func_array(array($this->dataSource, $method), $args);
67 }
68 }
69