1. Go to this page and download the library: Download wondernetwork/slim-kernel 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/ */
wondernetwork / slim-kernel example snippets
use WonderNetwork\SlimKernel\KernelBuilder;
use WonderNetwork\SlimKernel\ServiceFactory\SymfonyConsoleServiceFactory;
use WonderNetwork\SlimKernel\StartupHook\RoutesStartupHook;
// configure the container:
$container = KernelBuilder::start(
// all the paths will be calculated relative to this one
__DIR__.'/..',
)
// just add inline definitions if you’d like
->add([
'environment' => $environment
])
// specify a directory or directories to search definition files in
->glob(
// ->onStartup(
// automatically add routes
new RoutesStartupHook(__DIR__.'/../app/routes/*.php'),
)
// only pass a path for prod environments, null otherwise
->useCache(__DIR__.'/../.cache')
->build();
// get the slim application from the container
$app = $container->get(Slim\App::class)
$app->run();
// given it’s configured:
// $kernelBuilder->glob('app/services/*.php');
// next, in app/services/some.php:
use Psr\Container\ContainerInterface;
return [
'foo.scalar.dependency' => 10,
FooService::class => fn (ContainerInterface $container) => new FooService(
$container->get(FooDependency::class),
$container->get('foo.scalar.dependency'),
),
];
$kernelBuilder->onStartup(
new \WonderNetwork\SlimKernel\StartupHook\RoutesStartupHook(
__DIR__.'/../routes/*.php',
),
);
// app/routes/some.php
use Psr\Http\Message\ResponseInterface;
return static function (Slim\App $app) {
$app->get('/hello/{message}', function (ResponseInterface $response, string $message) {
return $response->withHeader("X-Hello", $message);
});
}
// somewhere in app/services/test/errors.php
use WonderNetwork\SlimKernel\SlimExtension\ErrorMiddlewareConfiguration as Configuration;
return [
Configuration::class => static fn () => Configuration::verbose();
];
// app/services/cli.php
return new WonderNetwork\SlimKernel\ServiceFactory\SymfonyConsoleServiceFactory(
// glob to find command files
__DIR__.'/../../src/Cli/**/*Command.php',
// name for your symfony console application
'acme v1.0',
);
// HTTP
$requestParams = WonderNetwork\SlimKernel\Http\RequestParams::of($serverRequest);
$requestParams->post->ing, but you can still cast them to ints
$routeArguments = WonderNetwork\SlimKernel\Http\RouteArgument::of($serverRequest);
$routeArguments->string('token');
$routeArguments->int('limit', 10);
// CLI
$cliParams = WonderNetwork\SlimKernel\Cli\InputParams::ofInput($input);
$cliParams->options
$cliParams->arguments
public function execute(InputInterface $input, OutputInterface $output): int {
return FingersCrossedHandler::of($input, $output)->run(
function (InputParams $input, FingersCrossedOutput $output) {
$output->write("Hello world!")
return 1;
},
);
}
public function __invoke(#[WonderNetwork\SlimKernel\Http\Serializer\Payload] MyDto $input) {}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.