1 | <?php |
||
28 | class Generator |
||
29 | { |
||
30 | /** string All generated view classes will end with this suffix */ |
||
31 | const VIEW_CLASSNAME_SUFFIX = 'View'; |
||
32 | |||
33 | /** @var array Collection of PHP reserved words */ |
||
34 | protected static $reservedWords = array( |
||
35 | 'list' |
||
36 | ); |
||
37 | |||
38 | /** @var Metadata[] Collection of view metadata */ |
||
39 | protected $metadata = array(); |
||
40 | |||
41 | /** @var \samsonphp\generator\Generator */ |
||
42 | protected $generator; |
||
43 | |||
44 | /** @var string Generated classes namespace prefix */ |
||
45 | protected $namespacePrefix; |
||
46 | |||
47 | /** |
||
48 | * Generator constructor. |
||
49 | * |
||
50 | * @param \samsonphp\generator\Generator $generator |
||
51 | * @param string $namespacePrefix |
||
52 | */ |
||
53 | 2 | public function __construct(\samsonphp\generator\Generator $generator, $namespacePrefix) |
|
58 | |||
59 | /** |
||
60 | * Recursively scan path for files with specified extensions. |
||
61 | * |
||
62 | * @param string $source Entry point path |
||
63 | * @param string $path Entry path for scanning |
||
64 | * @param array $extensions Collection of file extensions without dot |
||
65 | */ |
||
66 | 2 | public function scan($source, array $extensions = array(View::DEFAULT_EXT), $path = null) |
|
67 | { |
||
68 | 2 | $path = isset($path) ? $path : $source; |
|
69 | |||
70 | // Recursively go deeper into inner folders for scanning |
||
71 | 2 | $folders = glob($path.'/*', GLOB_ONLYDIR); |
|
72 | 2 | foreach ($folders as $folder) { |
|
73 | 2 | $this->scan($source, $extensions, $folder); |
|
74 | 2 | } |
|
75 | |||
76 | // Iterate file extensions |
||
77 | 2 | foreach ($extensions as $extension) { |
|
78 | 2 | foreach (glob(rtrim($path, '/') . '/*.'.$extension) as $file) { |
|
79 | 2 | $this->metadata[$file] = $this->analyze($file); |
|
80 | 2 | $this->metadata[$file]->path = str_replace($source, '', $file); |
|
81 | 1 | list($this->metadata[$file]->className, |
|
82 | 2 | $this->metadata[$file]->namespace) = $this->generateClassName($file, $source); |
|
83 | 2 | } |
|
84 | 2 | } |
|
85 | 2 | } |
|
86 | |||
87 | /** |
||
88 | * Analyze view file and create its metadata. |
||
89 | * |
||
90 | * @param string $file Path to view file |
||
91 | * |
||
92 | * @return Metadata View file metadata |
||
93 | */ |
||
94 | 2 | public function analyze($file) |
|
117 | |||
118 | /** |
||
119 | * Generic class name and its name space generator. |
||
120 | * |
||
121 | * @param string $file Full path to view file |
||
122 | * @param string $entryPath Entry path |
||
123 | * |
||
124 | * @return array Class name[0] and namespace[1] |
||
125 | * @throws GeneratedViewPathHasReservedWord |
||
126 | */ |
||
127 | 2 | protected function generateClassName($file, $entryPath) |
|
152 | |||
153 | 1 | public function generate($path = __DIR__) |
|
159 | |||
160 | 1 | protected function generateViewClass(Metadata $metadata, $path) |
|
184 | |||
185 | /** |
||
186 | * Generate constructor for application class. |
||
187 | * |
||
188 | * @param string $variable View variable name |
||
189 | * |
||
190 | * @return string View variable setter method |
||
191 | */ |
||
192 | 1 | protected function generateViewVariableSetter($variable) |
|
207 | } |
||
208 |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.