I am learning Auraphp Di, and I want to write sample code. Suppose I have these files:
public/index.php:
use Aura\Di\ContainerBuilder;
use MyPackage\Component\Authentication\AuthenticateFlow;
require_once dirname(__DIR__) . '/vendor/autoload.php';
$builder = new ContainerBuilder();
$di = $builder->newInstance();
$di->set('authenticateFlow', $di->lazyNew(AuthenticateFlow::class));
$authenticateFlow = $di->get('authenticateFlow');
$authenticateFlow->showName('Belkin');
/src/Components/Authentication/AuthenticationFlow.php:
namespace MyPackage\Components\Authentication;
class AuthenticationFlow
{
public function showName($name)
{
echo $name;
}
}
This is working fine. Now suppose I have another class (/src/Components/Authentication/Filter.php), which has a method called filterInput:
namespace MyPackage\Components\Authentication;
class Filter
{
public function filterInput($input)
{
return htmlspecialchars($input);
}
}
How can I inject Filter to AuthenticationFlow, to use filterInput() method? I wanna have something like this in AuthenticationFlow::showName():
echo $this->filter->filterInput($name);
I am aware that I need to inject Filter class in AuthenticationFlow constructor, but I don't know if I can use the container built in the index.php or not. If I need to create another container in AuthenticationFlow, how index.php would be aware of it?