|
1
|
|
|
<?php |
|
2
|
|
|
//[PHPCOMPRESSOR(remove,start)] |
|
3
|
|
|
/** |
|
4
|
|
|
* Created by Vitaly Iegorov <[email protected]>. |
|
5
|
|
|
* on 22.03.16 at 15:46 |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace samsoncms\api\generator; |
|
8
|
|
|
|
|
9
|
|
|
use samsoncms\api\generator\metadata\GenericMetadata; |
|
10
|
|
|
use samsoncms\api\generator\metadata\Virtual; |
|
11
|
|
|
use samsonphp\generator\Generator; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Table trait class generator. As all entities should |
|
15
|
|
|
* be able to create Table class instances for their selves |
|
16
|
|
|
* this class is a trait with methods to receive all available virtual |
|
17
|
|
|
* entity tables. |
|
18
|
|
|
* |
|
19
|
|
|
* @package samsoncms\api\generator |
|
20
|
|
|
*/ |
|
21
|
|
|
class TableTrait extends Generic |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Query constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param Generator $generator |
|
27
|
|
|
* @param $metadata |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(Generator $generator, $metadata) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct($generator, $metadata); |
|
32
|
|
|
|
|
33
|
|
|
$this->className = 'TableTrait'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Class uses generation part. |
|
38
|
|
|
* |
|
39
|
|
|
* @param Virtual $metadata Entity metadata |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function createUses($metadata) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->generator |
|
44
|
|
|
->newLine('use samsonframework\core\ViewInterface;') |
|
45
|
|
|
->newLine(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Class definition generation part. |
|
50
|
|
|
* |
|
51
|
|
|
* @param Virtual $metadata Entity metadata |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function createDefinition($metadata) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->generator |
|
|
|
|
|
|
56
|
|
|
->multiComment(array('"TableTrait database entity class')) |
|
57
|
|
|
->defTrait($this->className); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Class methods generation part. |
|
62
|
|
|
* |
|
63
|
|
|
* @param Virtual $metadata Entity metadata |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function createMethods($metadata) |
|
66
|
|
|
{ |
|
67
|
|
|
$methods = []; |
|
68
|
|
|
/** @var Virtual $metadataInstance Iterate all metadata entities */ |
|
69
|
|
|
foreach (GenericMetadata::$instances as $metadataInstance) { |
|
70
|
|
|
if ($metadataInstance->type === Virtual::TYPE_TABLE) { |
|
71
|
|
|
// Create table virtual entity with correct name ending |
|
72
|
|
|
$tableEntity = rtrim($metadataInstance->entity, 'Table') . 'Table'; |
|
73
|
|
|
|
|
74
|
|
|
$code = "\n\t" . '/**'; |
|
75
|
|
|
$code .= "\n\t" . ' * Create virtual ' . $metadataInstance->entityRealName . ' table instance.'; |
|
76
|
|
|
$code .= "\n\t" . ' * @param ViewInterface $renderer Renderer instance'; |
|
77
|
|
|
$code .= "\n\t" . ' *'; |
|
78
|
|
|
$code .= "\n\t" . ' * @return $this Chaining'; |
|
79
|
|
|
$code .= "\n\t" . ' */'; |
|
80
|
|
|
$code .= "\n\t" . 'public function ' . lcfirst($tableEntity) . '(ViewInterface $renderer)'; |
|
81
|
|
|
$code .= "\n\t" . '{'; |
|
82
|
|
|
$code .= "\n\t\t" . 'return new ' . $tableEntity . '($renderer, $this->id);'; |
|
83
|
|
|
$code .= "\n\t" . '}'; |
|
84
|
|
|
|
|
85
|
|
|
$methods[] = $code; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
// Add method text to generator |
|
90
|
|
|
$this->generator->text(implode("\n", $methods)); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
//[PHPCOMPRESSOR(remove,end)] |
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.