request-model icon indicating copy to clipboard operation
request-model copied to clipboard

Why does method RequestModelFactory::getRequestData() return an array and not a DTO?

Open lav45 opened this issue 2 years ago • 3 comments

namespace Yiisoft\RequestModel;

final class RequestModelFactory
{
    private function getRequestData(ServerRequestInterface $request): array
    {
        return [
            'query' => $request->getQueryParams(),
            'body' => $request->getParsedBody(),
            'attributes' => $request->getAttributes(),
            'headers' => $request->getHeaders(),
            'files' => $request->getUploadedFiles(),
            'cookie' => $request->getCookieParams(),
            'router' => $this->currentRoute->getArguments(),
        ];
    }
}

lav45 avatar Jan 03 '23 21:01 lav45

What's the benefit of using DTO here?

samdark avatar Jan 07 '23 20:01 samdark

The transparency

  • of the IDE code will quickly show where the value was set
  • the entire list of properties is visible

lav45 avatar Jan 07 '23 20:01 lav45

I like this idea.

vjik avatar Jan 08 '23 17:01 vjik