Revision: Fri, 31 May 2024 16:10:39 GMT
v1.0 – outdated
This version of the documentation is outdated. Consider upgrading your project to Spiral Framework 3.12
Edit this page

Code Generation

The Spiral Reactor component includes set of OOP based code declarations used to create classes, methods using declarative approach.

This section will review basic Reactor usages.

See spiral/scaffolder to code generation in action.

Generate controller

Let's generate controller declaration with pre-defined action method:

$controller = new ClassDeclaration('TestController', Controller::class);
    ->setComment('@var SomeService');

$method = $controller->method('indexAction');


    'return $this->service->doSomething($value);'


Resulted code:

class TestController extends Spiral\Core\Controller
     * @var SomeService
    private $service = null;

    public function indexAction(string $value = null)
        return $this->service->doSomething($value);