Skip to content

Commit

Permalink
Merge branch 'release/10.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
garbast committed Nov 10, 2023
2 parents 364ceb8 + 47aa9b9 commit add3a2c
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 3 deletions.
1 change: 1 addition & 0 deletions Classes/Composer/ClassComposer.php
Expand Up @@ -25,6 +25,7 @@ class ClassComposer
Generator\UseGenerator::class,
Generator\ClassGenerator::class,
Generator\TraitGenerator::class,
Generator\ConstantGenerator::class,
Generator\PropertyGenerator::class,
Generator\ConstructorGenerator::class,
Generator\ClassMethodGenerator::class,
Expand Down
78 changes: 78 additions & 0 deletions Classes/Composer/Generator/ConstantGenerator.php
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "extender" Extension for TYPO3 CMS.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Evoweb\Extender\Composer\Generator;

use Evoweb\Extender\Parser\FileSegments;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\ClassConst;

class ConstantGenerator implements GeneratorInterface
{
public function generate(array $statements, array $fileSegments): array
{
$namespace = $this->getNamespace($statements);
$class = $this->getClass($namespace);

if ($class) {
$class->stmts = [...$class->stmts, ...$this->getUniqueClassConstants($fileSegments)];
}

return $statements;
}

protected function getUniqueClassConstants(array $fileSegments): array
{
$classConstant = [];
/** @var FileSegments $fileSegment */
foreach ($fileSegments as $fileSegment) {
foreach ($fileSegment->getClassConsts() as $currentClassConstant) {
foreach ($currentClassConstant->consts as $currentConst) {
if (isset($classConstant[(string)$currentConst->name])) {
continue;
}
$classConstant[(string)$currentConst->name] = new ClassConst([$currentConst]);
}
}
}
return array_values($classConstant);
}

protected function getNamespace(array $statements): ?Namespace_
{
$namespace = null;
foreach ($statements as $statement) {
if ($statement instanceof Namespace_) {
$namespace = $statement;
break;
}
}
return $namespace;
}

protected function getClass(Namespace_ $namespace): ?Class_
{
/** @var ?Class_ $class */
$class = null;
foreach ($namespace->stmts as $node) {
if ($node instanceof Class_) {
$class = $node;
break;
}
}
return $class;
}
}
1 change: 1 addition & 0 deletions Classes/Parser/ClassParser.php
Expand Up @@ -27,6 +27,7 @@ class ClassParser
Visitor\UseVisitor::class,
Visitor\ClassVisitor::class,
Visitor\TraitVisitor::class,
Visitor\ConstantVisitor::class,
Visitor\PropertyVisitor::class,
Visitor\ConstructorVisitor::class,
Visitor\ClassMethodVisitor::class,
Expand Down
24 changes: 24 additions & 0 deletions Classes/Parser/FileSegments.php
Expand Up @@ -18,6 +18,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\TraitUse;
use PhpParser\Node\Stmt\UseUse;
Expand Down Expand Up @@ -46,6 +47,11 @@ class FileSegments implements \JsonSerializable
*/
protected array $traits = [];

/**
* @var ClassConst[]
*/
protected array $classConsts = [];

/**
* @var Property[]
*/
Expand Down Expand Up @@ -154,6 +160,24 @@ public function addTrait(TraitUse $traitUse): void
$this->traits[] = $traitUse;
}

/**
* @return ClassConst[]
*/
public function getClassConsts(): array
{
return $this->classConsts;
}

public function setClassConsts(array $classConst): void
{
$this->classConsts = $classConst;
}

public function addClassConst(ClassConst $classConst): void
{
$this->classConsts[] = $classConst;
}

/**
* @return Property[]
*/
Expand Down
31 changes: 31 additions & 0 deletions Classes/Parser/Visitor/ConstantVisitor.php
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "extender" Extension for TYPO3 CMS.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Evoweb\Extender\Parser\Visitor;

use PhpParser\Node;
use PhpParser\Node\Stmt\ClassConst;

class ConstantVisitor extends AbstractVisitor
{
protected array $properties = [];

public function enterNode(Node $node): void
{
if ($node instanceof ClassConst) {
$this->fileSegment->addClassConst($node);
}
}
}
4 changes: 2 additions & 2 deletions Documentation/Settings.cfg
@@ -1,8 +1,8 @@
[general]

project = extender
version = 10.0.0
release = 10.0.0
version = 10.0.1
release = 10.0.1
copyright = since 2014 by evoWeb

# code highlight https://app.codeimage.dev/
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Expand Up @@ -9,7 +9,7 @@
'author_email' => 'extender@evoweb.de',
'author_company' => 'evoWeb',
'state' => 'stable',
'version' => '10.0.0',
'version' => '10.0.1',
'constraints' => [
'depends' => [
'typo3' => '11.0.0-12.2.99',
Expand Down

0 comments on commit add3a2c

Please sign in to comment.