public function register($kernel, $options = array()) { if (isset($options['DefaultFieldView'])) { Action::$defaultFieldView = $options['DefaultFieldView']; } $container = new ServiceContainer(); $generator = $container['generator']; $generator->registerTemplate('TwigActionTemplate', new TwigActionTemplate()); $generator->registerTemplate('CodeGenActionTemplate', new CodeGenActionTemplate()); $generator->registerTemplate('RecordActionTemplate', new RecordActionTemplate()); $generator->registerTemplate('UpdateOrderingRecordActionTemplate', new UpdateOrderingRecordActionTemplate()); $action = new ActionRunner($container); $action->registerAutoloader(); $kernel->action = function () use($options, $action) { return $action; }; $kernel->event->register('view.init', function ($view) use($action) { $view->args['Action'] = $action; }); $kernel->event->register('phifty.before_path_dispatch', function () use($kernel) { if (!ActionRequest::hasAction($_REQUEST)) { return; } $runner = $kernel->action; // get runner $kernel->event->trigger('phifty.before_action'); $strout = fopen("php://output", "w"); // If we found any ajax action, exit the application if ($runner->handleWith($strout, $_REQUEST, $_FILES)) { exit(0); } }); }
/** * @synopsis * * $template->register($runner, array( * 'namespace' => 'test', * 'model' => 'testModel', // model's name * 'allowed_roles' => array('admin', 'manager'), * 'types' => [ * ['prefix' => 'Create', 'allowed_roles' => ['user', 'admin'] ], * ['prefix' => 'Update'], * ['prefix' => 'Delete'] * ] * )); */ public function register(ActionRunner $runner, $asTemplate, array $options = array()) { if (isset($options['use'])) { array_unshift($options['use'], '\\ActionKit\\Action', '\\ActionKit\\RecordAction\\BaseRecordAction'); } else { $options['use'] = ['\\ActionKit\\Action', '\\ActionKit\\RecordAction\\BaseRecordAction']; } if (!isset($options['namespace'])) { throw new RequiredConfigKeyException('namespace', 'namespace of the generated action'); } if (!isset($options['model'])) { throw new RequiredConfigKeyException('model', 'required for creating record actions'); } if (!isset($options['types'])) { throw new RequiredConfigKeyException('types', 'types is an array of operation names for CRUD'); } foreach ((array) $options['types'] as $type) { // re-define type if (is_string($type)) { $type = ['prefix' => $type]; } $actionClass = $options['namespace'] . '\\Action\\' . $type['prefix'] . $options['model']; $properties = ['recordClass' => $options['namespace'] . "\\Model\\" . $options['model']]; $traits = array(); if (isset($options['allowed_roles']) || isset($type['allowed_roles'])) { $properties['allowedRoles'] = isset($type['allowed_roles']) ? $type['allowed_roles'] : $options['allowed_roles']; $traits = ['ActionKit\\ActionTrait\\RoleChecker']; } $configs = ['extends' => "\\ActionKit\\RecordAction\\{$type['prefix']}RecordAction", 'properties' => $properties, 'traits' => $traits, 'use' => $options['use']]; $runner->register($actionClass, $asTemplate, $configs); } }
public function register($kernel, $options = array()) { $container = new ServiceContainer(); $generator = $container['generator']; $generator->registerTemplate('TwigActionTemplate', new TwigActionTemplate()); $generator->registerTemplate('CodeGenActionTemplate', new CodeGenActionTemplate()); $generator->registerTemplate('RecordActionTemplate', new RecordActionTemplate()); $generator->registerTemplate('UpdateOrderingRecordActionTemplate', new UpdateOrderingRecordActionTemplate()); $action = new ActionRunner($container); $action->registerAutoloader(); $kernel->action = function () use($options, $action) { return $action; }; $kernel->event->register('view.init', function ($view) use($action) { $view->args['Action'] = $action; }); $kernel->event->register('phifty.before_path_dispatch', function () use($kernel) { // check if there is $_POST['action'] or $_GET['action'] if (!isset($_REQUEST['__action'])) { return; } $runner = $kernel->action; // get runner $kernel->event->trigger('phifty.before_action'); $strout = fopen("php://stdout", "w"); $result = $runner->handleWith($strout, $_REQUEST, $_FILES); }); }
public function testSampleActionTemplate() { $generator = new ActionGenerator(); $generator->registerTemplate('SampleActionTemplate', new SampleActionTemplate()); $runner = new ActionRunner(['generator' => $generator]); // $runner->registerAction('SampleActionTemplate', array('action_class' => 'SampleAction')); $runner->getGenerator()->generate('SampleActionTemplate', 'SampleAction', ['namespace' => 'FooBar', 'action_name' => 'CreateSample']); }
/** * @synopsis * * $template->register($runner, [ * 'action_class' => 'FooAction', * 'extends' => "\\ActionKit\\RecordAction\\{$type}RecordAction", * 'properties' => [ * 'recordClass' => $options['namespace'] . "\\Model\\" . $options['model'], * ], * ]); */ public function register(ActionRunner $runner, $asTemplate, array $options = array()) { if (isset($options['use'])) { array_unshift($options['use'], '\\ActionKit\\Action'); } else { $options['use'] = ['\\ActionKit\\Action']; } $runner->register($options['action_class'], $asTemplate, $options); }
/** * @dataProvider orderingActionMapProvider */ public function testProductUpdateOrderingActions($actionClass, $recordClass) { $container = new ServiceContainer(); $generator = $container['generator']; $generator->registerTemplate('TwigActionTemplate', new TwigActionTemplate()); $generator->registerTemplate('UpdateOrderingRecordActionTemplate', new UpdateOrderingRecordActionTemplate()); $runner = new ActionRunner($container); $runner->registerAction('UpdateOrderingRecordActionTemplate', array('namespace' => 'ProductBundle', 'record_class' => $recordClass)); $action = $runner->createAction($actionClass); $this->assertNotNull($action); }
/** * @dataProvider roleProvider */ public function testRunnerWithMultiRoleInterface($roles, $resultType) { $container = new ServiceContainer(); $generator = $container['generator']; $generator->registerTemplate('RecordActionTemplate', new RecordActionTemplate()); $runner = new ActionRunner($container); $runner->registerAutoloader(); $runner->registerAction('RecordActionTemplate', array('namespace' => 'OrderBundle', 'model' => 'Order', 'types' => array(['prefix' => 'Create', 'allowed_roles' => ['user', 'admin']], ['prefix' => 'Update'], ['prefix' => 'Delete']))); $user = new TestUser(); $user->roles = $roles; $runner->setCurrentUser($user); $result = $runner->run('OrderBundle::Action::CreateOrder', ['qty' => '1']); ok($result); is($resultType, $result->type); }
/** * @synopsis * * $template->register($runner, * 'templateName', * array( * 'action_class' => 'User\\Action\\BulkUpdateUser', * 'template' => '@ActionKit/RecordAction.html.twig', * 'variables' => array( * 'record_class' => 'User\\Model\\User', * 'base_class' => 'ActionKit\\RecordAction\\CreateRecordAction' * ) * )); */ public function register(ActionRunner $runner, $asTemplate, array $options = array()) { // $targetActionClass, $template, $variables if (!isset($options['action_class'])) { throw new RequiredConfigKeyException('action_class'); } $class = $options['action_class']; if (!isset($options['template'])) { throw new RequiredConfigKeyException('template'); } $template = $options['template']; if (!isset($options['variables'])) { throw new RequiredConfigKeyException('variables'); } $variables = $options['variables']; $runner->register($class, $asTemplate, ['template' => $template, 'variables' => $variables]); }
public function register(Kernel $kernel, $options = array()) { $kernel->actionService = function () use($kernel, $options) { $container = new ServiceContainer(); $container['cache_dir'] = $kernel->cacheDir; if ($kernel->locale) { $container['locale'] = $kernel->locale->current; } if (isset($options['DefaultFieldView'])) { Action::$defaultFieldView = $options['DefaultFieldView']; } $generator = $container['generator']; $generator->registerTemplate('TwigActionTemplate', new TwigActionTemplate()); $generator->registerTemplate('CodeGenActionTemplate', new CodeGenActionTemplate()); $generator->registerTemplate('RecordActionTemplate', new RecordActionTemplate()); $generator->registerTemplate('UpdateOrderingRecordActionTemplate', new UpdateOrderingRecordActionTemplate()); return $container; }; $kernel->actionRunner = function () use($kernel) { $actionRunner = new ActionRunner($kernel->actionService); $actionRunner->registerAutoloader(); // $actionRunner->setDebug(); return $actionRunner; }; $kernel->action = function () use($kernel) { return $kernel->actionRunner; }; $kernel->event->register('view.init', function ($view) use($kernel) { $view['Action'] = $kernel->actionRunner; }); $kernel->event->register('phifty.before_path_dispatch', function () use($kernel) { if (!ActionRequest::hasAction($_REQUEST)) { return; } $runner = $kernel->action; // the new trigger for actions defined in Bundle::actions method $kernel->event->trigger('phifty.prepare_actions'); $kernel->event->trigger('phifty.before_action'); $strout = fopen('php://output', 'w'); // If we found any ajax action, exit the application if ($runner->handleWith($strout, $_REQUEST, $_FILES)) { exit(0); } }); }
public function testRecordActionTemplate() { $generator = new ActionGenerator(); $generator->registerTemplate('RecordActionTemplate', new RecordActionTemplate()); $runner = new ActionRunner(['generator' => $generator]); $actionArgs = array('namespace' => 'test', 'model' => 'testModel', 'types' => array(['prefix' => 'Create'], ['prefix' => 'Update'], ['prefix' => 'Delete'], ['prefix' => 'BulkDelete'])); $runner->registerAction('RecordActionTemplate', $actionArgs); /* $template = $generator->getTemplate('RecordActionTemplate'); $template->register($runner, 'RecordActionTemplate', $actionArgs); */ $this->assertCount(4, $runner->getPretreatments()); $className = 'test\\Action\\UpdatetestModel'; $this->assertNotNull($pretreatment = $runner->getActionPretreatment($className)); $generatedAction = $generator->generate('RecordActionTemplate', $className, $pretreatment['arguments']); $generatedAction->load(); ok(class_exists($className)); }
public function render_result($resultName) { $runner = ActionRunner::getInstance(); if ($result = $runner->getResult($resultName)) { $view = new View(); $view->result = $result; return $view->render('@CoreBundle/phifty/action_result_box.html'); } }
public function register(ActionRunner $runner, $asTemplate, array $options = array()) { if (isset($options['use'])) { array_unshift($options['use'], '\\ActionKit\\Action', '\\ActionKit\\RecordAction\\BaseRecordAction'); } else { $options['use'] = ['\\ActionKit\\Action', '\\ActionKit\\RecordAction\\BaseRecordAction']; } if (!isset($options['model'])) { if (isset($options['record_class'])) { $nslist = explode("\\Model\\", $options['record_class']); $options['model'] = $nslist[1]; if (!isset($options['namespace'])) { $options['namespace'] = $nslist[0]; } } else { throw new RequiredConfigKeyException('model', 'required for creating record actions'); } } if (!isset($options['namespace'])) { throw new RequiredConfigKeyException('namespace', 'namespace'); } $actionClass = $options['namespace'] . '\\Action\\Update' . $options['model'] . 'Ordering'; $runner->register($actionClass, $asTemplate, ['extends' => "\\ActionKit\\RecordAction\\UpdateOrderingRecordAction", 'properties' => ['recordClass' => $options['namespace'] . "\\Model\\" . $options['model']]]); }
/** * @expectedException ActionKit\Exception\ActionNotFoundException */ public function testRunnerWithActionNotFoundException() { $container = new ServiceContainer(); $runner = new ActionRunner($container); $result = $runner->run('Product::Action::Product'); }
} public function run() { if ($this->arg('email') == '*****@*****.**' && $this->arg('password') == 'test') { return $this->success('登入成功'); } else { if ($this->arg('email') != '*****@*****.**') { return $this->error('無此帳號'); } else { if ($this->arg('password') != 'test') { return $this->error('密碼錯誤'); } } } } } $container = new ActionKit\ServiceContainer(); $runner = new ActionKit\ActionRunner($container); // you can also run action directly // $result = $runner->run('MyLoginAction',array( 'email' => '...', 'password' => '...' )); if (isset($_POST['action'])) { $sig = $_POST['action']; unset($_POST['action']); $result = $runner->run($sig, $_POST); //var_dump($result); echo $result->getMessage(); } else { $action = new MyLoginAction(); echo $action->asView()->render(); // implies view class ActionKit\View\StackView }
public function get_result($resultName) { $runner = ActionRunner::getInstance(); return $runner->getResult($resultName); }