I have a class that will manage some of my dependencies. I want it to be called before any method is called in the controller , and for this I am using hooks . The problem is that I do not know how to call this object that has already been instantiated in hook in my controller methods. How could I do that? Here's how it is:
In I'm using this configuration:
$hook['post_controller_constructor'][] = array(
'class' => 'DependencyInjection',
'function' => 'initContainer',
'filename' => 'DependencyInjection.php',
'filepath' => 'hooks');
And the dependencia.php
file looks like this:
<?php
use Pimple\Container;
$container = new Container();
$container['guzz'] = function($c) {
return new GuzzleHttp\Client();
};
hook was created like this:
<?php
class DependencyInjection {
public $container;
public function initContainer () {
return $this->container = require_once '/var/www/projetoSize/dependencia.php';
}
}
I want to use this in my controller like this:
class Teste extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
var_dump($this->guzz);
}
}
But it is giving an error with the following message:
Message: Undefined property: Test :: $ guzz