Grido@master
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Grido
    • Components
      • Actions
      • Columns
      • Filters
    • DataSources
    • PropertyAccessors
    • Translations

Classes

  • Grido\Translations\FileTranslator
 1 <?php
 2 
 3 /**
 4  * This file is part of the Grido (https://github.com/o5/grido)
 5  *
 6  * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
 7  *
 8  * For the full copyright and license information, please view
 9  * the file LICENSE.md that was distributed with this source code.
10  */
11 
12 namespace Grido\DataSources;
13 
14 /**
15  * Model of data source.
16  *
17  * @package     Grido
18  * @subpackage  DataSources
19  * @author      Petr Bugyík
20  *
21  * @property-read IDataSource $dataSource
22  */
23 class Model extends \Nette\Object
24 {
25     /** @var array */
26     public $callback = array();
27 
28     /** @var IDataSource */
29     protected $dataSource;
30 
31     /**
32      * @param mixed $model
33      * @throws \InvalidArgumentException
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      * @return \IDataSource
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 
Grido@master API documentation generated by ApiGen