PHP code example of corneltek / class-template

1. Go to this page and download the library: Download corneltek/class-template library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

corneltek / class-template example snippets


$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();



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

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

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

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