Skip to content

Commit e92ac62

Browse files
authored
Merge pull request #134 from ticktackk/develop
1.5.0
2 parents 188aeeb + 89d1fa5 commit e92ac62

File tree

58 files changed

+1944
-574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1944
-574
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
CHANGELOG
22
==========================
33

4+
## 1.5.0 (`1050070`)
5+
6+
- **New:** Add `tck-devtools:finder-class-properties` command to apply class properties to type hint relations in finder (#126)
7+
- **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)
9+
- **Change:** Require Standard Library v1.20.1 by @Xon
10+
- **Fix:** Permission interface groups are not sorted correctly when building readme (#125)
11+
- **Fix:** Error: Call to undefined method `XF\Api\Templater::logPermissionError()` (#127)
12+
- **Fix:** Incompatible with XenForo 2.3 (#131)
13+
- **Fix:** Incompatible with XenForo 2.1 (#132)
14+
415
## 1.4.3 (`1040370`)
516

617
- **Fix:** Command `tck-dt:entity-class-properties` does not set getters and relations make use of `@property-read` tag as it should (#122)

Cli/Command/BetterExport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function configure() : void
4949
* @param OutputInterface $output
5050
*
5151
* @return int|null
52-
* @throws \Exception
52+
* @throws \Symfony\Component\Console\Exception\ExceptionInterface
5353
*/
5454
/** @noinspection PhpMissingParentCallCommonInspection */
5555
protected function execute(InputInterface $input, OutputInterface $output) : ?int
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace TickTackk\DeveloperTools\Cli\Command;
4+
5+
use XF\App as BaseApp;
6+
use XF\Entity\ClassExtension as ClassExtensionEntity;
7+
use XF\Mvc\Entity\AbstractCollection;
8+
use XF\Mvc\Entity\Repository;
9+
use XF\Repository\ClassExtension as ClassExtensionRepo;
10+
11+
trait ClassPropertiesCommandTrait
12+
{
13+
/**
14+
* @param string $class
15+
* @param string $addOnId
16+
* @param array|null $requireAddonIds
17+
* @param array|null $softRequireAddonIds
18+
* @param string|null $subClassOf
19+
*
20+
* @return array
21+
*
22+
* @throws \ReflectionException
23+
*/
24+
protected function getTypeHintForClass(
25+
string $class,
26+
string $addOnId,
27+
?array $requireAddonIds,
28+
?array $softRequireAddonIds,
29+
?string $subClassOf = null
30+
) : array
31+
{
32+
$classReflection = new \ReflectionClass($class);
33+
if (!$classReflection->isInstantiable())
34+
{
35+
return [];
36+
}
37+
38+
$classes = [];
39+
if (is_string($subClassOf))
40+
{
41+
$classes[] = "\\$subClassOf";
42+
43+
if (!$classReflection->isSubclassOf($subClassOf))
44+
{
45+
return $classes;
46+
}
47+
48+
$classes[] = "\\$class";
49+
}
50+
51+
$addOnIds = [$addOnId];
52+
53+
if (is_array($requireAddonIds))
54+
{
55+
array_push($addOnIds, $requireAddonIds);
56+
}
57+
58+
if (is_array($softRequireAddonIds))
59+
{
60+
array_push($addOnIds, $softRequireAddonIds);
61+
}
62+
63+
/** @var AbstractCollection|ClassExtensionEntity[] $classExtensions */
64+
$classExtensions = $this->getClassExtensionRepo()->findExtensionsForList()
65+
->where('from_class', '=', $class)
66+
->where('addon_id', '=', $addOnIds)
67+
->fetch();
68+
69+
foreach ($classExtensions AS $classExtension)
70+
{
71+
$classes[] = $classExtension->to_class;
72+
}
73+
74+
return array_unique($classes);
75+
}
76+
77+
protected function app() : BaseApp
78+
{
79+
return \XF::app();
80+
}
81+
82+
protected function repository(string $class) : Repository
83+
{
84+
return $this->app()->repository($class);
85+
}
86+
87+
/**
88+
* @return Repository|ClassExtensionRepo
89+
*/
90+
protected function getClassExtensionRepo() : ClassExtensionRepo
91+
{
92+
return $this->repository('XF:ClassExtension');
93+
}
94+
}

Cli/Command/EntityClassProperties.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use XF\Mvc\Entity\AbstractCollection;
1111
use XF\Mvc\Entity\Entity;
1212
use XF\Cli\Command\Development\RequiresDevModeTrait;
13-
use XF\Mvc\Entity\Finder;
1413
use XF\Mvc\Entity\Repository;
1514
use XF\Util\File as FileUtil;
1615
use XF\Util\Php as PhpUtil;
@@ -26,7 +25,7 @@
2625
*/
2726
class EntityClassProperties extends Command
2827
{
29-
use RequiresDevModeTrait;
28+
use RequiresDevModeTrait, ClassPropertiesCommandTrait;
3029

3130
protected function configure() : void
3231
{
@@ -117,13 +116,13 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
117116
}
118117

119118
$requireAddOnIds = null;
120-
$requireSoftAddOnIds = null;
119+
$softRequireAddOnIds = null;
121120
if (is_array($addOnJson))
122121
{
123122
$requireAddOnIds = array_keys($addOnJson['require']);
124123
if (isset($addOnJson['require-soft']))
125124
{
126-
$requireSoftAddOnIds = array_keys($addOnJson['require-require']);
125+
$softRequireAddOnIds = array_keys($addOnJson['require-require']);
127126
}
128127
}
129128

@@ -186,6 +185,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
186185
}
187186
else if ($returnType)
188187
{
188+
/** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */
189189
if ($returnType instanceof \ReflectionUnionType)
190190
{
191191
$returnTypes = $returnType->getTypes();
@@ -251,9 +251,15 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
251251
$typePart = substr($typePart, 0, strlen($typePart) - 2);
252252
}
253253

254-
foreach ($this->getAllClassesExtendingClass($addOnId, $requireAddOnIds, $requireSoftAddOnIds, $typePart) AS $class)
254+
$typeHintClasses = $this->getTypeHintForClass(
255+
$typePart,
256+
$addOnId,
257+
$requireAddOnIds,
258+
$softRequireAddOnIds
259+
);
260+
foreach ($typeHintClasses AS $typeHintClass)
255261
{
256-
$newType[] = '\\' . $class . ($isMulti ? '[]' : '');
262+
$newType[] = '\\' . $typeHintClass . ($isMulti ? '[]' : '');
257263
}
258264
}
259265
$newType = array_unique($newType);
@@ -307,12 +313,11 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
307313
$relation .= '_';
308314
}
309315

310-
$relationEntityClass = \XF::stringToClass($def['entity'], '%s\Entity\%s');
311-
$relationEntityClasses = $this->getAllClassesExtendingClass(
316+
$relationEntityClasses = $this->getTypeHintForClass(
317+
\XF::stringToClass($def['entity'], '%s\Entity\%s'),
312318
$addOnId,
313319
$requireAddOnIds,
314-
$requireSoftAddOnIds,
315-
$relationEntityClass
320+
$softRequireAddOnIds,
316321
);
317322

318323
$relations[$relation] = [
@@ -405,6 +410,7 @@ protected function getDocPlaceholder() : string
405410

406411
protected function getEntityTypeMap() : array
407412
{
413+
/** @noinspection PhpDeprecationInspection */
408414
return [
409415
Entity::INT => 'int',
410416
Entity::UINT => 'int',

Cli/Command/EntityFromTable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function configure() : void
6161
*
6262
* @return int
6363
*
64-
* @throws \Exception
64+
* @throws \Symfony\Component\Console\Exception\ExceptionInterface
6565
*/
6666
protected function execute(InputInterface $input, OutputInterface $output) : int
6767
{

0 commit comments

Comments
 (0)