Answer the question
In order to leave comments, you need to log in
What is the best practice for loading third party files in a function?
Good evening.
What is the best way to load a php file in a function? Some config is assumed, for example:
$config = [
'test' => 'test'
];
return $config;
Answer the question
In order to leave comments, you need to log in
function test(){
$container = &container_instance();//singliton
$config = $container->get('config');
}
namespace Acme\ServiceProvider;
use League\Container\ServiceProvider\AbstractServiceProvider;
class ConfigProvider extends AbstractServiceProvider
{
protected $provides = [
'config'
];
public function register()
{
$this->getContainer()->add('config', function(){
return [
'test' => 'test'
];
});
}
}
and I just did it differently:
$arr = json_decode(file_get_contents());
$app = Framework::init();
$app->config = array_merge($app->config, $arr);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question