Skip to content

Commit 4f06da9

Browse files
committed
closes #130
1 parent 5590ed2 commit 4f06da9

13 files changed

+592
-369
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55

66
- **New:** Add `tck-devtools:finder-class-properties` command to apply class properties to type hint relations in finder (#126)
77
- **New:** Add `tck-devtools:generate-schema-addon` command to generate schema for every entity at once (#128)
8+
- **New:** Generate code event listener code using code generator (#130)
89
- **Fix:** Permission interface groups are not sorted correctly when building readme (#125)
910

1011
## 1.4.3 (`1040370`)

Cli/Command/EntityClassProperties.php

+33
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,39 @@ protected function getListTypeMap() : array
437437
];
438438
}
439439

440+
protected function getAllClassesExtendingClass(
441+
string $addOnId,
442+
?array $requireAddOnIds,
443+
?array $softRequireAddOnIds,
444+
string $class
445+
) : array
446+
{
447+
$addOnIds = [$addOnId];
448+
$classes = [$class];
449+
450+
if (is_array($requireAddOnIds))
451+
{
452+
array_push($addOnIds, ...$requireAddOnIds);
453+
}
454+
455+
if (is_array($softRequireAddOnIds))
456+
{
457+
array_push($addOnIds, ...$softRequireAddOnIds);
458+
}
459+
460+
/** @var AbstractCollection|ClassExtensionEntity[] $classExtensions */
461+
$classExtensions = $this->getClassExtensionRepo()->findExtensionsForList()
462+
->where('from_class', '=', $class)
463+
->where('addon_id', '=', $addOnIds)
464+
->fetch();
465+
foreach ($classExtensions AS $classExtension)
466+
{
467+
$classes[] = $classExtension->to_class;
468+
}
469+
470+
return array_unique($classes);
471+
}
472+
440473
/**
441474
* @return Repository|ClassExtensionRepo
442475
*/

LICENSE-NettePhpGenerator.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
New BSD License
2+
---------------
3+
4+
Copyright (c) 2004, 2014 David Grudl (https://davidgrudl.com)
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
* Neither the name of "Nette Framework" nor the names of its contributors
18+
may be used to endorse or promote products derived from this software
19+
without specific prior written permission.
20+
21+
This software is provided by the copyright holders and contributors "as is" and
22+
any express or implied warranties, including, but not limited to, the implied
23+
warranties of merchantability and fitness for a particular purpose are
24+
disclaimed. In no event shall the copyright owner or contributors be liable for
25+
any direct, indirect, incidental, special, exemplary, or consequential damages
26+
(including, but not limited to, procurement of substitute goods or services;
27+
loss of use, data, or profits; or business interruption) however caused and on
28+
any theory of liability, whether in contract, strict liability, or tort
29+
(including negligence or otherwise) arising in any way out of the use of this
30+
software, even if advised of the possibility of such damage.

Listener.php

+44-46
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,46 @@
66
use XF\App as BaseApp;
77
use XF\Http\Response;
88
use XF\Mvc\Dispatcher;
9-
use XF\Mvc\Reply\AbstractReply;
109
use XF\Mvc\Renderer\AbstractRenderer;
10+
use XF\Mvc\Reply\AbstractReply;
1111
use XF\PermissionCache;
1212
use XF\Util\File as FileUtil;
13-
14-
use function count, is_string;
13+
use function count;
14+
use function is_string;
1515

1616
/**
1717
* Class Listener
18-
*
18+
*
1919
* This class declares code event listeners for the add-on.
20-
*
20+
*
2121
* @package TickTackk\DeveloperTools
2222
*/
2323
class Listener
2424
{
25-
/**
26-
* @param Dispatcher $dispatcher Dispatcher object
27-
* @param string|null $content The rendered content.
28-
* @param AbstractReply $reply Reply object.
29-
* @param AbstractRenderer $renderer Renderer object.
30-
* @param Response $response HTTP Response object.
31-
*/
32-
public static function dispatcherPostRender
33-
(
34-
/** @noinspection PhpUnusedParameterInspection */
35-
Dispatcher $dispatcher,
36-
?string &$content,
37-
AbstractReply $reply,
38-
AbstractRenderer $renderer,
39-
Response $response
40-
) : void
41-
{
42-
if (!is_string($content))
43-
{
44-
return;
45-
}
25+
/**
26+
* @param Dispatcher $dispatcher Dispatcher object
27+
* @param string|null $content The rendered content.
28+
* @param AbstractReply $reply Reply object.
29+
* @param AbstractRenderer $renderer Renderer object.
30+
* @param Response $response HTTP Response object.
31+
*/
32+
public static function dispatcherPostRender(
33+
Dispatcher $dispatcher,
34+
?string &$content,
35+
AbstractReply $reply,
36+
AbstractRenderer $renderer,
37+
Response $response
38+
): void {
39+
if (!is_string($content))
40+
{
41+
return;
42+
}
4643

47-
/** @var ExtendedTemplater $templater */
48-
$templater = $renderer->getTemplater();
49-
if (\is_callable([$templater, 'getPermissionErrors']))
50-
{
51-
$permissionErrors = $templater->getPermissionErrors();
44+
/** @var ExtendedTemplater $templater */
45+
$templater = $renderer->getTemplater();
46+
if (\is_callable([$templater, 'getPermissionErrors']))
47+
{
48+
$permissionErrors = $templater->getPermissionErrors();
5249

5350
if (count($permissionErrors))
5451
{
@@ -75,19 +72,20 @@ public static function dispatcherPostRender
7572
}
7673
}
7774

78-
/**
79-
* Called after the global \XF\App object has been setup. This will fire regardless of
80-
* the application type.
81-
*
82-
* @param BaseApp $app Global App object.
83-
*/
84-
public static function appSetup(BaseApp $app) : void
85-
{
86-
$app->offsetSet('permission.cache', function ($c) use ($app)
87-
{
88-
$class = $app->extendClass(PermissionCache::class);
8975

90-
return new $class($c['db']);
91-
});
92-
}
93-
}
76+
/**
77+
* Called after the global \XF\App object has been setup. This will fire regardless of
78+
* the application type.
79+
*
80+
* @param BaseApp $app Global App object.
81+
*/
82+
public static function appSetup(BaseApp $app): void
83+
{
84+
$app->offsetSet('permission.cache', function ($c) use ($app)
85+
{
86+
$class = $app->extendClass(PermissionCache::class);
87+
88+
return new $class($c['db']);
89+
});
90+
}
91+
}

Service/CodeEvent/DescriptionParser.php

+37-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TickTackk\DeveloperTools\Service\CodeEvent;
44

55
use Symfony\Component\DomCrawler\Crawler as DOMCrawler;
6+
use XF\AddOn\AddOn;
67
use XF\Entity\CodeEvent as CodeEventEntity;
78
use XF\Service\AbstractService;
89
use XF\App as BaseApp;
@@ -65,7 +66,7 @@ protected function getCodeEventDOMCrawler()
6566
/**
6667
* @return string
6768
*/
68-
protected function parseDescription() : string
69+
protected function parseDescription(AddOn $addOn) : string
6970
{
7071
$codeEventDOMCrawler = $this->getCodeEventDOMCrawler();
7172

@@ -84,7 +85,7 @@ protected function parseDescription() : string
8485
/**
8586
* @return string
8687
*/
87-
protected function parseEventHint() : string
88+
protected function parseEventHint(AddOn $addOn) : string
8889
{
8990
$codeEventDOMCrawler = $this->getCodeEventDOMCrawler();
9091

@@ -105,12 +106,29 @@ protected function parseEventHint() : string
105106
return trim($eventHintNode->nodeValue);
106107
}
107108

108-
/**
109-
* @param string $hint
110-
*
111-
* @return string
112-
*/
113-
protected function getFinalHint(string $hint)
109+
protected function getMinPhpRequire(AddOn $addOn) : string
110+
{
111+
$requirePhpversion = '5.6.0';
112+
$json = $addOn->getJson();
113+
114+
if (isset($json['require']['XF']))
115+
{
116+
$requireXfVersion = $json['require']['XF'];
117+
if ($requireXfVersion[0] >= 2020010)
118+
{
119+
$requirePhpversion = '7.0.0';
120+
}
121+
}
122+
123+
if (isset($json['require']['php']))
124+
{
125+
$requirePhpversion = $json['require']['php'][0];
126+
}
127+
128+
return $requirePhpversion;
129+
}
130+
131+
protected function getFinalHint(string $hint, AddOn $addOn)
114132
{
115133
switch ($hint)
116134
{
@@ -121,7 +139,7 @@ protected function getFinalHint(string $hint)
121139
return 'int';
122140

123141
case '':
124-
return 'mixed';
142+
return '';
125143
}
126144

127145
return $hint;
@@ -130,7 +148,7 @@ protected function getFinalHint(string $hint)
130148
/**
131149
* @return array
132150
*/
133-
protected function parseArguments() : array
151+
protected function parseArguments(AddOn $addOn) : array
134152
{
135153
$codeEventDOMCrawler = $this->getCodeEventDOMCrawler();
136154
$arguments = [];
@@ -182,8 +200,8 @@ protected function parseArguments() : array
182200
}
183201

184202
$arguments[] = [
185-
'hint' => $this->getFinalHint($hintType),
186-
'name' => $name,
203+
'hint' => $this->getFinalHint($hintType, $addOn),
204+
'name' => substr($name, 1), // Removes $
187205
'passedByRef' => $passedByRef,
188206
'description' => ucfirst($description)
189207
];
@@ -193,14 +211,17 @@ protected function parseArguments() : array
193211
}
194212

195213
/**
214+
* @param AddOn $addOn
215+
*
196216
* @return array
197217
*/
198-
public function parse() : array
218+
public function parse(AddOn $addOn) : array
199219
{
200220
return [
201-
'description' => $this->parseDescription(),
202-
'eventHint' => $this->parseEventHint(),
203-
'arguments' => $this->parseArguments()
221+
'description' => $this->parseDescription($addOn),
222+
'eventHint' => $this->parseEventHint($addOn),
223+
'arguments' => $this->parseArguments($addOn),
224+
'returnType' => version_compare($this->getMinPhpRequire($addOn), '7.1.0', '>=') ? 'void' : null
204225
];
205226
}
206227
}

0 commit comments

Comments
 (0)