1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Vitaly Iegorov <[email protected]>. |
4
|
|
|
* on 21.02.16 at 14:14 |
5
|
|
|
*/ |
6
|
|
|
namespace samsonphp\view; |
7
|
|
|
|
8
|
|
|
use samsonframework\core\ResourcesInterface; |
9
|
|
|
use samsonframework\core\SystemInterface; |
10
|
|
|
use samsonframework\view\Generator; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* SamsonPHP view module |
14
|
|
|
* @package samsonphp\view |
15
|
|
|
*/ |
16
|
|
|
class Module extends \samson\core\ExternalModule |
17
|
|
|
{ |
18
|
|
|
/** @var Generator */ |
19
|
|
|
protected $generator; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Module constructor. |
23
|
|
|
* |
24
|
|
|
* @param string $path |
25
|
|
|
* @param ResourcesInterface $resources |
26
|
|
|
* @param SystemInterface $system |
27
|
|
|
* @param Generator $generator |
28
|
|
|
*/ |
29
|
|
|
public function __construct($path, ResourcesInterface $resources, SystemInterface $system, Generator $generator = null) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($path, $resources, $system); |
32
|
|
|
|
33
|
|
|
$this->generator = isset($generator) |
34
|
|
|
? $generator |
35
|
|
|
: new Generator(new \samsonphp\generator\Generator(), 'view', array('\www', '\view')); |
|
|
|
|
36
|
|
|
|
37
|
|
|
// Register View class file autoloader |
38
|
|
|
spl_autoload_register(array($this, 'autoload')); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Help autoloading view classes as we know where we store them. |
43
|
|
|
* |
44
|
|
|
* @param string $class View class name for searching |
45
|
|
|
*/ |
46
|
|
|
public function autoload($class) |
47
|
|
|
{ |
48
|
|
|
$classPath = $this->cache_path.str_replace('\\', '/', $class).'.php'; |
49
|
|
|
if (file_exists($classPath)) { |
50
|
|
|
require_once($classPath); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Module preparation stage. |
56
|
|
|
* This function called after module instance creation but before |
57
|
|
|
* initialization stage. |
58
|
|
|
* |
59
|
|
|
* @param array $params Preparation stage parameters |
60
|
|
|
* |
61
|
|
|
* @return bool|void Preparation stage result |
62
|
|
|
*/ |
63
|
|
|
public function prepare(array $params = array()) |
64
|
|
|
{ |
65
|
|
|
$signature = $this->generator->hash(); |
|
|
|
|
66
|
|
|
if ($this->cache_refresh($signature)) { |
67
|
|
|
$this->generator->scan(__SAMSON_CWD__.'/src'); |
|
|
|
|
68
|
|
|
$this->generator->generate($this->cache_path); |
|
|
|
|
69
|
|
|
// Store cache file |
70
|
|
|
file_put_contents($signature, ''); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return parent::prepare($params); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.