Even more fluid code generation
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 17.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I looked at
https://github.com/nikic/PHP-Parser/blob/master/doc/4_Code_generation.markdown
I think it could be even more fluid :)
This is a snippet from here,
https://github.com/Ocramius/ProxyManager/issues/36#issuecomment-16843161
(further down)
I wrote this without knowledge of PHP-Parser syntax, so I don't insist on the exact identifiers.
$engine = new GeneratorEngine(..);
$blueprint = $engine->newClassBlueprint();
$blueprint->extend(..);
// Start with an empty public non-abstract method, then enhance it.
$blueprint->addMethod('foo')
->setProtected()
->setArguments(..)
->setBody(..)
;
// This will automatically scan the interface for methods
$blueprint->implement(..);
// Take the signature directly from the interface
// The interface needs to be added *before* this.
$blueprint->overrideMethod('bar')
->setBody(..)
;
// Class name is not decided before the end.
// Decisions about file generation vs eval() are made in GeneratorEngine,
// we don't have to worry about it.
$reflectionClass = $blueprint->createAtName('MyClass');
// We now have a reflection class to work with.
$object = $reflectionClass->newInstance(..);
// Just for fun, we can create a copy of this class with a different name,
// and a different implementation of foo().
$blueprint->addMethodIfNotExists('foo')
// Set the body to something else.
->setBody(..)
;
$blueprint->createAtName('AlternativeClass');
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read doc/4_Code_generation.markdown and compare its documented API with the proposed GeneratorEngine and blueprint flow. The issue does not identify implementation files or tests; work is not ready to start until the desired API and scope are decided, with completion defined by an agreed design and corresponding implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100