PHP code example of tueena-lib / dependency-injection
1. Go to this page and download the library: Download tueena-lib/dependency-injection library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tueena-lib / dependency-injection example snippets
use tueenaLib\dependencyInjection\ServiceLocator;
// The ServiceLocator is immutable. So the register*() methods will return new instances of
// the ServiceLocator on each call.
$serviceLocator = (new ServiceLocator)
// Define a concrete class.
// The constructor of the class may on $configuration) { return new SomeApi($configuration->getApiKey()); })
;
// The ServiceLocator provides two more methods, but you probably will never use them.
// Use the injector instead.
if ($serviceLocator->has(MyMailer::class))
$myMailer = $serviceLocator->get(MyMailer::class);
// The get() method throws an exception, if the service is not registered.