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
|
|
|
use Grido\Exception; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Model of data source. |
18
|
|
|
* |
19
|
|
|
* @package Grido |
20
|
|
|
* @subpackage DataSources |
21
|
|
|
* @author Petr Bugyík |
22
|
|
|
* |
23
|
|
|
* @property-read IDataSource $dataSource |
24
|
|
|
*/ |
25
|
|
|
class Model |
26
|
1 |
|
{ |
27
|
|
|
use \Nette\SmartObject; |
28
|
|
|
|
29
|
|
|
/** @var array */ |
30
|
|
|
public $callback = []; |
31
|
|
|
|
32
|
|
|
/** @var IDataSource */ |
33
|
|
|
protected $dataSource; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param mixed $model |
37
|
|
|
* @throws Exception |
38
|
|
|
*/ |
39
|
1 |
|
public function __construct($model) |
40
|
1 |
|
{ |
41
|
1 |
|
if ($model instanceof \Dibi\Fluent) { |
|
|
|
|
42
|
1 |
|
$dataSource = new DibiFluent($model); |
43
|
1 |
|
} elseif ($model instanceof \Nette\Database\Table\Selection) { |
|
|
|
|
44
|
1 |
|
$dataSource = new NetteDatabase($model); |
45
|
1 |
|
} elseif ($model instanceof \Doctrine\ORM\QueryBuilder) { |
|
|
|
|
46
|
1 |
|
$dataSource = new Doctrine($model); |
47
|
1 |
|
} elseif (is_array($model)) { |
48
|
1 |
|
$dataSource = new ArraySource($model); |
49
|
1 |
|
} elseif ($model instanceof IDataSource) { |
50
|
1 |
|
$dataSource = $model; |
51
|
|
|
} else { |
52
|
|
|
throw new Exception('Model must implement \Grido\DataSources\IDataSource.'); |
53
|
1 |
|
} |
54
|
1 |
|
|
55
|
|
|
$this->dataSource = $dataSource; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return IDataSource |
60
|
|
|
*/ |
61
|
1 |
|
public function getDataSource() |
62
|
|
|
{ |
63
|
|
|
return $this->dataSource; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function __call($method, $args) |
67
|
1 |
|
{ |
68
|
1 |
|
return isset($this->callback[$method]) |
69
|
|
|
? call_user_func_array($this->callback[$method], [$this->dataSource, $args]) |
70
|
|
|
: call_user_func_array([$this->dataSource, $method], $args); |
71
|
1 |
|
} |
72
|
|
|
} |
73
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.