Skip to content

Commit

Permalink
Merge branch 'update-example' into 4.x
Browse files Browse the repository at this point in the history
Closes #2553
Fixes #2552
  • Loading branch information
akrabat committed Dec 10, 2018
2 parents 94b7634 + 5e9177d commit bcf7df5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion example/README.md
Expand Up @@ -3,7 +3,7 @@
1. Install with [composer](https://getcomposer.org/)

```bash
$ cd Slim
$ cd Slim/example
$ composer install
```

Expand Down
7 changes: 7 additions & 0 deletions example/composer.json
@@ -0,0 +1,7 @@
{
"require": {
"slim/slim": "4.x-dev",
"slim/psr7": "dev-master",
"slim/http": "^0.6.0"
}
}
48 changes: 34 additions & 14 deletions example/index.php
@@ -1,25 +1,44 @@
<?php

/**
* Step 1: Require the Slim Framework using Composer's autoloader
*
* If you are not using Composer, you need to load Slim Framework with your own
* PSR-4 autoloader.
* Require the Slim Framework using Composer's autoloader
* This example uses: composer require slim/slim:4.x-dev slim/psr7:dev-master slim/http
*/
require __DIR__ . '/vendor/autoload.php';


/**
* Import relevant classes
*/
require 'vendor/autoload.php';
use Slim\App;
use Slim\Http\Factory\DecoratedResponseFactory;
use Slim\Http\ServerRequest;
use Slim\Middleware\ErrorMiddleware;
use Slim\Psr7\Factory\ResponseFactory;
use Slim\Psr7\Factory\ServerRequestFactory;
use Slim\Psr7\Factory\StreamFactory;

/**
* Step 2: Instantiate a Slim application
* Create a PSR-17 response factory and instantiate our Slim appliciation ($app)
*/
$responseFactory = new DecoratedResponseFactory(new ResponseFactory(), new StreamFactory());

/**
* Instantiate a Slim application
*
* This example instantiates a Slim application using
* its default settings. However, you will usually configure
* your Slim application now by passing an associative array
* of setting names and values into the application constructor.
* This example instantiates a Slim application using its default settings. However, you may choose to configure
* your Slim application now by passing an associative array of settings into the application constructor.
*/
$app = new App($responseFactory);

/**
* Add middleware as required. This is a LIFO stack.
* We recommend adding ErrorMiddleware at least
*/
$app = new Slim\App();
$app->add(new ErrorMiddleware($app->getCallableResolver(), $responseFactory, true, true, true));

/**
* Step 3: Define the Slim application routes
* Define the Slim application routes
*
* Here we define several Slim application routes that respond
* to appropriate HTTP request methods. In this example, the second
Expand All @@ -37,9 +56,10 @@
})->setArgument('name', 'World!');

/**
* Step 4: Run the Slim application
* Run the Slim application
*
* This method should be called last. This executes the Slim application
* and returns the HTTP response to the HTTP client.
*/
$app->run();
$request = new ServerRequest(ServerRequestFactory::createFromGlobals());
$app->run($request);

0 comments on commit bcf7df5

Please sign in to comment.