# src/Controller/UserController
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class UserController
{
public function create(Request $request): Response
{
$email = (string) $request->request->get('email');
$password = (string) $request->request->get('password');
// ... pass $email and $password to relevant services, build and return a response
}
}
# src/Request/CreateUserRequest.php
namespace App\Request;
use Symfony\Component\HttpFoundation\Request;
use webignition\EncapsulatingRequestResolverBundle\Model\EncapsulatingRequestInterface;
class CreateUserRequest implements EncapsulatingRequestInterface
{
public function __construct(private string $email, private string $password)
{
}
public static function create(Request $request): CreateUserRequest
{
return new CreateUserRequest(
(string) $request->request->get('email'),
(string) $request->request->get('password')
);
}
public function getEmail(): string
{
return $this->email;
}
public function getPassword(): string
{
return $this->password;
}
}
# src/Controller/UserController
namespace App\Controller;
use App\Request\CreateUserRequest;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class UserController
{
public function create(CreateUserRequest $request): Response
{
$email = $request->getEmail();
$password = $request->getPassword());
// ... pass $email and $password to relevant services, build and return a response
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.