{"record":{"id":"a7e724dbdbfb8b90","repo":"phalcon/cphalcon","slug":"a-dependency-injection-container-is-required-to-ac-a7e724","errorCode":null,"errorMessage":"A dependency injection container is required to access the 'response' service","messagePattern":"A dependency injection container is required to access the 'response' service","errorType":"exception","errorClass":"Phalcon\\Http\\Response\\Exceptions\\ResponseServiceUnavailable","httpStatus":null,"severity":"error","filePath":"phalcon/Http/Response/Cookies.zep","lineNumber":357,"sourceCode":"\n    /**\n     * Set if cookies in the bag must be automatically encrypted/decrypted\n     */\n    public function useEncryption(bool useEncryption) -> <CookiesInterface>\n    {\n        let this->useEncryption = useEncryption;\n\n        return this;\n    }\n\n    private function checkGetContainer() -> <DiInterface>\n    {\n        var container;\n\n        let container = this->container;\n\n        if container === null {\n            throw new ResponseServiceUnavailable();\n        }\n\n        return container;\n    }\n}\n","sourceCodeStart":339,"sourceCodeEnd":363,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Http/Response/Cookies.zep#L339-L363","documentation":"Http\\Response\\Cookies::checkGetContainer() throws ResponseServiceUnavailable when the cookies manager has no DI container. The manager needs the container internally (e.g. to resolve the response and crypt services) when cookies are set or sent, so a container-less Cookies object cannot work.","triggerScenarios":"$cookies = new Cookies(); $cookies->set('name', 'value')->send(); without ever calling setDI(); registering a replacement 'cookies' service as a bare instance that never receives the container.","commonSituations":"Manually constructed Cookies managers in tests or CLI workers; overriding the 'cookies' DI service with new Cookies instead of a container-resolved definition; using Cookies outside the full application lifecycle.","solutions":["Call $cookies->setDI($di) before setting or sending cookies","Use the shared 'cookies' service from FactoryDefault, which receives the container automatically","When registering a replacement, let DI construct it: $di->setShared('cookies', \\Phalcon\\Http\\Response\\Cookies::class);"],"exampleFix":"// before\n$cookies = new \\Phalcon\\Http\\Response\\Cookies();\n$cookies->set('theme', 'dark')->send(); // throws: no container\n\n// after\n$di = new \\Phalcon\\Di\\FactoryDefault();\n$cookies = new \\Phalcon\\Http\\Response\\Cookies();\n$cookies->setDI($di);\n$cookies->set('theme', 'dark')->send();","handlingStrategy":"validation","validationCode":"if (null === $cookies->getDI() && null === \\Phalcon\\Di\\Di::getDefault()) {\n    throw new \\RuntimeException('Cookies manager needs a DI container: call setDI()');\n}\n$cookies->set('name', 'value')->send();","typeGuard":null,"tryCatchPattern":"try { $cookies->send(); } catch (\\Phalcon\\Http\\Response\\Exceptions\\ResponseServiceUnavailable $e) { // wiring bug: attach container and retry\n    $cookies->setDI($di);\n    $cookies->send();\n}","preventionTips":["Use the shared 'cookies' service instead of new Cookies()","When overriding the service, let DI construct the instance so injection happens","Cover cookie sending in tests with a booted FactoryDefault container"],"tags":["php","phalcon","cookies","dependency-injection","response"],"backgroundTag":"missing-di-container","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}