コード例 #1
0
ファイル: Executor.php プロジェクト: rtens/domin
 /**
  * @param $id
  * @return ExecutionResult
  */
 public function execute($id)
 {
     if (!$this->access->isPermitted($id)) {
         return new NotPermittedResult();
     }
     try {
         $action = $this->actions->getAction($id);
         list($params, $missing) = $this->readParameters($action);
         if (!empty($missing)) {
             return new MissingParametersResult($missing);
         }
         if (!$this->access->isExecutionPermitted($id, $params)) {
             return new NotPermittedResult();
         }
         $returned = $action->execute($params);
         if (is_null($returned)) {
             return new NoResult();
         } else {
             if ($returned instanceof ExecutionResult) {
                 return $returned;
             } else {
                 return new ValueResult($returned);
             }
         }
     } catch (\Exception $e) {
         return new FailedResult($e);
     }
 }
コード例 #2
0
 private function givenTheInvisibleActions(array $ids)
 {
     foreach ($ids as $id) {
         $this->actions[$id] = Mockster::of(Action::class);
         $this->registry->add($id, Mockster::mock($this->actions[$id]));
     }
 }
コード例 #3
0
 function printLinksAsDropDown()
 {
     $this->actions->add('foo', Mockster::mock(Action::class));
     $this->links->add(new IdentifierLink(\DateTime::class, 'foo', 'id'));
     $rendered = $this->renderer->render(new Identifier(\DateTime::class, 'foo-id'));
     $this->assert->contains($rendered, "DateTime\n<span class=\"caret\"></span>");
     $this->assert->contains($rendered, '<ul class="dropdown-menu">' . '<li><a class="" href="foo?id=foo-id"></a></li>' . '</ul>');
 }
コード例 #4
0
ファイル: ActionGroups.php プロジェクト: rtens/domin
 /**
  * @param string $group
  * @return Action[] indexed by ID
  * @throws \Exception
  */
 public function getActionsOf($group)
 {
     $actions = [];
     foreach ($this->groups[$group] as $id) {
         $actions[$id] = $this->actions->getAction($id);
     }
     return $actions;
 }
コード例 #5
0
ファイル: ActionPanelRenderer.php プロジェクト: rtens/domin
 private function getContent(ActionPanel $value)
 {
     $key = spl_object_hash($value);
     if (!isset($this->results[$key])) {
         $action = $this->actions->getAction($value->getActionId());
         $this->results[$key] = $action->execute($this->inflate($action->parameters(), $value->getParameters()));
     }
     return $this->results[$key];
 }
コード例 #6
0
ファイル: ListActions.php プロジェクト: rtens/domin
 private function assembleActions()
 {
     $actions = [];
     foreach ($this->actions->getAllActions() as $id => $action) {
         if ($id != WebApplication::INDEX_ACTION && $this->access->isPermitted($id)) {
             $actions[] = new ActionListItem($id, $action->caption(), $this->parser->shorten($action->description()));
         }
     }
     return $actions;
 }
