-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for PHP 8.0 class attributes generation #145
base: 4.8.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first skim: endorse simplifying and removing flexibility in a first step.
The factory and the builder are not necessary, if the attribute generator can act as an immutable builder (most common use-case anyway)
src/Generator/AttributeGenerator.php
Outdated
use Laminas\Code\Generator\AttributeGenerator\AttributeBuilder; | ||
use ReflectionClass; | ||
|
||
class AttributeGenerator extends AbstractGenerator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably make this final
, since it's a new symbol, and inheritance abuse is strong :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I don't know why I extended it, maybe in the beginning when I didn't know the code, I'll stay on with interface GeneratorInterface
:)
|
||
use Stringable; | ||
|
||
interface AttributeAssembler extends Stringable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not make this Stringable
: Stringable
is a terrible API.
See also ShittySoft/symfony-live-berlin-2018-doctrine-tutorial#3 (comment) for more clarity
use ReflectionAttribute; | ||
use ReflectionClass; | ||
|
||
final class AttributeAssemblerFactory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code can all be inlined into the AttributeGenerator
: no need to make a separate class out of it.
|
||
final class AttributeBuilder | ||
{ | ||
private array $definitions = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is to be refined
namespace Laminas\Code\Generator\AttributeGenerator; | ||
|
||
//TODO Enum in PHP8.1 | ||
final class AttributePart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's mark all internally used symbols as @internal
, to allow refactoring/rewrite as soon as we are allowed to.
Sorry, didn't get to work on this at all, due to other priorities. |
return new self(...$assemblers); | ||
} | ||
|
||
public static function fromArray(array $definitions): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After digging further into this, I decided to skip it for Specifically, I would simplify the I understand that you wanted to split generator and data structure, but practically, it doesn't really help with the use-case of this library, IMO. What I'd end up with in the end is probably a single class with a thin
Everything else would be Therefore needing to put this patch aside: it needs a good weekend of thinking it through, which I didn't manage to find, sorry. |
Hello. 👋🏻 Is there anything I can do to help moving this PR forward? I'm working on a small code generator tool at the moment and I need the ability to emit class and property attributes. |
Sorry, I have no time to work it out, I'll try to close this next month. |
If there is no objections I would pick this up, make the requested changes and see to add method support along the way. |
I don't understand this object type parameter, there is AttributePrototype for it @kitsunet I've pushed some changes |
Cool, thanks! I guess I'll wait for ocramius verdict then and start in parallel to create changes for class members and methods on top of this. |
I've already started working on methods 😱 |
Hi, any updates on this? |
I'm waiting for @Ocramius review |
@Ocramius ?? |
This PR is already 17mo old almost 1 and a half years, still waiting for @Ocramius re-review for 7mo now. |
Colleagues, what the current status of this PR, as I can see, this feature is awaited by many developers. |
I'm still waiting for @Ocramius review |
Is there anyone else that could review this? |
Sorry, but it's a joke at this point, two years have passed. |
Haven't touched this component in a while, and OSS efforts currently compete with the time I'm dedicating to sleep. |
Description
Feature that allows attribute generation for classes (methods/properties is the next step)
Either non-arguments attributes and named arguments are supported.
Nested attributes are not supported yet.
You can use it in a few ways: