Rapture PHP code Generator
, (*1)
PHP code generator., (*2)
Requirements
Install
composer require mrjulio/rapture-generator
Quick start
$class = new PhpClass('Test');
$class->setNamespace('Demo')
->setIsAbstract(true)
->setIsFinal(true)
->setExtends('\Rapture\Component\Definition\ClassAbstract')
->addImplements('\Rapture\Component\Definition\ClassInterface')
->addTrait('\Rapture\Component\Definition\ClassTrait')
->addConstant('status_on', 1)
->addConstant('status_off', 2)
->addProperty(new PhpProperty('status', 'self::STATUS_OFF', PhpMethod::KEYWORD_PROTECTED))
->addMethod(
new PhpMethod(
'setStatus',
'$this->status = $status;' . "\n" . "\n" . 'return $this;',
PhpMethod::KEYWORD_PUBLIC,
[['status', 'int', 'self::STATUS_OFF']]
)
)
->setComment(new PhpComment(['Class Demo', '', '@see HelloWorld']));
file_put_contents('User.php', PhpRender::renderClass($class));
Result:, (*3)
<?php
namespace Demo;
use Rapture\Component\Definition\ClassAbstract;
use Rapture\Component\Definition\ClassInterface;
use Rapture\Component\Definition\ClassTrait;
/**
* Class Demo
*
* @see HelloWorld
*/
final abstract class Test extends ClassAbstract implements ClassInterface
{
use ClassTrait;
const STATUS_ON = 1;
const STATUS_OFF = 2;
protected $status = self::STATUS_OFF;
public function setStatus(int $status = self::STATUS_OFF)
{
$this->status = $status;
return $this;
}
}
About
Author
Iulian N. rapture@iuliann.ro
, (*4)
Testing
cd ./test && phpunit
License
Rapture PHP code Generator is licensed under the MIT License - see the LICENSE
file for details., (*5)