コード例 #7
0
 function printLinks()
 {
     $this->renderers->add(new ElementRenderer());
     $this->renderers->add(new PrimitiveRenderer());
     $this->actions->add('foo', Mockster::mock(Action::class));
     $this->actions->add('bar', Mockster::mock(Action::class));
     $this->links->add(new ClassLink(\StdClass::class, 'foo'));
     $this->links->add(new ClassLink(\StdClass::class, 'bar'));
     $rendered = $this->tableRenderer->render(new ObjectTable([new \StdClass()], $this->types));
     $this->assert->contains($rendered, '<div class="dropdown">' . "\n" . '<button class="btn btn-xs btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . "\n" . 'stdClass' . "\n" . '<span class="caret"></span>' . "\n" . '</button>' . "\n" . '<ul class="dropdown-menu">' . "\n" . '<li><a class="" href="foo"></a></li>' . "\n" . '<li><a class="" href="bar"></a></li>' . "\n" . '</ul>' . "\n" . '</div>');
 }
コード例 #8
0
ファイル: ActionFixture.php プロジェクト: rtens/domin
 public function givenTheAction_Returning($id, $value)
 {
     $action = Mockster::of(Action::class);
     $this->actions[$id] = $action;
     $this->registry->add($id, Mockster::mock($action));
     Mockster::stub($action->execute(Argument::any()))->will()->return_($value);
     Mockster::stub($action->caption())->will()->return_(ucfirst($id));
     $this->params[$id] = [];
     Mockster::stub($action->parameters())->will()->forwardTo(function () use($id) {
         return $this->params[$id];
     });
     Mockster::stub($action->fill(Argument::any()))->will()->forwardTo(function ($params) {
         return $params;
     });
 }
コード例 #9
0
ファイル: LinkPrinter.php プロジェクト: jonfm/domin
 private function createLinks($object, $classes = '')
 {
     return array_map(function (Link $link) use($object, $classes) {
         $action = $this->actions->getAction($link->actionId());
         $url = $this->baseUrl->appended($link->actionId())->withParameters(new Map($link->parameters($object)));
         $attributes = ['class' => $classes, 'href' => $url];
         if ($link->confirm() !== null) {
             $attributes['onclick'] = "return confirm('{$link->confirm()}');";
         }
         $description = $action->description();
         if (!is_null($description)) {
             $attributes['title'] = str_replace('"', "'", strip_tags($this->parser->shorten($description)));
         }
         return new Element('a', $attributes, [$action->caption()]);
     }, $this->links->getLinks($object));
 }
コード例 #10
0
ファイル: CliApplication.php プロジェクト: jonfm/domin
 private function printActions(Console $console)
 {
     $console->writeLine('Available Actions');
     $console->writeLine('~~~~~~~~~~~~~~~~~');
     foreach ($this->actions->getAllActions() as $id => $action) {
         $console->writeLine($id . ' - ' . $action->caption() . $this->shortDescription($action));
     }
 }
コード例 #11
0
ファイル: LinkPrinter.php プロジェクト: rtens/domin
 private function createLinks($object, $classes = '')
 {
     return array_map(function (Link $link) use($object, $classes) {
         $action = $this->actions->getAction($link->actionId());
         $parameters = $link->parameters($object);
         if ($action->isModifying() && $this->token) {
             $parameters[ExecutionResource::TOKEN_ARG] = $this->token->generate($link->actionId());
         }
         $url = (string) Url::relative($link->actionId(), $parameters);
         $attributes = ['class' => $classes, 'href' => $url];
         if ($link->confirm() !== null) {
             $attributes['onclick'] = "return confirm('{$link->confirm()}');";
         }
         $description = $action->description();
         if (!is_null($description)) {
             $attributes['title'] = str_replace('"', "'", strip_tags($this->parser->shorten($description)));
         }
         return new Element('a', $attributes, [$action->caption()]);
     }, $this->links->getLinks($object));
 }
コード例 #12
0
ファイル: ObjectRendererSpec.php プロジェクト: rtens/domin
 function confirmActions()
 {
     $this->renderers->add(new PrimitiveRenderer());
     $link = Mockster::of(Link::class);
     $this->links->add(Mockster::mock($link));
     $this->actions->add('', Mockster::mock(Action::class));
     Mockster::stub($link->handles(Argument::any()))->will()->return_(true);
     Mockster::stub($link->confirm())->will()->return_('Foo?');
     $object = new \StdClass();
     $object->foo = 'bar';
     $this->assert->contains($this->renderer->render($object), '<a class="btn btn-xs btn-primary" href="" onclick="return confirm(\'Foo?\');"></a>');
 }
コード例 #13
0
ファイル: ActionField.php プロジェクト: rtens/domin
 /**
  * @param Parameter $parameter
  * @return array|\rtens\domin\delivery\web\Element[]
  */
 public function headElements(Parameter $parameter)
 {
     $action = $this->actions->getAction($parameter->getName());
     $headElements = [self::descriptionCode()];
     foreach ($action->parameters() as $parameter) {
         $field = $this->fields->getField($parameter);
         if ($field instanceof WebField) {
             $headElements = array_merge($headElements, $field->headElements($parameter));
         }
     }
     return $headElements;
 }
コード例 #14
0
ファイル: TableRendererSpec.php プロジェクト: jonfm/domin
 function printLinks()
 {
     $this->renderers->add(new ElementRenderer());
     $this->renderers->add(new PrimitiveRenderer());
     $this->actions->add('foo', Mockster::mock(Action::class));
     $this->actions->add('bar', Mockster::mock(Action::class));
     $this->actions->add('baz', Mockster::mock(Action::class));
     $this->links->add(new GenericLink('foo', function ($item) {
         return $item['id'] == 'foo item';
     }));
     $this->links->add(new GenericLink('bar', function ($item) {
         return $item['id'] == 'bar item';
     }));
     $this->links->add(new GenericLink('baz', function ($item) {
         return $item['id'] == 'bar item';
     }));
     $rendered = $this->tableRenderer->render(new ArrayTable([['id' => 'foo item'], ['id' => 'bar item']]));
     $this->assert->contains($rendered, '<div class="dropdown">' . "\n" . '<button class="btn btn-xs btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . "\n" . 'Actions' . "\n" . '<span class="caret"></span>' . "\n" . '</button>' . "\n" . '<ul class="dropdown-menu">' . '<li><a class="" href="http://example.com/base/foo"></a></li>' . '</ul>' . "\n" . '</div>' . "\n" . '</td>' . "\n" . '<td>foo item</td>');
     $this->assert->contains($rendered, '<div class="dropdown">' . "\n" . '<button class="btn btn-xs btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . "\n" . 'Actions' . "\n" . '<span class="caret"></span>' . "\n" . '</button>' . "\n" . '<ul class="dropdown-menu">' . "\n" . '<li><a class="" href="http://example.com/base/bar"></a></li>' . "\n" . '<li><a class="" href="http://example.com/base/baz"></a></li>' . "\n" . '</ul>' . "\n" . '</div>' . "\n" . '</td>' . "\n" . '<td>bar item</td>');
 }
コード例 #15
0
ファイル: WebApplication.php プロジェクト: jonfm/domin
 public function prepare(WebRequest $request)
 {
     $this->registerRenderers($request->getContext());
     $this->registerFields();
     $this->actions->restrictAccess($this->getAccessControl($request));
 }
コード例 #16
0
ファイル: ShowMenuSpec.php プロジェクト: rtens/domin
 private function givenTheAction($id)
 {
     $this->actions->add($id, Mockster::mock(Mockster::of(Action::class)));
 }
コード例 #17
0
ファイル: WebApplication.php プロジェクト: rtens/domin
 private function registerDefaultAction()
 {
     $this->actions->add(self::INDEX_ACTION, new ListActions($this->actions, $this->groups, $this->access, $this->parser));
 }
コード例 #18
0
    function generateFromMethods()
    {
        eval('class ClassWithSomeMethods {
            /**
             * @param string $one
             * @param null|string $two
             */
            function doThis($one, $two = "default") {
                return $one . ":" . $two;
            }

            function doThat() {
                return "foo";
            }

            function _notMe() {}

            protected function notThis() {}

            static function neitherThis() {}
        }');
        /** @noinspection PhpUndefinedClassInspection */
        $object = new \ClassWithSomeMethods();
        $actions = new ActionRegistry();
        (new MethodActionGenerator($actions, new TypeFactory(), new CommentParser()))->fromObject($object)->configure($object, 'doThis', function (GenericMethodAction $action) {
            $action->generic()->setFill(function ($p) {
                $p['one'] = 'foo';
                return $p;
            })->setDescription('My description')->setCaption('My caption')->mapParameter('one', function (Parameter $one) {
                return new Parameter('one', new ArrayType($one->getType()));
            });
        })->configure($object, 'doThat', function (GenericMethodAction $action) {
            $action->generic()->setAfterExecute(function ($s) {
                return $s . '!';
            })->setCaption('That');
        });
        $this->assert->size($actions->getAllActions(), 2);
        $doThis = $actions->getAction('ClassWithSomeMethods~doThis');
        $this->assert($doThis->description(), 'My description');
        $this->assert($doThis->caption(), 'My caption');
        $this->assert($doThis->execute(['one' => 'foo', 'two' => 'bar']), 'foo:bar');
        $this->assert($doThis->fill(['one' => 'bar']), ['one' => 'foo', 'two' => 'default']);
        $this->assert($doThis->parameters()[0], new Parameter('one', new ArrayType(new StringType())));
        $doThat = $actions->getAction('ClassWithSomeMethods~doThat');
        $this->assert($doThat->description(), '');
        $this->assert($doThat->execute([]), 'foo!');
        $this->assert($doThat->caption(), 'That');
    }
コード例 #19
0
ファイル: ListActionSpec.php プロジェクト: jonfm/domin
 private function whenIListTheActions()
 {
     $this->actions = $this->registry->getAllActions();
 }