1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Resta\Container;
|
4
|
|
|
|
5
|
|
|
use Resta\Support\Utils;
|
6
|
|
|
use Resta\Foundation\ApplicationProvider;
|
7
|
|
|
|
8
|
|
|
class ContainerMethodDocumentResolver extends ApplicationProvider
|
9
|
|
|
{
|
10
|
|
|
/**
|
11
|
|
|
* @var null|object
|
12
|
|
|
*/
|
13
|
|
|
protected $reflection;
|
14
|
|
|
|
15
|
|
|
/**
|
16
|
|
|
* @var array
|
17
|
|
|
*/
|
18
|
|
|
protected $class;
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* ContainerMethodDocumentResolver constructor.
|
22
|
|
|
*
|
23
|
|
|
* @param $app
|
24
|
|
|
* @param $reflection
|
25
|
|
|
* @param array $class
|
26
|
|
|
*/
|
27
|
|
|
public function __construct($app,$reflection,$class=array())
|
28
|
|
|
{
|
29
|
|
|
parent::__construct($app);
|
30
|
|
|
|
31
|
|
|
$this->reflection = $reflection;
|
32
|
|
|
$this->class = $class;
|
33
|
|
|
|
34
|
|
|
// for class method,
|
35
|
|
|
// if there is cache in document data, it will be saved in container.
|
36
|
|
|
$this->isCacheMethod();
|
37
|
|
|
}
|
38
|
|
|
|
39
|
|
|
/**
|
40
|
|
|
* detect document cache for class method
|
41
|
|
|
*
|
42
|
|
|
* @return void|mixed
|
43
|
|
|
*/
|
44
|
|
|
private function isCacheMethod()
|
45
|
|
|
{
|
46
|
|
|
$cacheData = [];
|
47
|
|
|
|
48
|
|
|
if(!isset($this->class[1]) && !is_object($this->class[0])) return;
|
49
|
|
|
|
50
|
|
|
// if you have information about cache in
|
51
|
|
|
// the document section of the method, the cache process is executed.
|
52
|
|
|
if($this->reflection->isAvailableMethodDocument($this->class[1],'cache')){
|
|
|
|
|
53
|
|
|
|
54
|
|
|
//as static we inject the name value into the cache data.
|
55
|
|
|
$cacheData = ['cache'=>['name' => Utils::encryptArrayData($this->class)]];
|
56
|
|
|
|
57
|
|
|
//cache data with the help of foreach data are transferred into the cache.
|
58
|
|
|
foreach(array_filter(explode(" ",$this->reflection->getDocumentData()),'strlen') as $item){
|
59
|
|
|
|
60
|
|
|
$items = explode("=",$item);
|
61
|
|
|
|
62
|
|
|
$cacheData['cache'][$items[0]] = $items[1];
|
63
|
|
|
|
64
|
|
|
if(in_array('query',$items)){
|
65
|
|
|
$query = get($items[1],null);
|
|
|
|
|
66
|
|
|
if(!is_null($query)){
|
67
|
|
|
$cacheData['cache']['name'] = md5(sha1(
|
68
|
|
|
$cacheData['cache']['name'].'_'.$items[1].':'.$query
|
69
|
|
|
));
|
70
|
|
|
}
|
71
|
|
|
}
|
72
|
|
|
}
|
73
|
|
|
}
|
74
|
|
|
|
75
|
|
|
//we save the data stored in the cacheData variable as methodCache.
|
76
|
|
|
$this->app->register('cache','methodCache',$cacheData);
|
77
|
|
|
$this->app->register('cache','class',$this->class);
|
78
|
|
|
}
|
79
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.