{"action":"created","issue":{"url":"https://api.github.com/repos/slimphp/Slim/issues/1465","labels_url":"https://api.github.com/repos/slimphp/Slim/issues/1465/labels{/name}","comments_url":"https://api.github.com/repos/slimphp/Slim/issues/1465/comments","events_url":"https://api.github.com/repos/slimphp/Slim/issues/1465/events","html_url":"https://github.com/slimphp/Slim/issues/1465","id":103243511,"number":1465,"title":"Most of container variables appear to be \"frozen\" even before app run. ","user":{"login":"yurevichcv","id":67401,"avatar_url":"https://avatars.githubusercontent.com/u/67401?v=3","gravatar_id":"","url":"https://api.github.com/users/yurevichcv","html_url":"https://github.com/yurevichcv","followers_url":"https://api.github.com/users/yurevichcv/followers","following_url":"https://api.github.com/users/yurevichcv/following{/other_user}","gists_url":"https://api.github.com/users/yurevichcv/gists{/gist_id}","starred_url":"https://api.github.com/users/yurevichcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yurevichcv/subscriptions","organizations_url":"https://api.github.com/users/yurevichcv/orgs","repos_url":"https://api.github.com/users/yurevichcv/repos","events_url":"https://api.github.com/users/yurevichcv/events{/privacy}","received_events_url":"https://api.github.com/users/yurevichcv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":22,"created_at":"2015-08-26T11:32:09Z","updated_at":"2015-08-26T12:24:54Z","closed_at":null,"body":"This issue is caused by PR #1443\r\n\r\nUnfortunately, this PR doesn't have backward compatibility. Before I was able to \"override\" container values before `$app->run()`. \r\n\r\nBefore I was able to do the following in unit tests:\r\n```\r\n$app = new \\Slim\\App();\r\n\r\nConfigurator::configureApp($app); //seudo-code\r\n\r\n$c = $app->getContainer();\r\n$c['environment'] = $c->factory(function ($c) {\r\n....\r\n});\r\n$c['request'] = $c->factory(function ($c) {\r\n....\r\n});\r\n```\r\nNow it is not possible, getting following error:\r\n```\r\nRuntimeException : Cannot override frozen service \"environment\".\r\n``` \r\n\r\nAnd main problem is that now you freeze almost all container variables during router initialisation:\r\n\r\nBefore it was (worked perfectly):\r\n```\r\n $this['router'] = function ($c) {\r\n     return new Router();\r\n};\r\n```\r\n\r\nNot it is:\r\n```\r\nif (!isset($this['router'])) {\r\n            $this['router'] = function ($c) {\r\n                $router = new Router();\r\n\r\n                $uri = $c['request']->getUri();\r\n\r\n                if (is_callable([$uri, 'getBasePath'])) {\r\n                    $router->setBasePath($uri->getBasePath());\r\n                }\r\n\r\n                return $router;\r\n            };\r\n}\r\n```\r\n\r\nAs you can see, now you access $c['request'], which automatically freezes almost all essential components in container.\r\n\r\nMain idea is that essential container components, such as `environment`, `request` and `response` should not be frozen before app run.\r\n\r\nUse case:\r\n1. I want to configure my application (including all routes, acl, domain services, etc)\r\n2. Save it to static property or to cache.\r\n3. Override container's `environment`, `request` and `response` with factories.\r\n4. Run many tests against the same instance of application."},"comment":{"url":"https://api.github.com/repos/slimphp/Slim/issues/comments/134982689","html_url":"https://github.com/slimphp/Slim/issues/1465#issuecomment-134982689","issue_url":"https://api.github.com/repos/slimphp/Slim/issues/1465","id":134982689,"user":{"login":"yurevichcv","id":67401,"avatar_url":"https://avatars.githubusercontent.com/u/67401?v=3","gravatar_id":"","url":"https://api.github.com/users/yurevichcv","html_url":"https://github.com/yurevichcv","followers_url":"https://api.github.com/users/yurevichcv/followers","following_url":"https://api.github.com/users/yurevichcv/following{/other_user}","gists_url":"https://api.github.com/users/yurevichcv/gists{/gist_id}","starred_url":"https://api.github.com/users/yurevichcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yurevichcv/subscriptions","organizations_url":"https://api.github.com/users/yurevichcv/orgs","repos_url":"https://api.github.com/users/yurevichcv/repos","events_url":"https://api.github.com/users/yurevichcv/events{/privacy}","received_events_url":"https://api.github.com/users/yurevichcv/received_events","type":"User","site_admin":false},"created_at":"2015-08-26T12:24:54Z","updated_at":"2015-08-26T12:24:54Z","body":"@akrabat You solution works, but the code now is little bit smelly.\r\n\r\nThis is solution that is much better from architectural point of view:\r\n```\r\nif (!isset($this['router'])) {\r\n    $this['router'] = function ($c) {\r\n        $router = new Router();\r\n        if (isset($c['settings']['basePath']))) {\r\n            $router->setBasePath($c['settings']['basePath']);\r\n        }\r\n\r\n        return $router;\r\n    };\r\n}\r\n```"}}