From ddcad6e90de4324dee2f757100e04c5840011f2c Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 22:47:21 +0100 Subject: [PATCH 01/10] Fix case, minor wording tweak --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8128eae..ad94b7b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ If you are really new to the language, this is not for you. This tutorial is aim You should at least heard of [SOLID](http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29). If you are not familiar with it, now would be a good time to familiarize yourself with the principles before you start with the tutorial. -I saw a lot of people coming into the stackoverflow PHP chatroom that asked if X framework is any good. Most of the time the answer was that they should just use PHP and not a framework to build their application. But many are overwhelmed by this and don't know where to start. +I saw a lot of people coming into the Stack Overflow PHP chatroom and asking if X framework is any good. Most of the time the answer was that they should just use PHP and not a framework to build their application. But many are overwhelmed by this and don't know where to start. So my goal with this is to provide an easy resource that people can be pointed to. In most cases a framework does not make sense and writing an application from scratch with the help of some 3rd party packages is much, much easier than some people think. @@ -20,4 +20,4 @@ So let's get started right away with the [first part](1-front-controller.md). 4. [HTTP](4-http.md) 5. [Router](5-router.md) 6. [Controllers](6-controllers.md) -7. Dependency Injector \ No newline at end of file +7. Dependency Injector From d2d7f313556d9da6422fa614e279e8a7b8127b52 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 22:47:48 +0100 Subject: [PATCH 02/10] Word ordering --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad94b7b..7348bec 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ If you are really new to the language, this is not for you. This tutorial is aim You should at least heard of [SOLID](http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29). If you are not familiar with it, now would be a good time to familiarize yourself with the principles before you start with the tutorial. -I saw a lot of people coming into the Stack Overflow PHP chatroom and asking if X framework is any good. Most of the time the answer was that they should just use PHP and not a framework to build their application. But many are overwhelmed by this and don't know where to start. +I saw a lot of people coming into the Stack Overflow PHP chatroom and asking if framework X is any good. Most of the time the answer was that they should just use PHP and not a framework to build their application. But many are overwhelmed by this and don't know where to start. So my goal with this is to provide an easy resource that people can be pointed to. In most cases a framework does not make sense and writing an application from scratch with the help of some 3rd party packages is much, much easier than some people think. From dcb22ac846b0fca646829fef510ae6cb9af34e4b Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 22:51:39 +0100 Subject: [PATCH 03/10] Case fixes, punctuation, spelling --- 1-front-controller.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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) From 60a62a569ab8dd637503c0ec8800d5f7959f97d0 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 22:55:36 +0100 Subject: [PATCH 04/10] Apostrophe usage, punctuation, case, word ordering --- 2-composer.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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) From e9e9733fe26025218e8a97d5a08ceb18f0d2dc15 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 22:59:41 +0100 Subject: [PATCH 05/10] Remove repetition, inline code formatting, wording --- 3-error-handler.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) From cb57ca714e63f1d1af6df0fad12c6b582858eb8a Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 23:13:19 +0100 Subject: [PATCH 06/10] Spelling, punctuation, hyphenation, wording --- 4-http.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 = '

Hello World

'; @@ -57,8 +57,8 @@ $response->setContent('404 - Page not found'); $response->setStatusCode(404); ``` -Remember that the object is only storing data, so you if you set multiple status codes before you send the response, the last one will be applied. +Remember that the object is only storing data, so you if you set multiple status codes before you send the response, only the last one will be applied. I will show you in later parts how to use the different features of the components. In the meantime, feel free to read the [documentation](https://github.com/PatrickLouys/http) or the source code if you want to find out how something works. -[<< previous](3-error-handler.md) | [next >>](5-router.md) \ No newline at end of file +[<< previous](3-error-handler.md) | [next >>](5-router.md) From 3dbaa4e88003741e6d89128a2ea3a3d8741410e3 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 23:15:28 +0100 Subject: [PATCH 07/10] Case, add quotes --- 5-router.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/5-router.md b/5-router.md index cc178a2..f59be70 100644 --- a/5-router.md +++ b/5-router.md @@ -10,9 +10,9 @@ I will use [FastRoute](https://github.com/nikic/FastRoute) in this tutorial. But Alternative packages: [symfony/Routing](https://github.com/symfony/Routing), [Aura.Router](https://github.com/auraphp/Aura.Router), [fuelphp/routing](https://github.com/fuelphp/routing), [Klein](https://github.com/chriso/klein.php) -By now you know how to install composer packages, so I will leave that to you. +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. ``` $dispatcher = \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r) { @@ -76,4 +76,4 @@ $dispatcher = \FastRoute\simpleDispatcher($routeDefinitionCallback); This is already an improvement, but now all the handler code is in the `Routers.php` file. This is not optimal, so let's fix that in the next part. -[<< previous](4-http.md) | [next >>](6-controllers.md) \ No newline at end of file +[<< previous](4-http.md) | [next >>](6-controllers.md) From 6d7303d7aa3bdb77f0163853b09b9951428a7253 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 23:16:34 +0100 Subject: [PATCH 08/10] Spelling --- 6-controllers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/6-controllers.md b/6-controllers.md index 29537bf..8bcd605 100644 --- a/6-controllers.md +++ b/6-controllers.md @@ -2,6 +2,6 @@ ### Controllers -When I talk about a controller in this tutorial then I am just referring to a class that has handler methods. I am not talking about [MVC (Model-View-Controller)](http://martinfowler.com/eaaCatalog/modelViewController.html) controllers. MVC can't be implemented properly in PHP anyways, at least not in the way it was originally conceived. So forget about MVC and instead let's worry about [separation of concerns](http://en.wikipedia.org/wiki/Separation_of_concerns). +When I talk about a controller in this tutorial then I am just referring to a class that has handler methods. I am not talking about [MVC (Model-View-Controller)](http://martinfowler.com/eaaCatalog/modelViewController.html) controllers. MVC can't be implemented properly in PHP anyway, at least not in the way it was originally conceived. So forget about MVC and instead let's worry about [separation of concerns](http://en.wikipedia.org/wiki/Separation_of_concerns). -to be continued... \ No newline at end of file +to be continued... From 0e39a33421a8474fbc06d83f6be59d5f2a14a2e9 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 23:17:40 +0100 Subject: [PATCH 09/10] Numerals are best as words --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7348bec..fc2149e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ You should at least heard of [SOLID](http://en.wikipedia.org/wiki/SOLID_%28objec I saw a lot of people coming into the Stack Overflow PHP chatroom and asking if framework X is any good. Most of the time the answer was that they should just use PHP and not a framework to build their application. But many are overwhelmed by this and don't know where to start. -So my goal with this is to provide an easy resource that people can be pointed to. In most cases a framework does not make sense and writing an application from scratch with the help of some 3rd party packages is much, much easier than some people think. +So my goal with this is to provide an easy resource that people can be pointed to. In most cases a framework does not make sense and writing an application from scratch with the help of some third party packages is much, much easier than some people think. So let's get started right away with the [first part](1-front-controller.md). From de0cd1957f42eed1e79c18d6c458ed24023a06c1 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 15 Sep 2014 23:24:07 +0100 Subject: [PATCH 10/10] Hyphenation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc2149e..c59e4ef 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### Introduction -If you are really new to the language, this is not for you. This tutorial is aimed at people who have grasped the basics of PHP and know a little bit about object oriented programming. +If you are really new to the language, this is not for you. This tutorial is aimed at people who have grasped the basics of PHP and know a little bit about object-oriented programming. You should at least heard of [SOLID](http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29). If you are not familiar with it, now would be a good time to familiarize yourself with the principles before you start with the tutorial.