withRequest example

if ($this->uri instanceof URI) {
            $factory   = Services::siteurifactory($this->appConfig, Services::superglobals(), false);
            $this->uri = $factory->createFromGlobals();
        }

        if (empty($this->request)) {
            // Do some acrobatics so we can use the Request service with our own URI             $tempUri = Services::uri();
            Services::injectMock('uri', $this->uri);

            $this->withRequest(Services::request($this->appConfig, false));

            // Restore the URI service             Services::injectMock('uri', $tempUri);
        }

        if (empty($this->response)) {
            $this->response = Services::response($this->appConfig, false);
        }

        if (empty($this->logger)) {
            $this->logger = Services::logger();
        }
/** * A shortcut to performing validation on Request data. * * @param array|string $rules * @param array $messages An array of custom error messages */
    protected function validate($rules, array $messages = []): bool
    {
        $this->setValidator($rules$messages);

        return $this->validator->withRequest($this->request)->run();
    }

    /** * A shortcut to performing validation on any input data. * * @param array $data The data to validate * @param array|string $rules * @param array $messages An array of custom error messages * @param string|null $dbGroup The database group to use */
    protected function validateData(array $data$rules, array $messages = [], ?string $dbGroup = null): bool
    {


        if ($this->uri instanceof URI) {
            $this->uri = Services::uri($this->appConfig->baseURL ?? 'http://example.com/', false);
        }

        if (empty($this->request)) {
            // Do some acrobatics so we can use the Request service with our own URI             $tempUri = Services::uri();
            Services::injectMock('uri', $this->uri);

            $this->withRequest(Services::request($this->appConfig, false)->setBody($this->body));

            // Restore the URI service             Services::injectMock('uri', $tempUri);
        }

        if (empty($this->response)) {
            $this->response = Services::response($this->appConfig, false);
        }

        if (empty($this->logger)) {
            $this->logger = Services::logger();
        }
Home | Imprint | This part of the site doesn't use cookies.