thuata/intercessionbundle
Composer 安装命令:
composer require thuata/intercessionbundle
包简介
Bundle to help code generation
README 文档
README
Intercession principle
Intercession is the ability of a program to modify its own execution state. That mean intercession allows to generate and execute some code in live during the program execution.
The Intercession bundle is meant to generate class definitions and eventualy write it in a file. You are then free to include / require the file lively to have the new generated class available. The bundle provides also tools to add phpdoc.
Warning
Take in consideration that code generation, if not safely used can be very dangerous and harmfull for your applications. You should only use intercession with code you understand. Using intercession with unsafe code or code from uncertain source (like from a form request) should be done in specific environments (ie. containers or virtual systems ).
Being aware of that intercession can be a very powerfull tool.
Installation
Step 1: Download the Bundle
In your composer.json file add the following lines :
{
"require": {
// ...
"thuata/intercessionbundle": "^1",
// ...
}
}
or directly with composer on command line :
composer require thuata/intercessionbundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Thuata\IntercessionBundle\ThuataIntercessionBundle, ); // ... } // ... }
Usage
The intercession bundle provides some classes to prepare the Class, Methods and Properties definitions and a service to generate definition and / or write it in a file.
Here is a simple example that defines a class in a namspace. The class extends another one, implements some interfaces and uses some traits. It as a description and an author (for phpdoc)
$class = new IntercessionClass(); // instanciates the intercession class $class->setName('Foo'); // sets the class name ... $class->setNamespace('Bar/Baz'); // ... and the namespace $class->addAuthor('Anthony Maudry', 'anthony.maudry@thuata.com'); // the author (appears in phpdoc) $class->setDescription('The marvelous Foo class !'); // and a description (php doc too) $class->addInterface('\Bar\FooBarInterface'); // First interface to implement $class->addInterface('\Bar\BarFooInterface'); // and the second interface $class->addTrait('\Bar\FooBarTrait'); // one trait $class->addTrait('\Bar\BarFooTrait'); // another trait $class->setExtends('\Bar\AbstractFooBar'); // Foo class now extends another class /** @var GeneratorService $generator */ $generator = $container->get('thuata_intercession.generator'); // get the generator from the conatainer // get the definition as string ... $definition = $generator->renderClass($class); // or write it directly in a file $fileName = '/some/path/to/a/file.php'; $generator->createClassDefinitionFile($class, $fileName); // you can now include that file : include_once($fileName); // and instanciate your class : $foo = new \Bar\Baz\Foo();
A more complete document is coming.
Next steps
This version is 1.0. It provides only definition generation.
next steps will provide :
- A full documentation
- Live edition of classes, even after instantiation
thuata/intercessionbundle 适用场景与选型建议
thuata/intercessionbundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 176 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 11 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 thuata/intercessionbundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thuata/intercessionbundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 176
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-19