PHPackages                             blacktools/metabot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. blacktools/metabot

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

blacktools/metabot
==================

Php code that code php code.

1.0.0(9y ago)019[5 issues](https://github.com/henriquefernandez/PhpMetaBot/issues)MITPHPPHP &gt;=5.6.0

Since May 11Pushed 7y agoCompare

[ Source](https://github.com/henriquefernandez/PhpMetaBot)[ Packagist](https://packagist.org/packages/blacktools/metabot)[ Docs](https://github.com/henriquefernandez/PhpMetabot)[ RSS](/packages/blacktools-metabot/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

About
-----

[](#about)

PhpMetaBot is a very minimal framework that makes easy to write "php code from php code". It can be a lot useful to make CLI commands that generate scaffold codes from different needs. Let your creativity fly. Feel free to fork and do whatever you want. I done it just for fun.

Install
-------

[](#install)

Via Composer

```
$ composer require blacktools/metabot
```

Usage
-----

[](#usage)

```
/* or require 'vendor/autoload.php' */
require '../src/Code.php';
require '../src/PhpClass.php';
require '../src/PhpFile.php';
require '../src/PhpFunction.php';
require '../src/PhpMethod.php';

use Blacktools\Metabot\Base\PhpFile;
use Blacktools\Metabot\Base\PhpClass;
use Blacktools\Metabot\Base\PhpMethod;
use Blacktools\Metabot\Base\PhpFunction;

/* Create a PhpFile */
$file = new PhpFile('test.php');

/* Create a PhpClass */
$class = new PhpClass("ClassTest");
/* Set extends to a class: name */
$class->setExtends('ExtendTest');
/* Set implements to a class: name */
$class->setImplements('ImplementTest');
/* Set attribute to a class: scope / name */
$class->setAttribute('private','attributeTest');
/* Set attribute to a class: scope / name */
$class->setAttribute('private static','staticAtribute');

/* Create a PhpMethod: scope / name */
$methodTest = new PhpMethod("public","methodTest");
/* Set a parameter to a method: typehint / name  */
$methodTest->setParameter(null, "foo");
/* Set a parameter to a method: typehint / name / default */
$methodTest->setParameter(null, "bar","'zoo'");
/* Set inner content to a method, using \t for tabs and \n for break lines  */
$methodTest->setInner("\t\treturn null;\n");

/* Create a static PhpMethod: scope / name */
$staticMethod = new PhpMethod("public static","staticMethod");
/* Set a parameter to a method: typehint / name / default */
$staticMethod->setParameter('int', "xoo","'hoo'");
/* Set inner content to a method, using \t for tabs and \n for break lines  */
$staticMethod->setInner("\t\treturn ".'$xoo'.";\n");

/* Add PhpMethod to a PhpClass */
$class->setMethod($methodTest);
/* Add another PhpMethod to a PhpClass */
$class->setMethod($staticMethod);

/* Create PhpFunction: name */
$function = new PhpFunction('hey');

/* Set a namespace to a PhpFile */
$file->setNamespace('Test\Namespace');
/* Set a use keyword to a PhpFile */
$file->setUse('AnotherTest\UseThis');
/* Write a PhpClass in the PhpFile */
$file->setClass($class);
/* Write a PhpFunction in the PhpFile */
$file->setFunction($function);

/* Get the code as string */
echo $file->getBody();

// Returns

//
