public function initGenericClassWithOptions(TemplateClassFile $templateClassFile, array $options = array()) { if (isset($options['use'])) { foreach ($options['use'] as $use) { $templateClassFile->useClass($use); } } if (isset($options['extends'])) { $templateClassFile->extendClass($options['extends']); } if (isset($options['properties'])) { foreach ($options['properties'] as $name => $value) { $templateClassFile->addProperty($name, $value); } } if (isset($options['constants'])) { foreach ($options['constants'] as $name => $value) { $templateClassFile->addConst($name, $value); } } if (isset($options['traits'])) { foreach ($options['traits'] as $traitClass) { $templateClassFile->useTrait($traitClass); } } }
public function generate($actionClass, array $options = array()) { if (!isset($options['namespace'])) { throw new RequiredConfigKeyException('action_name'); } if (!isset($options['action_name'])) { throw new RequiredConfigKeyException('action_name'); } $namespace = $options['namespace']; $actionName = $options['action_name']; $actionClass = "{$namespace}\\Action\\{$actionName}"; $options = ['extends' => 'Action']; $templateClassFile = new TemplateClassFile($actionClass); // General use statement $templateClassFile->useClass('\\ActionKit\\Action'); $templateClassFile->useClass('\\ActionKit\\RecordAction\\BaseRecordAction'); $this->initGenericClassWithOptions($templateClassFile, $options); $templateClassFile->addMethod('public', 'schema', [], ''); $templateClassFile->addMethod('public', 'run', [], 'return $this->success("Success!");'); $code = $templateClassFile->render(); return new GeneratedAction($actionClass, $code, $templateClassFile); }