1. Go to this page and download the library: Download pmjones/caplet 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/ */
pmjones / caplet example snippets
use Caplet\Caplet;
$caplet = new Caplet();
namespace Foo;
class Bar
{
public function __construct(
protected string $bar,
protected string $baz
) {
}
}
use Caplet\Caplet;
use Foo\Bar;
$caplet = new Caplet([
Bar::class => [
'bar' => 'bar-value',
'baz' => 'baz-value',
];
]);
$bar = $caplet->get(Bar::class);
namespace Project;
use Caplet\Caplet;
class ProjectCaplet extends Caplet
{
public function __construct(array $env)
{
parent::__construct([
Foo::class => [
'bar' => $env['BAR_VALUE'],
'baz' => $env['BAZ_VALUE'],
],
]);
}
}
namespace Project;
use Caplet\Caplet;
use Project\Log\Logger;
use Psr\Log\LoggerInterface;
class ProjectCaplet extends Caplet
{
public function __construct(
string $bar,
string $baz,
) {
parent::__construct([
Foo::class => [
'bar' => 'bar-value',
'baz' => 'baz-value',
],
]);
$this->factory(
LoggerInterface::class,
fn (Caplet $caplet) => $caplet->get(Logger::class)
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.