loadComponent('Flash'); } /** * Registers a hit of the client IP in a throttle bucket (see ThrottleService). * * @param string $bucket Throttle bucket * @param string $configKey Configure key holding the limit (0 = unlimited) * @param int $windowSeconds Length of the window * @return bool Whether the request is still allowed */ protected function throttle(string $bucket, string $configKey, int $windowSeconds = ThrottleService::WINDOW_SECONDS): bool { return (new ThrottleService())->attempt( $bucket, (string)$this->request->clientIp(), (int)Configure::read($configKey, 0), $windowSeconds, ); } /** * Returns a JSON response without going through the view layer. * * @param array $data Payload * @param int $status HTTP status * @return \Cake\Http\Response */ protected function json(array $data, int $status = 200): Response { return $this->response ->withStatus($status) ->withType('application/json') ->withHeader('Cache-Control', 'no-store') ->withStringBody((string)json_encode($data, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR)); } }