1. Go to this page and download the library: Download dhii/services 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/ */
function (ContainerInterface $c) {
$dep1 = $c->get('dep1');
if (!is_int($dep1)) {
throw new TypeError(sprintf('Parameter $dep1 must be of type int; %1$s given', is_object($dep1) ? get_class($dep1) : gettype($dep1));
}
$dep2 = $c->get('dep2');
if (!($dep2 instanceof SomeInterface)) {
throw new TypeError(sprintf('Parameter $dep2 must be of type int; %1$s given', is_object($dep2) ? get_class($dep2) : gettype($dep2));
}
// ...
}
new Extension(['dep1', 'dep2'], function($prev, $dep1, $dep2) {
// ...
});
function (ContainerInterface $c) {
$dep1 = $c->get('dep1');
$dep2 = $c->get('dep2');
return function ($arg1, $arg2) use ($dep1, $dep2) {
// ...
};
}
$service = new Factory(['database'], function ($database) {
// ...
});
$service2 = $service->withDependencies(['db']);
class LoggerProvider implements ServiceProviderInterface
{
public function getFactories()
{
return [
'logger' => new Constructor(FileLogger::class, ['file_path']),
'file_path' => new Value(sys_get_tmp_dir() . '/log.txt')
];
}
public function getExtensions ()
{
return [];
}
}
class PrefixingProvider implements ServiceProviderInterface {
public function getFactories() {
$factories = [];
foreach ($this->provider->getFactories() as $key => $factory) {
$deps = $factory->getDependencies();
$newDeps = array_map(fn($dep) => $this->prefix . $dep, $deps);
$factories[$this->prefix . $key] = $factory->withDependencies($newDeps);
}
return $factories;
}
}
$debugLogProvider = new PrefixingProvider('debug_', new LoggerProvider);
$errorLogProvider = new PrefixingProvider('error_', new LoggerProvider);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.