Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ADF-660/ParamConverter #3148

Draft
wants to merge 22 commits into
base: develop
Choose a base branch
from
Draft

Conversation

shpran
Copy link
Contributor

@shpran shpran commented Sep 29, 2021

ADF-660

Examples

Method: GET
URL: extension/SomeController/someAction?uri=someUri&value=someValue&data[uri]=anotherUri&data[value]=anotherValue

Old code
class SomeController
{
    public function someAction(): void
    {
        $uri = $this->getGetParameter('uri', '');
        $value = $this->getGetParameter('value', 0);

        $this->someMethod($uri, $value);

        $data = $this->getGetParameter('data', []);
        $dataUri = $data['uri'] ?? null;
        $dataValue = $data['value'] ?? null;

        $this->anotherMethod($dataUri, $dataValue);
    }

    private function someMethod(string $uri, int $value): void
    {
        ... code ...
    }

    private function anotherMethod(?string $uri, ?string $value): void
    {
        ... code ...
    }
}
New code
use TestClass;
use AnotherClass;
use oat\tao\model\ParamConverter\Configuration\ParamConverter;

class SomeController
{
    /**
     * @ParamConverter("class", converter="oat.tao.param_converter.query")
     */
    public function someAction(TestClass $class): void
    {
        $this->someMethod($class);
        $this->anotherMethod($class->getData())
    }

    private function someMethod(TestClass $class): void
    {
        ... code ...
    }

    private function anotherMethod(AnotherClass $anotherClass): void
    {
        ... code ...
    }
}
use AnotherClass;

class TestClass
{
    /** @var string */
    private $uri;

    /** @var int */
    private $value;

    /** @var AnotherClass */
    private $data;

    public function __construct(string $uri, int $value)
    {
        $this->uri = $uri;
        $this->value = $value;
    }

    public function getUri(): string
    {
        return $this->uri;
    }

    public function getValue(): int
    {
        return $this->value;
    }

    public function getData(): AnotherClass
    {
        return $this->data;
    }

    public function setData(AnotherClass $anotherClass): void
    {
        $this->data = $anotherClass;
    }
}
class AnotherClass
{
    /** @var string/null */
    private $uri;

    /** @var string|null */
    private $value;

    public function getUri(): ?string
    {
        return $this->uri;
    }

    public function setUri(string $uri): void
    {
        $this->uri = $uri;
    }

    public function getValue(): ?string
    {
        return $this->value;
    }

    public function setValue(string $value): void
    {
        $this->value = $value;
    }
}

Require PRs

Tasks

  • Add unit tests
  • Add / Update README.md
  • Update composer.json dependencies

@shpran shpran marked this pull request as draft September 29, 2021 13:35
@shpran shpran force-pushed the feature/adf-660/param-converter branch from 1f1ca97 to 9046d66 Compare September 29, 2021 21:17
Copy link
Contributor

@gabrielfs7 gabrielfs7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good initiative! Good job 🚀

@shpran shpran force-pushed the feature/adf-660/param-converter branch from 8b6f5d9 to acf7b8e Compare September 30, 2021 15:50
@shpran shpran force-pushed the feature/adf-660/param-converter branch from e190469 to ea2543f Compare October 13, 2021 16:50
@shpran shpran force-pushed the feature/adf-660/param-converter branch from ea2543f to 09f10f2 Compare October 13, 2021 16:52
actions/class.TestAction.php Outdated Show resolved Hide resolved
@github-actions
Copy link

Version

Target Version 50.7.0
Last version 50.6.1

There are 0 BREAKING CHANGE, 2 features, 0 fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants