Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thenlabs/class-builder

Dynamic management of classes, traits and interfaces in PHP.
https://github.com/thenlabs/class-builder

builder builder-pattern php php-builder php-class php-classes php-interface php-library php-traits

Last synced: 9 days ago
JSON representation

Dynamic management of classes, traits and interfaces in PHP.

Awesome Lists containing this project

README

        

# ClassBuilder

Dynamic management of classes, traits and interfaces in PHP.

>If you like this project gift us a ⭐.

## Documentation.

1. English (Pending)
2. [Español](doc/es/index.md)

## Installation.

$ composer require thenlabs/class-builder

>Require PHP >= 7.2

## Example.

The next example shows a way to create dinamically a PHP class using our `ClassBuilder`.

```php
setNamespace('ThenLabs\Demo');

$personClass->addProperty('name')->setAccess('protected');

$personClass->addMethod('__construct', function (string $name) {
$this->name = $name;
});

$personClass->addMethod('getName', function (): string {
return $this->name;
});

$personClass->install();

$andy = new Person('Andy');

$andy->getName() === 'Andy'; // true
$andy instanceof \ThenLabs\Demo\Person; // true
```

## Development.

Clone this repository and install the Composer dependencies.

$ composer install

### Running the tests.

All the tests of this project was written with our testing framework [PyramidalTests][pyramidal-tests] wich is based on [PHPUnit][phpunit].

Run tests:

$ composer test

[phpunit]: https://phpunit.de
[pyramidal-tests]: https://github.com/thenlabs/pyramidal-tests