Aura\Di container locked exception question

19 views
Skip to first unread message

Chris Johnson

unread,
Sep 26, 2016, 1:44:40 PM9/26/16
to The Aura Project for PHP
Why does the following code throw an exception, but does not throw it if I comment out the first ini_set() and comment in the second.  In both cases, I am not changing the container, although in the first error-causing version, I am getting a value from it.  

The exception message is: "exception 'Aura\Di\Exception\ContainerLocked' with message 'Cannot modify container when locked.'"

```php
<?php


use Aura\Di\Container;
use Aura\Di\ContainerConfig;
use Clx\ConfigIni;


class _Config extends ContainerConfig
{
   
public function define(Container $di)
   
{
       
// read key/value pairs out of configuration file.
        $config
= new ConfigIni('local', 'dev.ini');
       
foreach ($config->getAll() as $key => $val) {
            $di
->values[$key] = $val;
       
}
   
}


   
public function modify(Container $di)
   
{
        ini_set
('session.cookie_domain', $di->values['cookie_domain']);
       
// ini_set('session.cookie_domain', 'localhost');
   
}
}

```

Hari K T

unread,
Sep 27, 2016, 12:40:17 AM9/27/16
to aur...@googlegroups.com
Hi Chris,
I probably don't know what may be the reason for accessing config values is restricted.

But this is where it cause the problem 


Alternative way is call getInjectionFactory  : 


and call  getResolver 


Now you have full access to read these properties from resolver .


So here is the code that should work.

$di->getInjectionFactory()->getResolver()->values['cookie_domain']

Hope that helps to resolve your issue.

Thank you
Reply all
Reply to author
Forward
0 new messages