Get support for mnapoli/procedure
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
mnapoli/procedure
Procedure
Standard project layout:
app/
Config/
routing.yml
Controller/
home.php
View/
home.html.twig
web/
index.php
Routing configuration example:
homepage:
path: /
defaults: { _controller: MyApp\Controller\home() }
Controller:
<?php
namespace MyApp\Controller;
function home(Request $request, ResponseHelper $helper)
{
return $helper->render('home.html.twig');
}
Dependency injection in the controller
PHP-DI is used for dependency injection in the function's parameters:
function home(Request $request, MyService $service)
{
}
You can inject:
- the request by type-hinting the parameter with Symfony's request object (
Symfony\Component\HttpFoundation\Request
) - a request parameter by naming your function parameter like the request parameter
- a service from the container, by type-hinting the parameter with the class name
Getting started
This project is just an experiment, so this is not really serious stuff (for now at least).
To use it, require "mnapoli/procedure"
in composer, and then here is an example of a front controller (web/index.php
):
// Create and configure the container (see PHP-DI's documentation)
$builder = new ContainerBuilder();
$container = $builder->build();
$request = Request::createFromGlobals();
$eventDispatcher = new EventDispatcher();
// Routing
$locator = new FileLocator(array(__DIR__ . '/../app/'));
$context = new RequestContext();
$context->fromRequest($request);
$router = new Router(
new YamlFileLoader($locator),
'routing.yml',
array(),
$context
);
$eventDispatcher->addSubscriber(new RouterListener());
// Configure the HttpKernel
$resolver = new FunctionControllerResolver($container, new PSR4FunctionLoader());
$kernel = new HttpKernel($eventDispatcher, $resolver);
// Handle the request
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
(this is just a mock up, not tested)
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2