diff --git a/1-front-controller.md b/1-front-controller.md index 411bb00..413924c 100644 --- a/1-front-controller.md +++ b/1-front-controller.md @@ -8,9 +8,9 @@ To start, create an empty directory for your project. You also need an entry poi A common way to do this is to just put the `index.php` in the root folder of the projects. This is also how some frameworks do it. Let me explain why you should not do this. -The `index.php` is the starting point, so it has to be inside the webserver directory. Which means that the webserver has access to all subdirectories. If you set things up properly, you can still prevent it from accessing your subfolders where your application files are. +The `index.php` is the starting point, so it has to be inside the web server directory. This means that the web server has access to all subdirectories. If you set things up properly, you can still prevent it from accessing your subfolders where your application files are. -But sometimes things don't go according to plan. And if something goes wrong and your files are set up as explained above, your whole application source code could get exposed to visitors. I won't have to explain why this is not a good thing. +But sometimes things don't go according to plan. And if something goes wrong and your files are set up as above, your whole application source code could be exposed to visitors. I won't have to explain why this is not a good thing. So instead of doing that, create a folder in your project folder called `public`. This is a good time to create an `src` folder for your application, also in the project root folder. @@ -24,7 +24,7 @@ require '../src/Bootstrap.php'; The `Bootstrap.php` will be the file that wires your application together. We will get to it shortly. -The rest of the public folder is reserved for your public asset files (like javascript files and stylesheets). +The rest of the public folder is reserved for your public asset files (like JavaScript files and stylesheets). Now navigate inside your `src` folder and create a new `Bootstrap.php` file with the following content: @@ -34,10 +34,10 @@ Now navigate inside your `src` folder and create a new `Bootstrap.php` file with echo 'Hello World!'; ``` -Now let's see if everything is set up correctly. Open up a console and navigate into your projects `public` folder. In there type `php -S localhost:8000` and press enter. This will start the built-in webserver and you can access your page in a browser with `http://localhost:8000`. You should now see the hello world message. +Now let's see if everything is set up correctly. Open up a console and navigate into your projects `public` folder. In there type `php -S localhost:8000` and press enter. This will start the built-in webserver and you can access your page in a browser with `http://localhost:8000`. You should now see the 'hello world' message. If there is an error, go back and try to fix it. If you only see a blank page, check the console window where the server is running for errors. -Now would be a good time to commit your progress. If you are not already using git, set up a repository now. This is not a git tutorial so I won't go over the details. But using version control should be a habit, even if it is just for a tutorial project like this. +Now would be a good time to commit your progress. If you are not already using Git, set up a repository now. This is not a Git tutorial so I won't go over the details. But using version control should be a habit, even if it is just for a tutorial project like this. -[next >>](2-composer.md) \ No newline at end of file +[next >>](2-composer.md) diff --git a/2-composer.md b/2-composer.md index 16ad1fd..31fca77 100644 --- a/2-composer.md +++ b/2-composer.md @@ -4,11 +4,11 @@ [Composer](https://getcomposer.org/) is a dependency manager for PHP. -Just because you are not using a framework does not mean you will have to reinvent the wheel every time you want to do something. With composer you can install 3rd party libraries for your application. +Just because you are not using a framework does not mean you will have to reinvent the wheel every time you want to do something. With Composer, you can install third-party libraries for your application. -If you don't have composer installed already, head over to the website and install it. You can find composer packages for your project on [packagist](https://packagist.org/). +If you don't have Composer installed already, head over to the website and install it. You can find Composer packages for your project on [Packagist](https://packagist.org/). -Create a new file in your project root folder called `composer.json`. This is the composer configuration file that will be used to configure your project and it's dependencies. It must be valid json or composer will fail. +Create a new file in your project root folder called `composer.json`. This is the Composer configuration file that will be used to configure your project and its dependencies. It must be valid JSON or Composer will fail. Add the following content to the file: @@ -40,15 +40,15 @@ In the autoload part you can see that I am using the `Example` namespace for the Open a new console window and navigate into your project root folder. There run `composer update`. -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: ``` composer.lock vendor/ ``` -This will exclude the included file and folder from your commits. For which would be a good time now by the way. +This will exclude the included file and folder from your commits. For which now would be a good time, by the way. Now you have successfully created an empty playground which you can use to set up your project. -[<< previous](1-front-controller.md) | [next >>](3-error-handler.md) \ No newline at end of file +[<< previous](1-front-controller.md) | [next >>](3-error-handler.md) diff --git a/3-error-handler.md b/3-error-handler.md index 8fcc823..f3b887d 100644 --- a/3-error-handler.md +++ b/3-error-handler.md @@ -27,9 +27,9 @@ Now before you start adding the error handler code to the **Important:** Never show any errors in your production environment. A stack trace or even just a simple error message can help someone to gain access to your system. Always show a user friendly error page instead and send an email to yourself, write to a log or something similar. So only you can see the errors in the production environment. -For development that does not make sense though and you want a nice error page. So the solution is to have an environment switch in your code. For now you can just set it to `development`. +For development that does not make sense though -- you want a nice error page. The solution is to have an environment switch in your code. For now you can just set it to `development`. -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: ``` >](4-http.md) diff --git a/4-http.md b/4-http.md index 17831f1..92da393 100644 --- a/4-http.md +++ b/4-http.md @@ -4,7 +4,7 @@ PHP already has a few things built in to make working with HTTP easier. For example there are the [superglobals](http://php.net/manual/en/language.variables.superglobals.php) that contain the request information. -These are good if you just want to get a small script up and running without much thought on maintenance. But if you want to write clean, maintanable, [SOLID](http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29) code, then you will want a class with a nice object oriented interface that you can use in your application. +These are good if you just want to get a small script up and running without much thought on maintenance. However, if you want to write clean, maintainable, [SOLID](http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29) code, then you will want a class with a nice object-oriented interface that you can use in your application. Once again, you don't have to reinvent the wheel and just install a package. I decided to write my own [HTTP component](https://github.com/PatrickLouys/http) because I did not like the existing components, but you don't have to do the same. @@ -43,7 +43,7 @@ echo $response->getContent(); This will send the response data to the browser. If you don't do this, nothing happens as the `Response` object only stores data. This is handled differently by most other HTTP components where the classes send data back to the browser as a side-effect, so keep that in mind if you use another component. -Right now it is just sending an empty response back to the browser with the status code `200`, so 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: ``` $content = '