thenlabs / class-builder
PHP中类的、特性和接口的动态管理。
v1.0.10
2022-05-13 22:27 UTC
Requires
- php: >=7.2
Requires (Dev)
- doctrine/annotations: ^1.8
- friendsofphp/php-cs-fixer: ^3.2
- thenlabs/pyramidal-tests: 2.0.x-dev
README
PHP中类的、特性和接口的动态管理。
如果你喜欢这个项目,请给我们一个 ⭐。
文档。
- 英语(待定)
- 西班牙语
安装。
$ composer require thenlabs/class-builder
需要 PHP >= 7.2
示例。
以下示例展示了如何使用我们的 ClassBuilder
动态创建 PHP 类。
<?php use ThenLabs\ClassBuilder\ClassBuilder; $personClass = new ClassBuilder('Person'); $personClass->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
开发。
克隆此存储库并安装 Composer 依赖项。
$ composer install
运行测试。
此项目的所有测试均使用我们的测试框架 PyramidalTests 编写,该框架基于 PHPUnit。
运行测试
$ composer test