corneltek/class-template

Class template Utilities

Installs: 11 880

Dependents: 4

Stars: 6

Watchers: 2

Forks: 2

Open Issues: 9

Language: PHP

2.1.1 2015-08-26 06:29 UTC

README

ClassTemplate library is used for generating static PHP class files from a programmable interface with PHP.

SYNOPSIS

$class1 = new ClassTemplate\ClassFile('Foo\\Bar22',array(
    'template' => 'Class.php.twig',
    'template_dirs' => array('src/ClassTemplate/Templates'),
));
ok($class1);

$class1->addConst('TYPE_A', 1);
$class1->addConst('TYPE_B', 2);
$class1->addConst('TYPE_C', 3);

$class1->addMethod('public','getTwo',[],'return 2;');
$class1->addMethod('public','getFoo',['$i'],'return $i;');

$class1->extendClass('FooClass');

$class1->extendClass('SplArray', true);

$code = $class1->render();

The above code outpus:

<?php
namespace Foo;
class Bar22 {
    public function getTwo() {
        return 2;
    }

    public function getFoo($i) {
        return $i;
    }
}

INSTALL

Define the dependency in your composer.json file:

{
    "require": {
        "corneltek/class-template": "*"
    }
}

Then run composer.phar to install:

$ composer install --dev

Classes

ClassProperty

$property = new ClassProperty('key','123');
echo $property->render(); // public $key = 123;

ClassMethod

$method = new ClassMethod('methodName',[ '$i' ], 'return $i;');