Skip to content

Instantly share code, notes, and snippets.

@dantleech
Last active July 11, 2017 09:26
Show Gist options
  • Save dantleech/97a0a558a74718ea9ec6004f253b1062 to your computer and use it in GitHub Desktop.
Save dantleech/97a0a558a74718ea9ec6004f253b1062 to your computer and use it in GitHub Desktop.
API for source code generator / modifier
<?php
$builder = $sourceBuilder->prototypeBuilder();
$builder->namespace('Animals');
$builder->use('Measurements\\Height');
$builder->class('Rabbits')
->properties()
->property('television')
->visiblity('private')
->end()
->end()
->methods()
->method('jump')
->position(0) // prepend
->parameters()
->parameter('how)
->default('high')
->type('Measurements\\Height')
->end()
->end()
->body()
->append('$this->television = "lamp"')
->end()
$prototype = $builder->build();
// apply prototype to existing source code (idempotent)
$sourceBuilder->apply($prototype, file_get_contents('SomeFile.php'));
// generate source
$sourceBuilder->generate($prototype);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment