2017 © Pedro Peláez
 

symfony-bundle intercessionbundle

Bundle to help code generation

image

thuata/intercessionbundle

Bundle to help code generation

  • Wednesday, April 5, 2017
  • by Kuchulem
  • Repository
  • 1 Watchers
  • 0 Stars
  • 63 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

Intercession Bundle

Build Status Codeship, (*1)

Intercession principle

Intercession is the ability of a program to modify its own execution state. That mean intercession allows to generate and execute some code in live during the program execution., (*2)

The Intercession bundle is meant to generate class definitions and eventualy write it in a file. You are then free to include / require the file lively to have the new generated class available. The bundle provides also tools to add phpdoc., (*3)

Warning

Take in consideration that code generation, if not safely used can be very dangerous and harmfull for your applications. You should only use intercession with code you understand. Using intercession with unsafe code or code from uncertain source (like from a form request) should be done in specific environments (ie. containers or virtual systems )., (*4)

Being aware of that intercession can be a very powerfull tool., (*5)

Installation

Step 1: Download the Bundle

In your composer.json file add the following lines :, (*6)

{
    "require": {
      // ...
        "thuata/intercessionbundle": "^1",
      // ...
    }
}

or directly with composer on command line :, (*7)

composer require thuata/intercessionbundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*8)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*9)

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Thuata\IntercessionBundle\ThuataIntercessionBundle,
        );

        // ...
    }

    // ...
}

Usage

The intercession bundle provides some classes to prepare the Class, Methods and Properties definitions and a service to generate definition and / or write it in a file., (*10)

Here is a simple example that defines a class in a namspace. The class extends another one, implements some interfaces and uses some traits. It as a description and an author (for phpdoc), (*11)


$class = new IntercessionClass(); // instanciates the intercession class $class->setName('Foo'); // sets the class name ... $class->setNamespace('Bar/Baz'); // ... and the namespace $class->addAuthor('Anthony Maudry', 'anthony.maudry@thuata.com'); // the author (appears in phpdoc) $class->setDescription('The marvelous Foo class !'); // and a description (php doc too) $class->addInterface('\Bar\FooBarInterface'); // First interface to implement $class->addInterface('\Bar\BarFooInterface'); // and the second interface $class->addTrait('\Bar\FooBarTrait'); // one trait $class->addTrait('\Bar\BarFooTrait'); // another trait $class->setExtends('\Bar\AbstractFooBar'); // Foo class now extends another class /** @var GeneratorService $generator */ $generator = $container->get('thuata_intercession.generator'); // get the generator from the conatainer // get the definition as string ... $definition = $generator->renderClass($class); // or write it directly in a file $fileName = '/some/path/to/a/file.php'; $generator->createClassDefinitionFile($class, $fileName); // you can now include that file : include_once($fileName); // and instanciate your class : $foo = new \Bar\Baz\Foo();

A more complete document is coming., (*12)

Next steps

This version is 1.0. It provides only definition generation., (*13)

next steps will provide : - A full documentation - Live edition of classes, even after instantiation, (*14)

The Versions

05/04 2017

v1.0.x-dev

1.0.9999999.9999999-dev

Bundle to help code generation

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2016
06/12 2016

dev-fix/versions

dev-fix/versions

Bundle to help code generation

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2016

dev-feature/constants-and-return-types

dev-feature/constants-and-return-types

Bundle to help code generation

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2016

dev-fix/readme

dev-fix/readme

Bundle to help code generation

  Sources   Download

MIT

The Requires

 

The Development Requires

04/12 2016

dev-feature/travis

dev-feature/travis

Bundle to help code generation

  Sources   Download

MIT

The Requires

 

The Development Requires

01/10 2016
21/04 2016

v1.0.3

1.0.3.0

Bundle to help code generation

  Sources   Download

MIT

The Requires

 

The Development Requires

08/04 2016

1.0.1

1.0.1.0

Bundle to help code generation

  Sources   Download

MIT

The Requires

 

The Development Requires

08/04 2016

v1.0.2

1.0.2.0

Bundle to help code generation

  Sources   Download

MIT

The Requires

 

The Development Requires

07/04 2016