1. Go to this page and download the library: Download kanel/enuma 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/ */
kanel / enuma example snippets
$phpClass = new PhpClass('Foo');
$enuma = new Enuma();
$enuma->save($phpClass, 'path/to/a/file);
class Foo
{
}
$phpInterface = new PhpInterface('Foo');
$enuma = new Enuma();
$enuma->save($phpInterface, 'path/to/a/file);
interface Foo
{
}
$phpTrait = new PhpTrait('Foo');
$enuma = new Enuma();
$enuma->save($phpTrait, 'path/to/a/file);
trait Foo
{
}
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->setEncoding('your encoding');
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->setUsePhpClosingTag(true);
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->setIndentation("\t");
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->setClassBracesInNewLine(false);
//will generate :
class A {
}
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->setMethodBracesInNewLine(false);
//will generate :
class A
{
public function aaa() {
}
}
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->setUnixLineFeedEnding(false);
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->useWindowsNewLine(true);
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->useShortArrayNotation(false);
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->setAutoComments(false);
$customCodingStyle = new CustomCodingStyle();
$customCodingStyle->setClassBracesInNewLine(false);
$phpClass = new PhpClass('Foo', $customCodingStyle);
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
class Foo {
}
$phpClass = new PhpClass('Foo');
$phpClass->namespace('My\\Name\\Space');
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
class Foo
{
}
$phpClass = new PhpClass('Foo');
$phpClass->use('My\\Package\\Class1');
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
use My\Package\Class1;
class Foo
{
}
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->use('My\\Package\\Class1')
->addComment("This is my class\n@package My\\Name\\Space");
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
use My\Package\Class1;
/**
* This is my class
* @package My\Name\Space
*/
class Foo
{
}
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->abstract(true);
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
abstract class Foo
{
}
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->final(true);
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
final class Foo
{
}
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->extends('My\\OtherPackage\\Class2');
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
use My\OtherPackage\Class2;
final class Foo extends Class2
{
}
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->implements('My\\OtherPackage\\Interface1')
->implements('My\\OtherPackage\\Interface2');
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
use My\OtherPackage\Interface1;
use My\OtherPackage\Interface2;
class Foo implements Interface1, Interface2
{
}
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->useTrait('My\\OtherPackage\\Trait1')
->useTrait('My\\OtherPackage\\Trait2');
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
use My\OtherPackage\Trait1;
use My\OtherPackage\Trait2;
class Foo
{
use Trait1;
use Trait2;
}
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->addConst(new Constant('MY_CONST', true));
->addConst(new Constant('MY_OTHER_CONST', array(1, 2, 3));
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->addMethod(new Method('bar'));
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
class Foo
{
/**
* @return mixed
*/
public function bar()
{
}
}
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->addMethod(new Method('bar', Visibility::PROTECTED));
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
class Foo
{
/**
* @return mixed
*/
protected function bar()
{
}
}
$method = new Method('bar', Visibility::PROTECTED);
$method->setIsStatic(true);
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->addMethod($method);
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
class Foo
{
/**
* @return mixed
*/
protected static function bar()
{
}
}
$method = new Method('bar', Visibility::PROTECTED);
$method->setIsAbstract(true);
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->addMethod($method);
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
abstract class Foo
{
/**
* @return mixed
*/
abstract protected function bar();
}
$method = new Method('bar', Visibility::PROTECTED);
$method->setIsFinal(true);
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->addMethod($method);
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
class Foo
{
/**
* @return mixed
*/
final protected function bar()
{
}
}
$method = new Method('bar', Visibility::PROTECTED);
$method->setComment('This is my function');
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->addMethod($method);
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
class Foo
{
/**
* This is my function
* @return mixed
*/
protected function bar()
{
}
}
$method = new Method('bar', Visibility::PROTECTED);
$method->setReturnType('bool');
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->addMethod($method);
$enuma = new Enuma();
echo $enuma->stringify($phpClass);
namespace My\Name\Space;
class Foo
{
/**
* This is my function
* @return bool
*/
protected function bar(): bool
{
}
}
$method = new Method('bar', Visibility::PROTECTED);
$parameter = new Parameter("test");
$parameter->setValue(true);
$parameter->setType('bool');
$method->addParameter($parameter);
$phpClass = new PhpClass('Foo');
$phpClass
->namespace('My\\Name\\Space')
->addMethod($method);
$enuma = new Enuma();
echo $enuma->stringify($phpClass);