Ejemplo n.º 1
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);
     }
 }
Ejemplo n.º 2
0
 /**
  * @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);
 }
Ejemplo n.º 3
0
 /**
  *  @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(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']]]);
 }