added code formatting

This commit is contained in:
Patrick 2014-09-17 22:07:26 +02:00
parent 13a5d0fb01
commit 38f6886933
6 changed files with 15 additions and 15 deletions

View file

@ -16,7 +16,7 @@ So instead of doing that, create a folder in your project folder called `public`
Inside the `public` folder you can now create your `index.php`. Remember that you don't want to expose anything here, so put just the following code in there: Inside the `public` folder you can now create your `index.php`. Remember that you don't want to expose anything here, so put just the following code in there:
``` ```php
<?php <?php
require '../src/Bootstrap.php'; require '../src/Bootstrap.php';
@ -28,7 +28,7 @@ The rest of the public folder is reserved for your public asset files (like Java
Now navigate inside your `src` folder and create a new `Bootstrap.php` file with the following content: Now navigate inside your `src` folder and create a new `Bootstrap.php` file with the following content:
``` ```php
<?php <?php
echo 'Hello World!'; echo 'Hello World!';

View file

@ -12,7 +12,7 @@ Create a new file in your project root folder called `composer.json`. This is th
Add the following content to the file: Add the following content to the file:
``` ```json
{ {
"name": "Project name", "name": "Project name",
"description": "Your project description", "description": "Your project description",
@ -42,7 +42,7 @@ Open a new console window and navigate into your project root folder. There run
Composer creates a `composer.lock` file that locks in your dependencies and a vendor directory. To remove those from your Git repository, add a new file in your project root folder called `.gitignore` with the following content: Composer creates a `composer.lock` file that locks in your dependencies and a vendor directory. To remove those from your Git repository, add a new file in your project root folder called `.gitignore` with the following content:
``` ```php
composer.lock composer.lock
vendor/ vendor/
``` ```

View file

@ -12,7 +12,7 @@ An alternative package would be: [PHP-Error](https://github.com/JosephLenton/PHP
To install a new package, open up your `composer.json` and add the package to the require part. It should now look like this: To install a new package, open up your `composer.json` and add the package to the require part. It should now look like this:
``` ```php
"require": { "require": {
"php": ">=5.5.0", "php": ">=5.5.0",
"filp/whoops": ">=1.1.2" "filp/whoops": ">=1.1.2"
@ -29,7 +29,7 @@ For development that does not make sense though -- you want a nice error page. T
Then after the error handler registration, throw an `Exception` to test if everything is working correctly. Your `Bootstrap.php` should now look similar to this: Then after the error handler registration, throw an `Exception` to test if everything is working correctly. Your `Bootstrap.php` should now look similar to this:
``` ```php
<?php <?php
namespace Example; namespace Example;

View file

@ -14,7 +14,7 @@ In this tutorial I will use my own HTTP component, but of course you can use whi
Again, edit the `composer.json` to add the new component and then run `composer update`: Again, edit the `composer.json` to add the new component and then run `composer update`:
``` ```json
"require": { "require": {
"php": ">=5.5.0", "php": ">=5.5.0",
"filp/whoops": ">=1.1.2", "filp/whoops": ">=1.1.2",
@ -24,7 +24,7 @@ Again, edit the `composer.json` to add the new component and then run `composer
Now you can add the following below your error handler code in your `Bootstrap.php` (and don't forget to remove the exception): Now you can add the following below your error handler code in your `Bootstrap.php` (and don't forget to remove the exception):
``` ```php
$request = new \Http\HttpRequest($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER); $request = new \Http\HttpRequest($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
$response = new \Http\HttpResponse; $response = new \Http\HttpResponse;
``` ```
@ -33,7 +33,7 @@ This sets up the `Request` and `Response` objects that you can use in your other
To actually send something back, you will also need to add the following snippet at the end of your `Bootstrap.php` file: To actually send something back, you will also need to add the following snippet at the end of your `Bootstrap.php` file:
``` ```php
foreach ($response->getHeaders() as $header) { foreach ($response->getHeaders() as $header) {
header($header); header($header);
} }
@ -45,14 +45,14 @@ This will send the response data to the browser. If you don't do this, nothing h
Right now it is just sending an empty response back to the browser with the status code `200`; to change that, add the following code between the code snippets from above: Right now it is just sending an empty response back to the browser with the status code `200`; to change that, add the following code between the code snippets from above:
``` ```php
$content = '<h1>Hello World</h1>'; $content = '<h1>Hello World</h1>';
$response->setContent($content); $response->setContent($content);
``` ```
If you want to try a 404 error, use the following code: If you want to try a 404 error, use the following code:
``` ```php
$response->setContent('404 - Page not found'); $response->setContent('404 - Page not found');
$response->setStatusCode(404); $response->setStatusCode(404);
``` ```

View file

@ -14,7 +14,7 @@ By now you know how to install Composer packages, so I will leave that to you.
Now add this code block to your `Bootstrap.php` file where you added the 'hello world' message in the last part. Now add this code block to your `Bootstrap.php` file where you added the 'hello world' message in the last part.
``` ```php
$dispatcher = \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r) { $dispatcher = \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/hello-world', function () { $r->addRoute('GET', '/hello-world', function () {
echo 'Hello World'; echo 'Hello World';
@ -48,7 +48,7 @@ This setup might work for really small applications, but once you start adding a
Create a `Routes.php` file in the `src/` folder. It should look like this: Create a `Routes.php` file in the `src/` folder. It should look like this:
``` ```php
<?php <?php
return [ return [
@ -63,7 +63,7 @@ return [
Now let's rewrite the route collection part to use the `Routes.php` file. Now let's rewrite the route collection part to use the `Routes.php` file.
``` ```php
$routeDefinitionCallback = function (\FastRoute\RouteCollector $r) { $routeDefinitionCallback = function (\FastRoute\RouteCollector $r) {
$routes = include('Routes.php'); $routes = include('Routes.php');
foreach ($routes as $route) { foreach ($routes as $route) {

View file

@ -4,7 +4,7 @@
A dependency injector resolves the dependencies of your class and makes sure that the correct objects are injected when the class is instantiated. A dependency injector resolves the dependencies of your class and makes sure that the correct objects are injected when the class is instantiated.
My favorite injector is [Auryn](https://github.com/rdlowrey/Auryn), so install `rdlowrey/auryn` with composer or use one of the alternatives below: My favorite injector is [Auryn](https://github.com/rdlowrey/Auryn), so install `rdlowrey/auryn` with composer or use one of these alternatives:
[Pimple](http://pimple.sensiolabs.org/), [Orno DI](https://github.com/orno/di), [PHP-DI](https://github.com/mnapoli/PHP-DI) [Pimple](http://pimple.sensiolabs.org/), [Orno DI](https://github.com/orno/di), [PHP-DI](https://github.com/mnapoli/PHP-DI)
Create a new file called `Dependencies.php` in your `src/` folder. In there add the following content: Create a new file called `Dependencies.php` in your `src/` folder. In there add the following content: