1414class Configurator {
1515
1616 public static function getContainer (array $ config ) {
17+ // Object Retriever Definition
18+ $ objectRetrieverDefinition = DI \autowire ();
19+ $ orConstructorParameters = [
20+ 'cache_provider ' => 'file ' ,
21+ 'cache_provider.file.directory ' => $ config ['cache_dir ' ] . '/config ' ,
22+ 'static_config_path ' => $ config ['uploads_dir ' ] . '/config ' ,
23+ 'logger ' => DI \get (Logger::class)
24+ ];
25+
26+ if (!isset ($ config ['co.auth_ns ' ]) && CredentialManager::isConfigured ()) {
27+ // Access Object API via Account Gateway using local developer account
28+ $ objectRetrieverDefinition ->constructor ($ orConstructorParameters )
29+ ->method ('setClient ' , function () {
30+ return CredentialManager::getAccountContext ()->getClient ();
31+ }, '/ws/ ' );
32+ } else {
33+ // Access Object API with specified namespace credentials
34+ $ objectRetrieverDefinition ->constructor (array_merge ([
35+ 'auth_ns ' => $ config ['co.auth_ns ' ],
36+ 'auth_secret ' => $ config ['co.auth_secret ' ],
37+ ], $ orConstructorParameters ));
38+ }
39+
1740 // Create Dependency Injection Container
1841 $ builder = new DI \ContainerBuilder ();
1942 $ builder ->addDefinitions ($ config );
@@ -32,22 +55,14 @@ public static function getContainer(array $config) {
3255 }
3356 return $ logger ;
3457 },
58+ ObjectRetriever::class => $ objectRetrieverDefinition ,
3559 ObjectRetrieverPool::class => DI \autowire ()
36- ->constructorParameter ('baseHostname ' , $ config ['co.auth_ns ' ])
60+ ->constructorParameter ('baseHostname ' , @ $ config ['co.auth_ns ' ])
3761 ->constructorParameter ('options ' , [
3862 'cache_provider ' => 'file ' ,
3963 'cache_provider.file.directory ' => $ config ['cache_dir ' ] . '/config ' ,
4064 'static_config_path ' => $ config ['uploads_dir ' ] . '/config ' ,
4165 'logger ' => DI \get (Logger::class)
42- ]),
43- ObjectRetriever::class => DI \autowire ()
44- ->constructor ([
45- 'auth_ns ' => $ config ['co.auth_ns ' ],
46- 'auth_secret ' => $ config ['co.auth_secret ' ],
47- 'cache_provider ' => 'file ' ,
48- 'cache_provider.file.directory ' => $ config ['cache_dir ' ] . '/config ' ,
49- 'static_config_path ' => $ config ['uploads_dir ' ] . '/config ' ,
50- 'logger ' => DI \get (Logger::class)
5166 ])
5267 ]);
5368
0 commit comments