2017 © Pedro Peláez
 

library code-builder

Generating and modifying source code

image

phpactor/code-builder

Generating and modifying source code

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 55 % Grown

The README.md

Code Builder

CI, (*1)

This library can be used to generate or idempotently add classes, methods, properties, use statements, etc. to existing source code using prototypes., (*2)

A prototype is an object which defines structural code elements., (*3)

Usage

The library provides a source code prototype builder:, (*4)

$builder = SourceBuilder::create()
    ->namespace('Animals');
    ->use('Measurements\\Height');
    ->class('Rabbits')
        ->extends('Leopridae')
        ->property('force')
            ->visibility('private')
            ->type('int')
            ->defaultValue(5)
        ->end()
        ->method('jump')
            ->parameters()
                ->parameter('how')
                    ->default('high')
                    ->type('Height')
                ->end();
            ->end()
        ->end()
    ->end();

$sourcePrototype = $builder->build();

the above prototype can either be used to generate a new class:, (*5)

$renderer = new TwigRenderer();
$renderer->render($sourcePrototype);

Or it can be applied to an existing source code, given the following:, (*6)

<?php

class Rabbits
{
}

When we do:, (*7)

$updater = new TolerantUpdater();
$updater->apply($sourcePrototype, Code::fromString(file_get_contents('Rabbits.php')));

Then we get:, (*8)

<?php

namespace Animals;

use Measurements\Height;

class Rabbits extends Leopridae
{
    private $force = 5;

    public function jump(Height $how = 'high')
    {
    }
}

About this project

This library is part of the phpactor project., (*9)

Contributing

This package is open source and welcomes contributions! Feel free to open a pull request on this repository., (*10)

Support

  • Create an issue on the main Phpactor repository.
  • Join the #phpactor channel on the Slack Symfony Devs channel.

The Versions

21/05 2018

dev-method_inclusive

dev-method_inclusive

Generating and modifying source code

  Sources   Download

MIT

The Requires

 

The Development Requires

10/05 2018

dev-master

9999999-dev

Generating and modifying source code

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2018

dev-ignore_existing_use

dev-ignore_existing_use

Generating and modifying source code

  Sources   Download

MIT

The Requires

 

The Development Requires

05/08 2017

dev-method_body_2

dev-method_body_2

Generating and modifying source code

  Sources   Download

MIT

The Requires

 

The Development Requires

05/08 2017

dev-method_body

dev-method_body

Generating and modifying source code

  Sources   Download

MIT

The Requires

 

The Development Requires

18/07 2017

0.1.0

0.1.0.0

Generating and modifying source code

  Sources   Download

MIT

The Requires

 

The Development Requires