corneltek / class-template
Class template Utilities
Installs: 152 709
Dependents: 2
Suggesters: 0
Security: 0
Stars: 14
Watchers: 4
Forks: 3
Open Issues: 10
Requires
- php: >=5.3.0
- corneltek/codegen: ^3.0.0
- twig/twig: ^1.22
Requires (Dev)
- corneltek/phpunit-testmore: dev-master
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;');