Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x - App Factory & ServerRequest Creator Auto-Detection #2646

Merged
merged 11 commits into from Apr 21, 2019

Conversation

l0gicgate
Copy link
Member

@l0gicgate l0gicgate commented Apr 21, 2019

This PR introduces AppFactory which enables you to create an app without having to create ResponseFactory and also gives the ability to the end user to run the app without having to manually create a ServerRequest given that they have installed one of the supported PSR-7 implementations / ServerRequest creator combos.

In order for auto-detection to work you need to install one of the following supported combos:

Hello World using PSR-7 & ServerRequest creator auto-detection

<?php
require 'vendor/autoload.php';

use Slim\AppFactory;

/**
 * The AppFactory::create() method takes 5 optional parameters
 * 
 * @param ResponseFactoryInterface Any implementation of a ResponseFactory
 * @param ContainerInterface|null Any implementation of a Container
 * @param CallableResolverInterface|null Any implementation of a CallableResolver
 * @param RouteCollectorInterface|null Any implementation of a RouteCollector
 * @param RouteResolverInterface|null Any implementation of a RouteResolverInterface
 */
$app = AppFactory::create();
$app->get('/hello/{name}', function ($request, $response, $args) {
    $response->getBody()->write("Hello, " . $args['name']);
    return $response;
});

$app->run();

Closes #2621

@l0gicgate l0gicgate added this to the 4.0 milestone Apr 21, 2019
@coveralls
Copy link

coveralls commented Apr 21, 2019

Coverage Status

Coverage increased (+0.9%) to 99.457% when pulling fd2aef9 on l0gicgate:4.x-AppFactory into 36d6786 on slimphp:4.x.

@l0gicgate l0gicgate merged commit 939aaa0 into slimphp:4.x Apr 21, 2019
@l0gicgate l0gicgate deleted the 4.x-AppFactory branch April 21, 2019 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants