From b717500558d9433b10a40e6a91c67c811001e5cb Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Fri, 20 Jun 2014 21:29:47 +0100 Subject: [PATCH 01/29] Add a PHPDoc post --- _posts/15-01-01-PHPDoc.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 _posts/15-01-01-PHPDoc.md diff --git a/_posts/15-01-01-PHPDoc.md b/_posts/15-01-01-PHPDoc.md new file mode 100644 index 0000000..6b10b60 --- /dev/null +++ b/_posts/15-01-01-PHPDoc.md @@ -0,0 +1,36 @@ +--- +anchor: phpdoc +--- + +# PHPDoc {#phpdoc} + +PHPDoc is an informal standard for commenting PHP code. There are a *lot* of different [tags](http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags.pkg.html) available. The full list of tags and examples can be found at the [PHPDoc manual](http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags.pkg.html). + +Below is an example of how you might comment a class and a method; + +{% highlight php %} + + * @link http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags.link.pkg.html + * @package demo + */ +class DateTimeHelper +{ + /** + * @param mixed $anything + * + * @return \DateTime + * @throws \InvalidArgumentException + */ + public static function dateTimeFromAnything($anything) { + $type = gettype($anything); + + switch ($type) { + case "object": + if ($anything instanceof \DateTime) { + return $anything; + } + break; +... +{% endhighlight %} From c3c45a89698e817c062e9cbbe1ca2a42401753d9 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Mon, 23 Jun 2014 09:26:08 +0100 Subject: [PATCH 02/29] Updated the URLs to new documentation after some feedback --- _posts/15-01-01-PHPDoc.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_posts/15-01-01-PHPDoc.md b/_posts/15-01-01-PHPDoc.md index 6b10b60..1645f07 100644 --- a/_posts/15-01-01-PHPDoc.md +++ b/_posts/15-01-01-PHPDoc.md @@ -4,7 +4,7 @@ anchor: phpdoc # PHPDoc {#phpdoc} -PHPDoc is an informal standard for commenting PHP code. There are a *lot* of different [tags](http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags.pkg.html) available. The full list of tags and examples can be found at the [PHPDoc manual](http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags.pkg.html). +PHPDoc is an informal standard for commenting PHP code. There are a *lot* of different [tags](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/index.html) available. The full list of tags and examples can be found at the [PHPDoc manual](http://www.phpdoc.org/docs/latest/index.html). Below is an example of how you might comment a class and a method; @@ -12,7 +12,7 @@ Below is an example of how you might comment a class and a method; - * @link http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags.link.pkg.html + * @link http://www.phpdoc.org/docs/latest/index.html * @package demo */ class DateTimeHelper From de8cef6c7d0bb68591018f4d07fcddcff322a14a Mon Sep 17 00:00:00 2001 From: christian studer Date: Mon, 30 Jun 2014 13:37:13 +0200 Subject: [PATCH 03/29] Typo and missing link for SQL injections --- _posts/07-01-01-Databases.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/07-01-01-Databases.md b/_posts/07-01-01-Databases.md index 7d16f2a..a314cfa 100644 --- a/_posts/07-01-01-Databases.md +++ b/_posts/07-01-01-Databases.md @@ -61,7 +61,7 @@ $pdo->query("SELECT name FROM users WHERE id = " . $_GET['id']); // <-- NO! {% endhighlight %} This is terrible code. You are inserting a raw query parameter into a SQL query. This will get you hacked in a -heartbeat, using a practice called [SQL Injecton]. Just imagine if a hacker passes in an inventive `id` parameter by calling a URL like +heartbeat, using a practice called [SQL Injection](http://wiki.hashphp.org/Validation). Just imagine if a hacker passes in an inventive `id` parameter by calling a URL like `http://domain.com/?id=1%3BDELETE+FROM+users`. This will set the `$_GET['id']` variable to `1;DELETE FROM users` which will delete all of your users! Instead, you should sanitize the ID input using PDO bound parameters. From 1dc778fe07a032727bf76043eb7ae23953d10181 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Tue, 1 Jul 2014 13:32:54 +0100 Subject: [PATCH 04/29] Expand documentation and explain (and it's exclusion) --- _posts/15-01-01-PHPDoc.md | 47 ++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/_posts/15-01-01-PHPDoc.md b/_posts/15-01-01-PHPDoc.md index 1645f07..f0fec15 100644 --- a/_posts/15-01-01-PHPDoc.md +++ b/_posts/15-01-01-PHPDoc.md @@ -6,31 +6,58 @@ anchor: phpdoc PHPDoc is an informal standard for commenting PHP code. There are a *lot* of different [tags](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/index.html) available. The full list of tags and examples can be found at the [PHPDoc manual](http://www.phpdoc.org/docs/latest/index.html). -Below is an example of how you might comment a class and a method; +Below is an example of how you might document a class with a few methods; {% highlight php %} * @link http://www.phpdoc.org/docs/latest/index.html - * @package demo + * @package helper */ class DateTimeHelper { /** - * @param mixed $anything + * @param mixed $anything Anything that we can convert to a \DateTime object * * @return \DateTime * @throws \InvalidArgumentException */ - public static function dateTimeFromAnything($anything) { + public function dateTimeFromAnything($anything) + { $type = gettype($anything); switch ($type) { - case "object": - if ($anything instanceof \DateTime) { - return $anything; - } - break; -... + // Some code that tries to return a \DateTime object + } + + throw new \InvalidArgumentException( + "Failed Converting param of type '{$type}' to DateTime object" + ); + } + + /** + * @param mixed $date Anything that we can convert to a \DateTime object + * + * @return void + */ + public function printISO8601Date($date) + { + echo $this->dateTimeFromAnything($date)->format('c'); + } + + /** + * @param mixed $date Anything that we can convert to a \DateTime object + */ + public function printRFC2822Date($date) + { + echo $this->dateTimeFromAnything($date)->format('r'); + } +} {% endhighlight %} + +The documentation for the class as a whole firstly has the [@author](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/author.html) tag, this tag is used to document the author of the code and can be repeated for documenting several authors. Secondly is the [@link](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/link.html) tag, used to link to a website indicating a relationship between the website and the code. Thirdly it has the [@pacakge](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/package.html) tag, used to categorize the code. + +Inside the class, the first method has an [@param](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/param.html) tag documenting the type, name and description of the parameter being passed to the method. Additionally it has the [@return](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/return.html) and [@throws](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/throws.html) tags for documenting the return type, and any exceptions that could be throw respectively. + +The second and third methods are very similar and have a single [@param](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/param.html) tag as did the first method. The import difference between the second and third method is doc block is the inclusion/exclusion of the [@return](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/return.html) tag. `@return void` explicitly informs us that there is no return, historically omitting the `@return void` statement also results in the same (no return) action. \ No newline at end of file From bfc8c51123350806538d127cb98e440a11ebdfe9 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Wed, 2 Jul 2014 13:21:44 +0100 Subject: [PATCH 05/29] Maximum number of contributors in a single request The Github api limits results to 30 per page by default. The maximum for a single result of contributors is 100. --- scripts/setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup.js b/scripts/setup.js index bab8251..819d71f 100644 --- a/scripts/setup.js +++ b/scripts/setup.js @@ -10,7 +10,7 @@ dataType: 'jsonp', timeout: 3000, type: 'GET', - url: 'https://api.github.com/repos/codeguy/php-the-right-way/contributors' + url: 'https://api.github.com/repos/codeguy/php-the-right-way/contributors?per_page=100' }).done(function (data) { if ( data.data && data.data.length ) { var $ul = $('
    '), dataLength = data.data.length; From 6f8793ebee35853e2391e5b634ead22917644bd0 Mon Sep 17 00:00:00 2001 From: Yannick Lyn Fatt Date: Wed, 9 Jul 2014 13:37:15 -0500 Subject: [PATCH 06/29] Fixed typo in PHPDoc.md Closes #405 --- _posts/15-01-01-PHPDoc.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_posts/15-01-01-PHPDoc.md b/_posts/15-01-01-PHPDoc.md index f0fec15..21f4dfa 100644 --- a/_posts/15-01-01-PHPDoc.md +++ b/_posts/15-01-01-PHPDoc.md @@ -56,8 +56,8 @@ class DateTimeHelper } {% endhighlight %} -The documentation for the class as a whole firstly has the [@author](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/author.html) tag, this tag is used to document the author of the code and can be repeated for documenting several authors. Secondly is the [@link](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/link.html) tag, used to link to a website indicating a relationship between the website and the code. Thirdly it has the [@pacakge](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/package.html) tag, used to categorize the code. +The documentation for the class as a whole firstly has the [@author](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/author.html) tag, this tag is used to document the author of the code and can be repeated for documenting several authors. Secondly is the [@link](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/link.html) tag, used to link to a website indicating a relationship between the website and the code. Thirdly it has the [@package](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/package.html) tag, used to categorize the code. Inside the class, the first method has an [@param](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/param.html) tag documenting the type, name and description of the parameter being passed to the method. Additionally it has the [@return](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/return.html) and [@throws](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/throws.html) tags for documenting the return type, and any exceptions that could be throw respectively. -The second and third methods are very similar and have a single [@param](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/param.html) tag as did the first method. The import difference between the second and third method is doc block is the inclusion/exclusion of the [@return](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/return.html) tag. `@return void` explicitly informs us that there is no return, historically omitting the `@return void` statement also results in the same (no return) action. \ No newline at end of file +The second and third methods are very similar and have a single [@param](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/param.html) tag as did the first method. The import difference between the second and third method is doc block is the inclusion/exclusion of the [@return](http://www.phpdoc.org/docs/latest/references/phpdoc/tags/return.html) tag. `@return void` explicitly informs us that there is no return, historically omitting the `@return void` statement also results in the same (no return) action. From 00f8879add222a0bfc0a1edc05af899fb7595068 Mon Sep 17 00:00:00 2001 From: Tyler Pearson Date: Thu, 10 Jul 2014 23:17:50 -0700 Subject: [PATCH 07/29] Fixed typo --- _posts/07-01-02-Interacting-via-Code.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_posts/07-01-02-Interacting-via-Code.md b/_posts/07-01-02-Interacting-via-Code.md index f595dc2..8b28079 100644 --- a/_posts/07-01-02-Interacting-via-Code.md +++ b/_posts/07-01-02-Interacting-via-Code.md @@ -20,7 +20,7 @@ foreach ($db->query('SELECT * FROM table') as $row) { This is bad practice for all sorts of reasons, mainly that its hard to debug, hard to test, hard to read and it is going to output a lot of fields if you don't put a limit on there. -While there are many other solutions to doing this - depending on if you prefer [OOP](/#object-oriented-programming) or [functional programming](/#functional-programming) - there must be some element of seperation. +While there are many other solutions to doing this - depending on if you prefer [OOP](/#object-oriented-programming) or [functional programming](/#functional-programming) - there must be some element of separation. Consider the most basic step: @@ -35,7 +35,7 @@ foreach (getAllFoos() as $row) { } {% endhighlight %} -That is a good start. Put those two items in two different files and you've got some clean seperation. +That is a good start. Put those two items in two different files and you've got some clean separation. Create a class to place that method in and you have a "Model". Create a simple `.php` file to put the presentation logic in and you have a "View", which is very nearly [MVC] - a common OOP architecture for most [frameworks](/#frameworks_title). From 86f94fbfc2c7e4507c53d1be703127163f94a4aa Mon Sep 17 00:00:00 2001 From: Kunio Murasawa Date: Tue, 15 Jul 2014 00:14:45 +0900 Subject: [PATCH 08/29] fix a typo --- _posts/07-01-02-Interacting-via-Code.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_posts/07-01-02-Interacting-via-Code.md b/_posts/07-01-02-Interacting-via-Code.md index 8b28079..9414247 100644 --- a/_posts/07-01-02-Interacting-via-Code.md +++ b/_posts/07-01-02-Interacting-via-Code.md @@ -26,7 +26,7 @@ Consider the most basic step: {% highlight php %} query('SELECT * FROM table'); } @@ -70,7 +70,7 @@ class Foo() $this->db = $db; } - public functon getAllFoos() { + public function getAllFoos() { return $this->db->query('SELECT * FROM table'); } } From ac548011c06a69a1a1e343e24d56154aada0d845 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 15 Jul 2014 16:55:55 +0100 Subject: [PATCH 09/29] Add note about patchwork utf8 --- _posts/05-05-01-PHP-and-UTF8.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/_posts/05-05-01-PHP-and-UTF8.md b/_posts/05-05-01-PHP-and-UTF8.md index 96952e4..c0a979c 100644 --- a/_posts/05-05-01-PHP-and-UTF8.md +++ b/_posts/05-05-01-PHP-and-UTF8.md @@ -18,9 +18,8 @@ for a brief, practical summary. The basic string operations, like concatenating two strings and assigning strings to variables, don't need anything special for UTF-8. However most string functions, like `strpos()` and `strlen()`, do need special consideration. These -functions often have an `mb_*` counterpart: for example, `mb_strpos()` and `mb_strlen()`. Together, these counterpart -functions are called the Multibyte String Functions. The multibyte string functions are specifically designed to -operate on Unicode strings. +functions often have an `mb_*` counterpart: for example, `mb_strpos()` and `mb_strlen()`. These `mb_*` strings are made +available to you via the [Multibyte String Extension], and are specifically designed to operate on Unicode strings. You must use the `mb_*` functions whenever you operate on a Unicode string. For example, if you use `substr()` on a UTF-8 string, there's a good chance the result will include some garbled half-characters. The correct function to use @@ -32,17 +31,21 @@ string has a chance of being garbled during further processing. Not all string functions have an `mb_*` counterpart. If there isn't one for what you want to do, then you might be out of luck. -Additionally, you should use the `mb_internal_encoding()` function at the top of every PHP script you write (or at the +You should use the `mb_internal_encoding()` function at the top of every PHP script you write (or at the top of your global include script), and the `mb_http_output()` function right after it if your script is outputting to a browser. Explicitly defining the encoding of your strings in every script will save you a lot of headaches down the road. -Finally, many PHP functions that operate on strings have an optional parameter letting you specify the character +Additionally, many PHP functions that operate on strings have an optional parameter letting you specify the character encoding. You should always explicitly indicate UTF-8 when given the option. For example, `htmlentities()` has an -option for character encoding, and you should always specify UTF-8 if dealing with such strings. +option for character encoding, and you should always specify UTF-8 if dealing with such strings. Note that as of PHP 5.4.0, UTF-8 is the default encoding for `htmlentities()` and `htmlspecialchars()`. -Note that as of PHP 5.4.0, UTF-8 is the default encoding for `htmlentities()` and `htmlspecialchars()`. +Finally, If you are building an distributed application and cannot be certain that the `mbstring` extension will be +enabled, then consider using the [patchwork/utf8] Composer package. This +will use `mbstring` if it is available, and fall back to non UTF-8 functions if not. +[Multibyte String Extension]: http://php.net/manual/en/book.mbstring.php +[patchwork/utf8]: https://packagist.org/packages/patchwork/utf8 ### UTF-8 at the Database level From 3d7f2957d9ffc4125dc396dfe42d79ac2e783446 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 15 Jul 2014 16:57:26 +0100 Subject: [PATCH 10/29] Working with UTF-8 --- _posts/05-05-01-PHP-and-UTF8.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_posts/05-05-01-PHP-and-UTF8.md b/_posts/05-05-01-PHP-and-UTF8.md index c0a979c..801bfe2 100644 --- a/_posts/05-05-01-PHP-and-UTF8.md +++ b/_posts/05-05-01-PHP-and-UTF8.md @@ -1,9 +1,10 @@ --- +title: Working with UTF-8 isChild: true anchor: php_and_utf8 --- -## PHP and UTF-8 {#php_and_utf8_title} +## Working with UTF-8 {#php_and_utf8_title} _This section was originally written by [Alex Cabal](https://alexcabal.com/) over at [PHP Best Practices](https://phpbestpractices.org/#utf-8) and has now been shared here_. From 9a41f407f081a0cb31b1d484bda00b7b67fcb994 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 15 Jul 2014 17:05:07 +0100 Subject: [PATCH 11/29] Charset in content-type --- _posts/05-05-01-PHP-and-UTF8.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/_posts/05-05-01-PHP-and-UTF8.md b/_posts/05-05-01-PHP-and-UTF8.md index 801bfe2..a4adcc7 100644 --- a/_posts/05-05-01-PHP-and-UTF8.md +++ b/_posts/05-05-01-PHP-and-UTF8.md @@ -7,7 +7,7 @@ anchor: php_and_utf8 ## Working with UTF-8 {#php_and_utf8_title} _This section was originally written by [Alex Cabal](https://alexcabal.com/) over at -[PHP Best Practices](https://phpbestpractices.org/#utf-8) and has now been shared here_. +[PHP Best Practices](https://phpbestpractices.org/#utf-8) and has been used as the basis for our own UTF-8 advice_. ### There's no one-liner. Be careful, detailed, and consistent. @@ -62,8 +62,9 @@ Further Reading for why. ### UTF-8 at the browser level -Use the `mb_http_output()` function to ensure that your PHP script outputs UTF-8 strings to your browser. In your HTML, -include the [charset `` tag](http://htmlpurifier.org/docs/enduser-utf8.html) in your page's `` tag. +Use the `mb_http_output()` function to ensure that your PHP script outputs UTF-8 strings to your browser. + +The browser will then need to be told by the HTTP response that this page should be considered as UTF-8. The historic approach to doing that was to include the [charset `` tag](http://htmlpurifier.org/docs/enduser-utf8.html) in your page's `` tag. This approach is perfectly valid, but setting the charset in the `Content-Type` header is actually [much faster](https://developers.google.com/speed/docs/best-practices/rendering#SpecifyCharsetEarly). {% highlight php %} execute(); // Store the result into an object that we'll output later in our HTML $result = $handle->fetchAll(\PDO::FETCH_OBJ); + +header('Content-Type: text/html; charset=utf-8'); ?> - UTF-8 test page From 40101b60bad28d686bd62175450b2903823fb0ce Mon Sep 17 00:00:00 2001 From: Kunio Murasawa Date: Wed, 16 Jul 2014 09:39:07 +0900 Subject: [PATCH 12/29] fix the indentation --- _posts/07-01-02-Interacting-via-Code.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/_posts/07-01-02-Interacting-via-Code.md b/_posts/07-01-02-Interacting-via-Code.md index 9414247..9f38be9 100644 --- a/_posts/07-01-02-Interacting-via-Code.md +++ b/_posts/07-01-02-Interacting-via-Code.md @@ -27,7 +27,7 @@ Consider the most basic step: {% highlight php %} query('SELECT * FROM table'); + return $db->query('SELECT * FROM table'); } foreach (getAllFoos() as $row) { @@ -63,16 +63,16 @@ include 'views/foo-list.php'; db = $db; - } + public function __construct(PDO $db) + { + $this->db = $db; + } - public function getAllFoos() { - return $this->db->query('SELECT * FROM table'); - } + public function getAllFoos() { + return $this->db->query('SELECT * FROM table'); + } } {% endhighlight %} From b761690292e1fb72dbec95941ada58ff8f6b83e3 Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Fri, 25 Jul 2014 14:53:02 -0400 Subject: [PATCH 13/29] Add new Templating section. --- ...de.md => 07-02-01-Interacting-via-Code.md} | 2 +- ...yers.md => 07-03-01-Abstraction-Layers.md} | 2 +- _posts/08-01-01-Templating.md | 12 ++++++++ _posts/08-02-01-Benefits.md | 21 ++++++++++++++ _posts/08-03-01-Plain-PHP-Templates.md | 28 +++++++++++++++++++ _posts/08-04-01-Compiled-Templates.md | 28 +++++++++++++++++++ _posts/08-05-01-Further-Reading.md | 27 ++++++++++++++++++ ...s.md => 09-01-01-Errors-and-Exceptions.md} | 0 ...{08-02-01-Errors.md => 09-02-01-Errors.md} | 0 ...1-Exceptions.md => 09-03-01-Exceptions.md} | 0 ...01-01-Security.md => 10-01-01-Security.md} | 0 ...d => 10-02-01-Web-Application-Security.md} | 0 ...ashing.md => 10-03-01-Password-Hashing.md} | 0 ...iltering.md => 10-04-01-Data-Filtering.md} | 0 ...les.md => 10-05-01-Configuration-Files.md} | 0 ...lobals.md => 10-06-01-Register-Globals.md} | 0 ...porting.md => 10-07-01-Error-Reporting.md} | 0 ...0-01-01-Testing.md => 11-01-01-Testing.md} | 0 ...md => 11-02-01-Test-Driven-Development.md} | 0 ...> 11-03-01-Behavior-Driven-Development.md} | 0 ...> 11-04-01-Complementary-Testing-Tools.md} | 0 ....md => 12-01-01-Servers-and-Deployment.md} | 0 ...e.md => 12-02-01-Platform-as-a-Service.md} | 0 ... 12-03-01-Virtual-or-Dedicated-Servers.md} | 0 ...-Servers.md => 12-04-01-Shared-Servers.md} | 0 ... => 12-05-01-Building-your-Application.md} | 0 ...2-01-01-Caching.md => 13-01-01-Caching.md} | 0 ...de-Cache.md => 13-02-01-Bytecode-Cache.md} | 0 ...-Caching.md => 13-03-01-Object-Caching.md} | 0 ...-01-Resources.md => 14-01-01-Resources.md} | 0 ...1-Frameworks.md => 14-02-01-Frameworks.md} | 0 ...1-Components.md => 14-03-01-Components.md} | 0 .../{13-04-01-Books.md => 14-04-01-Books.md} | 0 ...-01-Community.md => 15-01-01-Community.md} | 0 ...{15-01-01-PHPDoc.md => 16-01-01-PHPDoc.md} | 0 35 files changed, 118 insertions(+), 2 deletions(-) rename _posts/{07-01-02-Interacting-via-Code.md => 07-02-01-Interacting-via-Code.md} (97%) rename _posts/{07-01-03-Abstraction-Layers.md => 07-03-01-Abstraction-Layers.md} (95%) create mode 100644 _posts/08-01-01-Templating.md create mode 100644 _posts/08-02-01-Benefits.md create mode 100644 _posts/08-03-01-Plain-PHP-Templates.md create mode 100644 _posts/08-04-01-Compiled-Templates.md create mode 100644 _posts/08-05-01-Further-Reading.md rename _posts/{08-01-01-Errors-and-Exceptions.md => 09-01-01-Errors-and-Exceptions.md} (100%) rename _posts/{08-02-01-Errors.md => 09-02-01-Errors.md} (100%) rename _posts/{08-03-01-Exceptions.md => 09-03-01-Exceptions.md} (100%) rename _posts/{09-01-01-Security.md => 10-01-01-Security.md} (100%) rename _posts/{09-02-01-Web-Application-Security.md => 10-02-01-Web-Application-Security.md} (100%) rename _posts/{09-03-01-Password-Hashing.md => 10-03-01-Password-Hashing.md} (100%) rename _posts/{09-04-01-Data-Filtering.md => 10-04-01-Data-Filtering.md} (100%) rename _posts/{09-05-01-Configuration-Files.md => 10-05-01-Configuration-Files.md} (100%) rename _posts/{09-06-01-Register-Globals.md => 10-06-01-Register-Globals.md} (100%) rename _posts/{09-07-01-Error-Reporting.md => 10-07-01-Error-Reporting.md} (100%) rename _posts/{10-01-01-Testing.md => 11-01-01-Testing.md} (100%) rename _posts/{10-02-01-Test-Driven-Development.md => 11-02-01-Test-Driven-Development.md} (100%) rename _posts/{10-03-01-Behavior-Driven-Development.md => 11-03-01-Behavior-Driven-Development.md} (100%) rename _posts/{10-04-01-Complementary-Testing-Tools.md => 11-04-01-Complementary-Testing-Tools.md} (100%) rename _posts/{11-01-01-Servers-and-Deployment.md => 12-01-01-Servers-and-Deployment.md} (100%) rename _posts/{11-02-01-Platform-as-a-Service.md => 12-02-01-Platform-as-a-Service.md} (100%) rename _posts/{11-03-01-Virtual-or-Dedicated-Servers.md => 12-03-01-Virtual-or-Dedicated-Servers.md} (100%) rename _posts/{11-04-01-Shared-Servers.md => 12-04-01-Shared-Servers.md} (100%) rename _posts/{11-05-01-Building-your-Application.md => 12-05-01-Building-your-Application.md} (100%) rename _posts/{12-01-01-Caching.md => 13-01-01-Caching.md} (100%) rename _posts/{12-02-01-Bytecode-Cache.md => 13-02-01-Bytecode-Cache.md} (100%) rename _posts/{12-03-01-Object-Caching.md => 13-03-01-Object-Caching.md} (100%) rename _posts/{13-01-01-Resources.md => 14-01-01-Resources.md} (100%) rename _posts/{13-02-01-Frameworks.md => 14-02-01-Frameworks.md} (100%) rename _posts/{13-03-01-Components.md => 14-03-01-Components.md} (100%) rename _posts/{13-04-01-Books.md => 14-04-01-Books.md} (100%) rename _posts/{14-01-01-Community.md => 15-01-01-Community.md} (100%) rename _posts/{15-01-01-PHPDoc.md => 16-01-01-PHPDoc.md} (100%) diff --git a/_posts/07-01-02-Interacting-via-Code.md b/_posts/07-02-01-Interacting-via-Code.md similarity index 97% rename from _posts/07-01-02-Interacting-via-Code.md rename to _posts/07-02-01-Interacting-via-Code.md index 9f38be9..c3364e4 100644 --- a/_posts/07-01-02-Interacting-via-Code.md +++ b/_posts/07-02-01-Interacting-via-Code.md @@ -4,7 +4,7 @@ title: Interacting with Databases anchor: databases_interacting --- -## Interacting with Databases +## Interacting with Databases {#databases_interacting_title} When developers first start to learn PHP, they often end up mixing their database interaction up with their presentation logic, using code that might look like this: diff --git a/_posts/07-01-03-Abstraction-Layers.md b/_posts/07-03-01-Abstraction-Layers.md similarity index 95% rename from _posts/07-01-03-Abstraction-Layers.md rename to _posts/07-03-01-Abstraction-Layers.md index f2bcfc4..ee61b63 100644 --- a/_posts/07-01-03-Abstraction-Layers.md +++ b/_posts/07-03-01-Abstraction-Layers.md @@ -4,7 +4,7 @@ title: Abstraction Layers anchor: databases_abstraction_layers --- -## Abstraction Layers +## Abstraction Layers {#databases_abstraction_layers_title} Many frameworks provide their own abstraction layer which may or may not sit on top of PDO. These will often emulate features for one database system that is missing from another by wrapping your queries in PHP methods, giving you actual database abstraction instead of just the connection abstraction that PDO provides. diff --git a/_posts/08-01-01-Templating.md b/_posts/08-01-01-Templating.md new file mode 100644 index 0000000..8957e2f --- /dev/null +++ b/_posts/08-01-01-Templating.md @@ -0,0 +1,12 @@ +--- +title: Templating +anchor: templating +--- + +# Templating {#templating_title} + +Templates provide a convenient way of separating your controller and domain logic from your presentation logic. +Templates typically contain the HTML of your application, but may also be used for other formats, such as XML. +Templates are often referred to as "views", the second component of the +[model–view–controller](http://www.phptherightway.com/pages/Design-Patterns.html#model-view-controller) (MVC) +software architecture pattern. \ No newline at end of file diff --git a/_posts/08-02-01-Benefits.md b/_posts/08-02-01-Benefits.md new file mode 100644 index 0000000..1da94d6 --- /dev/null +++ b/_posts/08-02-01-Benefits.md @@ -0,0 +1,21 @@ +--- +isChild: true +anchor: templating_benefits +--- + +## Benefits {#templating_benefits_title} + +The main benefit to using templates is the clear separation they create between the presentation logic and the rest of +your application. Templates have the sole responsibility of displaying formatted content. They are not responsible for +data lookup, persistence or other more complex tasks. This leads to cleaner, more readable code which is especially +helpful in a team environment where developers work on the server-side code (controllers, models) and designers work on +the client-side code (markup). + +Templates also improve the organization of presentation code. Templates are typically placed in a "views" folder, each +defined within a single file. This approach encourages code reuse where larger blocks of code are broken into smaller, +reusable pieces. For example, your site header and footer can each be defined as templates, which are then included +before and after each page template. + +Finally, depending on the library you use, templates can offer more security by automatically escaping user-generated +content. Some libraries even offer sand-boxing, where template designers are only given access to white-listed +variables and functions. \ No newline at end of file diff --git a/_posts/08-03-01-Plain-PHP-Templates.md b/_posts/08-03-01-Plain-PHP-Templates.md new file mode 100644 index 0000000..137d6e4 --- /dev/null +++ b/_posts/08-03-01-Plain-PHP-Templates.md @@ -0,0 +1,28 @@ +--- +isChild: true +anchor: plain_php_templates +--- + +## Plain PHP Templates {#plain_php_templates_title} + +Plain PHP templates are simply templates that use native PHP code. They are a natural choice since PHP is actually a +template language itself. That simply means that you can combine PHP code within other code, like HTML. This is +beneficial to PHP developers as there is no new syntax to learn, they know the functions available to them, and their +code editors already have PHP syntax highlighting and auto-completion built-in. Further, plain PHP templates tend to be +very fast as no compiling stage is required. + +Every modern PHP framework employs some kind of template system, most of which use plain PHP by default. Outside of +frameworks, libraries like [Plates](http://platesphp.com/) or [Aura.View](https://github.com/auraphp/Aura.View) make +working with plain PHP templates easier by offering modern template functionality such as inheritance, layouts and +extensions. + +Example of a plain PHP template (using the [Plates](http://platesphp.com/) library): + +{% highlight php %} +insert('header', ['title' => 'User Profile']) ?> + +

    User Profile

    +

    Hello, escape($name)?>

    + +insert('footer') ?> +{% endhighlight %} \ No newline at end of file diff --git a/_posts/08-04-01-Compiled-Templates.md b/_posts/08-04-01-Compiled-Templates.md new file mode 100644 index 0000000..d46cd70 --- /dev/null +++ b/_posts/08-04-01-Compiled-Templates.md @@ -0,0 +1,28 @@ +--- +isChild: true +anchor: compiled_templates +--- + +## Compiled Templates {#compiled_templates} + +While PHP has evolved into a mature, object oriented language, it +[hasn't improved much](http://fabien.potencier.org/article/34/templating-engines-in-php) as a templating language. +Compiled templates, like [Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/), fill this void by +offering a new syntax that has been geared specifically to templating. From automatic escaping, to inheritance and +simplified control structures, compiled templates are designed to be easier to write, cleaner to read and safer to use. +Compiled templates can even be shared across different languages, [Mustache](http://mustache.github.io/) being a good +example of this. Since these templates must be compiled there is a slight performance hit, however this is very minimal +when proper caching is used. + +Example of a compiled template (using the [Twig](http://twig.sensiolabs.org/) library): + +{% highlight text %} +{% raw %} +{% include 'header.html' with {'title': 'User Profile'} %} + +

    User Profile

    +

    Hello, {{ name }}

    + +{% include 'footer.html' %} +{% endraw %} +{% endhighlight %} \ No newline at end of file diff --git a/_posts/08-05-01-Further-Reading.md b/_posts/08-05-01-Further-Reading.md new file mode 100644 index 0000000..fd8c160 --- /dev/null +++ b/_posts/08-05-01-Further-Reading.md @@ -0,0 +1,27 @@ +--- +isChild: true +anchor: templating_further_reading +--- + +## Further Reading {#templating_further_reading_title} + +### Articles & Tutorials + +- [Templating Engines in PHP](http://fabien.potencier.org/article/34/templating-engines-in-php) +- [An Introduction to Views & Templating in CodeIgniter](http://code.tutsplus.com/tutorials/an-introduction-to-views-templating-in-codeigniter--net-25648) +- [Getting Started With PHP Templating](http://www.smashingmagazine.com/2011/10/17/getting-started-with-php-templating/) +- [Roll Your Own Templating System in PHP](http://code.tutsplus.com/tutorials/roll-your-own-templating-system-in-php--net-16596) +- [Master Pages](https://laracasts.com/series/laravel-from-scratch/episodes/7) +- [Working With Templates in Symfony 2](http://code.tutsplus.com/tutorials/working-with-templates-in-symfony-2--cms-21172) + +### Libraries + +- [Aura.View](https://github.com/auraphp/Aura.View) *(native)* +- [Blade](http://laravel.com/docs/templates) *(compiled, framework specific)* +- [Dwoo](http://dwoo.org/) *(compiled)* +- [Mustache](https://github.com/bobthecow/mustache.php) *(compiled)* +- [PHPTAL](http://phptal.org/) *(compiled)* +- [Plates](http://platesphp.com/) *(native)* +- [Smarty](http://www.smarty.net/) *(compiled)* +- [Twig](http://twig.sensiolabs.org/) *(compiled)* +- [Zend\View](http://framework.zend.com/manual/2.3/en/modules/zend.view.quick-start.html) *(native, framework specific)* \ No newline at end of file diff --git a/_posts/08-01-01-Errors-and-Exceptions.md b/_posts/09-01-01-Errors-and-Exceptions.md similarity index 100% rename from _posts/08-01-01-Errors-and-Exceptions.md rename to _posts/09-01-01-Errors-and-Exceptions.md diff --git a/_posts/08-02-01-Errors.md b/_posts/09-02-01-Errors.md similarity index 100% rename from _posts/08-02-01-Errors.md rename to _posts/09-02-01-Errors.md diff --git a/_posts/08-03-01-Exceptions.md b/_posts/09-03-01-Exceptions.md similarity index 100% rename from _posts/08-03-01-Exceptions.md rename to _posts/09-03-01-Exceptions.md diff --git a/_posts/09-01-01-Security.md b/_posts/10-01-01-Security.md similarity index 100% rename from _posts/09-01-01-Security.md rename to _posts/10-01-01-Security.md diff --git a/_posts/09-02-01-Web-Application-Security.md b/_posts/10-02-01-Web-Application-Security.md similarity index 100% rename from _posts/09-02-01-Web-Application-Security.md rename to _posts/10-02-01-Web-Application-Security.md diff --git a/_posts/09-03-01-Password-Hashing.md b/_posts/10-03-01-Password-Hashing.md similarity index 100% rename from _posts/09-03-01-Password-Hashing.md rename to _posts/10-03-01-Password-Hashing.md diff --git a/_posts/09-04-01-Data-Filtering.md b/_posts/10-04-01-Data-Filtering.md similarity index 100% rename from _posts/09-04-01-Data-Filtering.md rename to _posts/10-04-01-Data-Filtering.md diff --git a/_posts/09-05-01-Configuration-Files.md b/_posts/10-05-01-Configuration-Files.md similarity index 100% rename from _posts/09-05-01-Configuration-Files.md rename to _posts/10-05-01-Configuration-Files.md diff --git a/_posts/09-06-01-Register-Globals.md b/_posts/10-06-01-Register-Globals.md similarity index 100% rename from _posts/09-06-01-Register-Globals.md rename to _posts/10-06-01-Register-Globals.md diff --git a/_posts/09-07-01-Error-Reporting.md b/_posts/10-07-01-Error-Reporting.md similarity index 100% rename from _posts/09-07-01-Error-Reporting.md rename to _posts/10-07-01-Error-Reporting.md diff --git a/_posts/10-01-01-Testing.md b/_posts/11-01-01-Testing.md similarity index 100% rename from _posts/10-01-01-Testing.md rename to _posts/11-01-01-Testing.md diff --git a/_posts/10-02-01-Test-Driven-Development.md b/_posts/11-02-01-Test-Driven-Development.md similarity index 100% rename from _posts/10-02-01-Test-Driven-Development.md rename to _posts/11-02-01-Test-Driven-Development.md diff --git a/_posts/10-03-01-Behavior-Driven-Development.md b/_posts/11-03-01-Behavior-Driven-Development.md similarity index 100% rename from _posts/10-03-01-Behavior-Driven-Development.md rename to _posts/11-03-01-Behavior-Driven-Development.md diff --git a/_posts/10-04-01-Complementary-Testing-Tools.md b/_posts/11-04-01-Complementary-Testing-Tools.md similarity index 100% rename from _posts/10-04-01-Complementary-Testing-Tools.md rename to _posts/11-04-01-Complementary-Testing-Tools.md diff --git a/_posts/11-01-01-Servers-and-Deployment.md b/_posts/12-01-01-Servers-and-Deployment.md similarity index 100% rename from _posts/11-01-01-Servers-and-Deployment.md rename to _posts/12-01-01-Servers-and-Deployment.md diff --git a/_posts/11-02-01-Platform-as-a-Service.md b/_posts/12-02-01-Platform-as-a-Service.md similarity index 100% rename from _posts/11-02-01-Platform-as-a-Service.md rename to _posts/12-02-01-Platform-as-a-Service.md diff --git a/_posts/11-03-01-Virtual-or-Dedicated-Servers.md b/_posts/12-03-01-Virtual-or-Dedicated-Servers.md similarity index 100% rename from _posts/11-03-01-Virtual-or-Dedicated-Servers.md rename to _posts/12-03-01-Virtual-or-Dedicated-Servers.md diff --git a/_posts/11-04-01-Shared-Servers.md b/_posts/12-04-01-Shared-Servers.md similarity index 100% rename from _posts/11-04-01-Shared-Servers.md rename to _posts/12-04-01-Shared-Servers.md diff --git a/_posts/11-05-01-Building-your-Application.md b/_posts/12-05-01-Building-your-Application.md similarity index 100% rename from _posts/11-05-01-Building-your-Application.md rename to _posts/12-05-01-Building-your-Application.md diff --git a/_posts/12-01-01-Caching.md b/_posts/13-01-01-Caching.md similarity index 100% rename from _posts/12-01-01-Caching.md rename to _posts/13-01-01-Caching.md diff --git a/_posts/12-02-01-Bytecode-Cache.md b/_posts/13-02-01-Bytecode-Cache.md similarity index 100% rename from _posts/12-02-01-Bytecode-Cache.md rename to _posts/13-02-01-Bytecode-Cache.md diff --git a/_posts/12-03-01-Object-Caching.md b/_posts/13-03-01-Object-Caching.md similarity index 100% rename from _posts/12-03-01-Object-Caching.md rename to _posts/13-03-01-Object-Caching.md diff --git a/_posts/13-01-01-Resources.md b/_posts/14-01-01-Resources.md similarity index 100% rename from _posts/13-01-01-Resources.md rename to _posts/14-01-01-Resources.md diff --git a/_posts/13-02-01-Frameworks.md b/_posts/14-02-01-Frameworks.md similarity index 100% rename from _posts/13-02-01-Frameworks.md rename to _posts/14-02-01-Frameworks.md diff --git a/_posts/13-03-01-Components.md b/_posts/14-03-01-Components.md similarity index 100% rename from _posts/13-03-01-Components.md rename to _posts/14-03-01-Components.md diff --git a/_posts/13-04-01-Books.md b/_posts/14-04-01-Books.md similarity index 100% rename from _posts/13-04-01-Books.md rename to _posts/14-04-01-Books.md diff --git a/_posts/14-01-01-Community.md b/_posts/15-01-01-Community.md similarity index 100% rename from _posts/14-01-01-Community.md rename to _posts/15-01-01-Community.md diff --git a/_posts/15-01-01-PHPDoc.md b/_posts/16-01-01-PHPDoc.md similarity index 100% rename from _posts/15-01-01-PHPDoc.md rename to _posts/16-01-01-PHPDoc.md From 4cf1099ca074cb9e54f54f04f2610942e281bf55 Mon Sep 17 00:00:00 2001 From: David Matejka Date: Sun, 27 Jul 2014 01:36:00 +0200 Subject: [PATCH 14/29] Templating: added latte link --- _posts/08-05-01-Further-Reading.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_posts/08-05-01-Further-Reading.md b/_posts/08-05-01-Further-Reading.md index fd8c160..02f3357 100644 --- a/_posts/08-05-01-Further-Reading.md +++ b/_posts/08-05-01-Further-Reading.md @@ -19,9 +19,10 @@ anchor: templating_further_reading - [Aura.View](https://github.com/auraphp/Aura.View) *(native)* - [Blade](http://laravel.com/docs/templates) *(compiled, framework specific)* - [Dwoo](http://dwoo.org/) *(compiled)* +- [Latte](https://github.com/nette/latte) *(compiled)* - [Mustache](https://github.com/bobthecow/mustache.php) *(compiled)* - [PHPTAL](http://phptal.org/) *(compiled)* - [Plates](http://platesphp.com/) *(native)* - [Smarty](http://www.smarty.net/) *(compiled)* - [Twig](http://twig.sensiolabs.org/) *(compiled)* -- [Zend\View](http://framework.zend.com/manual/2.3/en/modules/zend.view.quick-start.html) *(native, framework specific)* \ No newline at end of file +- [Zend\View](http://framework.zend.com/manual/2.3/en/modules/zend.view.quick-start.html) *(native, framework specific)* From 39caad2fa62f7f3975b7e7e8591cb729c3b8b522 Mon Sep 17 00:00:00 2001 From: James Gill Date: Sun, 3 Aug 2014 20:14:02 -0700 Subject: [PATCH 15/29] Several grammatic edits to introductory topics to improve readability and flow. --- _posts/01-02-01-Use-the-Current-Stable-Version.md | 2 +- _posts/01-03-01-Built-in-Web-Server.md | 2 +- _posts/01-04-01-Mac-Setup.md | 7 +++---- _posts/03-05-01-Command-Line-Interface.md | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/_posts/01-02-01-Use-the-Current-Stable-Version.md b/_posts/01-02-01-Use-the-Current-Stable-Version.md index 16d2f1d..fa5f8f9 100644 --- a/_posts/01-02-01-Use-the-Current-Stable-Version.md +++ b/_posts/01-02-01-Use-the-Current-Stable-Version.md @@ -6,7 +6,7 @@ anchor: use_the_current_stable_version ## Use the Current Stable Version (5.5) {#use_the_current_stable_version_title} -If you are just getting started with PHP make sure to start with the current stable release of [PHP 5.5][php-release]. PHP has made great strides adding powerful [new features](#language_highlights) over the last few years. Don't let the minor version number difference between 5.2 and 5.5 fool you, it represents _major_ improvements. If you are looking for a function or its usage, the documentation on the [php.net][php-docs] website will have the answer. +If you are getting started with PHP, start with the current stable release of [PHP 5.5][php-release]. PHP has added powerful [new features](#language_highlights) over the last few years. Though the incremental version number difference between 5.2 and 5.5 is small, it represents _major_ improvements. If you are looking for a function or its usage, the documentation on the [php.net][php-docs] website will have the answer. [php-release]: http://www.php.net/downloads.php [php-docs]: http://www.php.net/manual/en/ diff --git a/_posts/01-03-01-Built-in-Web-Server.md b/_posts/01-03-01-Built-in-Web-Server.md index a7b9fff..f33c002 100644 --- a/_posts/01-03-01-Built-in-Web-Server.md +++ b/_posts/01-03-01-Built-in-Web-Server.md @@ -6,7 +6,7 @@ anchor: builtin_web_server ## Built-in web server {#builtin_web_server_title} -You can start learning PHP without the hassle of installing and configuring a full-fledged web server (PHP 5.4+ required). To start the server, run the following from your terminal in your project's web root: +With PHP 5.4 or newer, you can start learning PHP without installing and configuring a full-fledged web server. To start the server, run the following command from your terminal in your project's web root: > php -S localhost:8000 diff --git a/_posts/01-04-01-Mac-Setup.md b/_posts/01-04-01-Mac-Setup.md index 3aed1e6..bcdbb9e 100644 --- a/_posts/01-04-01-Mac-Setup.md +++ b/_posts/01-04-01-Mac-Setup.md @@ -11,11 +11,10 @@ Mountain Lion has 5.3.10, and Mavericks has 5.4.17. To update PHP on OSX you can get it installed through a number of Mac [package managers][mac-package-managers], with [php-osx by Liip][php-osx-downloads] being recommended. -The other option is to [compile it yourself][mac-compile], in that case be sure to have installed either Xcode or -Apple's substitute ["Command Line Tools for Xcode"][apple-developer] downloadable from Apple's Mac Developer Center. +You can also [compile it yourself][mac-compile]; if you do, be sure to have installed either Xcode or +Apple's substitute ["Command Line Tools for Xcode"][apple-developer], downloadable from Apple's Mac Developer Center. -For a complete "all-in-one" package including PHP, Apache web server and MySQL database, all this with a nice control -GUI, try [MAMP][mamp-downloads] or [XAMPP][xampp]. +For a complete "all-in-one" package that includes PHP, Apache web server and MySQL database, all with a nice graphical interface, try [MAMP][mamp-downloads] or [XAMPP][xampp]. [mac-package-managers]: http://www.php.net/manual/en/install.macosx.packages.php [mac-compile]: http://www.php.net/manual/en/install.macosx.compile.php diff --git a/_posts/03-05-01-Command-Line-Interface.md b/_posts/03-05-01-Command-Line-Interface.md index bf40a88..d5d9af4 100644 --- a/_posts/03-05-01-Command-Line-Interface.md +++ b/_posts/03-05-01-Command-Line-Interface.md @@ -5,7 +5,7 @@ anchor: command_line_interface ## Command Line Interface {#command_line_interface_title} -PHP was created primarily to write web applications, but it's also useful for scripting command line interface (CLI) programs. Command line PHP programs can help you automate common tasks like testing, deployment, and application administrivia. +PHP was created to write web applications, but is also useful for scripting command line interface (CLI) programs. Command line PHP programs can help automate common tasks like testing, deployment, and application administrivia. CLI PHP programs are powerful because you can use your app's code directly without having to create and secure a web GUI for it. Just be sure not to put your CLI PHP scripts in your public web root! From d6f59a1ce01a8dd0a8f0a2f903e5622e8ec35f80 Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Fri, 15 Aug 2014 13:53:45 -0400 Subject: [PATCH 16/29] Improve to the templating section Add inheritance examples Add the word "partials" to better describe reusable pieces of code Clarify the role of templates (views) in the MVC pattern Add note of caution around Smarty auto escaping --- _posts/08-01-01-Templating.md | 2 +- _posts/08-02-01-Benefits.md | 4 +-- _posts/08-03-01-Plain-PHP-Templates.md | 36 ++++++++++++++++++++- _posts/08-04-01-Compiled-Templates.md | 45 ++++++++++++++++++++++++-- 4 files changed, 81 insertions(+), 6 deletions(-) diff --git a/_posts/08-01-01-Templating.md b/_posts/08-01-01-Templating.md index 8957e2f..3bcc5b8 100644 --- a/_posts/08-01-01-Templating.md +++ b/_posts/08-01-01-Templating.md @@ -7,6 +7,6 @@ anchor: templating Templates provide a convenient way of separating your controller and domain logic from your presentation logic. Templates typically contain the HTML of your application, but may also be used for other formats, such as XML. -Templates are often referred to as "views", the second component of the +Templates are often referred to as “views”, which make up **part of** the second component of the [model–view–controller](http://www.phptherightway.com/pages/Design-Patterns.html#model-view-controller) (MVC) software architecture pattern. \ No newline at end of file diff --git a/_posts/08-02-01-Benefits.md b/_posts/08-02-01-Benefits.md index 1da94d6..8e21de7 100644 --- a/_posts/08-02-01-Benefits.md +++ b/_posts/08-02-01-Benefits.md @@ -13,8 +13,8 @@ the client-side code (markup). Templates also improve the organization of presentation code. Templates are typically placed in a "views" folder, each defined within a single file. This approach encourages code reuse where larger blocks of code are broken into smaller, -reusable pieces. For example, your site header and footer can each be defined as templates, which are then included -before and after each page template. +reusable pieces, often called partials. For example, your site header and footer can each be defined as templates, +which are then included before and after each page template. Finally, depending on the library you use, templates can offer more security by automatically escaping user-generated content. Some libraries even offer sand-boxing, where template designers are only given access to white-listed diff --git a/_posts/08-03-01-Plain-PHP-Templates.md b/_posts/08-03-01-Plain-PHP-Templates.md index 137d6e4..57a6a53 100644 --- a/_posts/08-03-01-Plain-PHP-Templates.md +++ b/_posts/08-03-01-Plain-PHP-Templates.md @@ -16,13 +16,47 @@ frameworks, libraries like [Plates](http://platesphp.com/) or [Aura.View](https: working with plain PHP templates easier by offering modern template functionality such as inheritance, layouts and extensions. -Example of a plain PHP template (using the [Plates](http://platesphp.com/) library): +### Simple example of a plain PHP template + +Using the [Plates](http://platesphp.com/) library. {% highlight php %} + + insert('header', ['title' => 'User Profile']) ?>

    User Profile

    Hello, escape($name)?>

    insert('footer') ?> +{% endhighlight %} + +### Example of plain PHP templates using inheritance + +Using the [Plates](http://platesphp.com/) library. + +{% highlight php %} + + + + + <?=$title?> + + + +
    + section('content')?> +
    + + + +{% endhighlight %} + +{% highlight php %} + + +layout('template', ['title' => 'User Profile']) ?> + +

    User Profile

    +

    Hello, escape($name)?>

    {% endhighlight %} \ No newline at end of file diff --git a/_posts/08-04-01-Compiled-Templates.md b/_posts/08-04-01-Compiled-Templates.md index d46cd70..02aabee 100644 --- a/_posts/08-04-01-Compiled-Templates.md +++ b/_posts/08-04-01-Compiled-Templates.md @@ -7,14 +7,18 @@ anchor: compiled_templates While PHP has evolved into a mature, object oriented language, it [hasn't improved much](http://fabien.potencier.org/article/34/templating-engines-in-php) as a templating language. -Compiled templates, like [Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/), fill this void by +Compiled templates, like [Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/)*, fill this void by offering a new syntax that has been geared specifically to templating. From automatic escaping, to inheritance and simplified control structures, compiled templates are designed to be easier to write, cleaner to read and safer to use. Compiled templates can even be shared across different languages, [Mustache](http://mustache.github.io/) being a good example of this. Since these templates must be compiled there is a slight performance hit, however this is very minimal when proper caching is used. -Example of a compiled template (using the [Twig](http://twig.sensiolabs.org/) library): +**While Smarty offers automatic escaping, this feature is NOT enabled by default.* + +### Simple example of a compiled template + +Using the [Twig](http://twig.sensiolabs.org/) library. {% highlight text %} {% raw %} @@ -25,4 +29,41 @@ Example of a compiled template (using the [Twig](http://twig.sensiolabs.org/) li {% include 'footer.html' %} {% endraw %} +{% endhighlight %} + +### Example of compiled templates using inheritance + +Using the [Twig](http://twig.sensiolabs.org/) library. + +{% highlight text %} +{% raw %} +// template.php + + + + {% block title %}{% endblock %} + + + +
    + {% block content %}{% endblock %} +
    + + + +{% endraw %} +{% endhighlight %} + +{% highlight text %} +{% raw %} +// user_profile.php + +{% extends "template.html" %} + +{% block title %}User Profile{% endblock %} +{% block content %} +

    User Profile

    +

    Hello, {{ name }}

    +{% endblock %} +{% endraw %} {% endhighlight %} \ No newline at end of file From cc9361f1e66f3170b485d877ec7317e52a3e63ea Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Fri, 15 Aug 2014 14:01:56 -0400 Subject: [PATCH 17/29] Remove magic quotes from templating section. --- _posts/08-01-01-Templating.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/08-01-01-Templating.md b/_posts/08-01-01-Templating.md index 3bcc5b8..a8d3b27 100644 --- a/_posts/08-01-01-Templating.md +++ b/_posts/08-01-01-Templating.md @@ -7,6 +7,6 @@ anchor: templating Templates provide a convenient way of separating your controller and domain logic from your presentation logic. Templates typically contain the HTML of your application, but may also be used for other formats, such as XML. -Templates are often referred to as “views”, which make up **part of** the second component of the +Templates are often referred to as "views", which make up **part of** the second component of the [model–view–controller](http://www.phptherightway.com/pages/Design-Patterns.html#model-view-controller) (MVC) software architecture pattern. \ No newline at end of file From 9bb94659d88006c7b5889e992ee712cafc482b31 Mon Sep 17 00:00:00 2001 From: ISHIDA Akio Date: Tue, 19 Aug 2014 20:16:07 +0900 Subject: [PATCH 18/29] Heroku supports PHP. Fix link. Heroku PHP support is now GA. https://blog.heroku.com/archives/2014/7/15/the_new_php_on_heroku_now_generally_available --- _posts/14-01-01-Resources.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_posts/14-01-01-Resources.md b/_posts/14-01-01-Resources.md index 0d3ac38..06c3b2e 100644 --- a/_posts/14-01-01-Resources.md +++ b/_posts/14-01-01-Resources.md @@ -29,8 +29,7 @@ anchor: resources * [PagodaBox](https://pagodabox.com/) * [AppFog](https://appfog.com/) -* [Heroku](https://heroku.com) - (PHP support is undocumented but based on stable Facebook partnership [link](http://net.tutsplus.com/tutorials/php/quick-tip-deploy-php-to-heroku-in-seconds/)) +* [Heroku](https://devcenter.heroku.com/categories/php) * [fortrabbit](http://fortrabbit.com/) * [Engine Yard Cloud](https://www.engineyard.com/products/cloud) * [Red Hat OpenShift Platform](http://openshift.com) From 39624a493248e2749fd328eeac8c8036abb6808b Mon Sep 17 00:00:00 2001 From: Johnson Date: Fri, 22 Aug 2014 10:59:49 +1000 Subject: [PATCH 19/29] Fix menu links for "welcome" anchors. In the `index.html`, `{{ welcome_content |markdownify }}` generates name attributes for header tags like "my-title", whereas `{{ post.content }}` generates name attributes like "my_title". This fixes the links for only the welcome menu items so that the anchors in the menu match the different name format. --- _layouts/default.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_layouts/default.html b/_layouts/default.html index 8e09eee..073cbc5 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -35,8 +35,8 @@
  • Welcome
  • {% assign lastIsChild = false %} From 1523e9ab671e49a66e89b97a11c5de8e0c5cfc45 Mon Sep 17 00:00:00 2001 From: Johnson Date: Fri, 22 Aug 2014 11:10:36 +1000 Subject: [PATCH 20/29] Change branch names from "master" to "gh-pages". --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 43fe3da..23109f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,8 +51,8 @@ included in the project: 2. If you cloned a while ago, get the latest changes from upstream: ```bash - git checkout master - git pull upstream master + git checkout gh-pages + git pull upstream gh-pages ``` 3. Create a new topic branch (off the main project development branch) to @@ -73,7 +73,7 @@ included in the project: 6. Locally merge (or rebase) the upstream development branch into your topic branch: ```bash - git pull [--rebase] upstream master + git pull [--rebase] upstream gh-pages ``` 7. Push your topic branch up to your fork: From 2e82df6750728b71dd54df5e0ea2111cd05fea64 Mon Sep 17 00:00:00 2001 From: "Marc J. Schmidt" Date: Wed, 27 Aug 2014 22:58:09 +0200 Subject: [PATCH 21/29] Fixed wrong link for Propel --- _posts/07-03-01-Abstraction-Layers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/07-03-01-Abstraction-Layers.md b/_posts/07-03-01-Abstraction-Layers.md index ee61b63..c52554a 100644 --- a/_posts/07-03-01-Abstraction-Layers.md +++ b/_posts/07-03-01-Abstraction-Layers.md @@ -22,7 +22,7 @@ Some abstraction layers have been built using the [PSR-0][psr0] or [PSR-4][psr4] [2]: http://www.doctrine-project.org/projects/dbal.html [4]: http://packages.zendframework.com/docs/latest/manual/en/index.html#zend-db [6]: https://github.com/auraphp/Aura.Sql -[7]: http://propelorm.org/Propel/ +[7]: http://propelorm.org/ [psr0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md [psr4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md From d4d8bee33d20196fca3672de28fd4f50a6cfb94d Mon Sep 17 00:00:00 2001 From: Francisco Presencia Date: Tue, 2 Sep 2014 10:36:39 +0200 Subject: [PATCH 22/29] New stable PHP version released (5.6) http://php.net/archive/2014.php#id2014-08-28-1 --- _posts/01-02-01-Use-the-Current-Stable-Version.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_posts/01-02-01-Use-the-Current-Stable-Version.md b/_posts/01-02-01-Use-the-Current-Stable-Version.md index fa5f8f9..53a004f 100644 --- a/_posts/01-02-01-Use-the-Current-Stable-Version.md +++ b/_posts/01-02-01-Use-the-Current-Stable-Version.md @@ -1,12 +1,12 @@ --- -title: Use the Current Stable Version (5.5) +title: Use the Current Stable Version (5.6) isChild: true anchor: use_the_current_stable_version --- -## Use the Current Stable Version (5.5) {#use_the_current_stable_version_title} +## Use the Current Stable Version (5.6) {#use_the_current_stable_version_title} -If you are getting started with PHP, start with the current stable release of [PHP 5.5][php-release]. PHP has added powerful [new features](#language_highlights) over the last few years. Though the incremental version number difference between 5.2 and 5.5 is small, it represents _major_ improvements. If you are looking for a function or its usage, the documentation on the [php.net][php-docs] website will have the answer. +If you are getting started with PHP, start with the current stable release of [PHP 5.6][php-release]. PHP has added powerful [new features](#language_highlights) over the last few years. Though the incremental version number difference between 5.2 and 5.6 is small, it represents _major_ improvements. If you are looking for a function or its usage, the documentation on the [php.net][php-docs] website will have the answer. [php-release]: http://www.php.net/downloads.php [php-docs]: http://www.php.net/manual/en/ From a1602637fc1eae1e4c9f2daccf54a5322fe13d76 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Tue, 2 Sep 2014 10:32:07 +0200 Subject: [PATCH 23/29] updated to PHP 5.6 in getting started chapter --- _posts/01-02-01-Use-the-Current-Stable-Version.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_posts/01-02-01-Use-the-Current-Stable-Version.md b/_posts/01-02-01-Use-the-Current-Stable-Version.md index fa5f8f9..53a004f 100644 --- a/_posts/01-02-01-Use-the-Current-Stable-Version.md +++ b/_posts/01-02-01-Use-the-Current-Stable-Version.md @@ -1,12 +1,12 @@ --- -title: Use the Current Stable Version (5.5) +title: Use the Current Stable Version (5.6) isChild: true anchor: use_the_current_stable_version --- -## Use the Current Stable Version (5.5) {#use_the_current_stable_version_title} +## Use the Current Stable Version (5.6) {#use_the_current_stable_version_title} -If you are getting started with PHP, start with the current stable release of [PHP 5.5][php-release]. PHP has added powerful [new features](#language_highlights) over the last few years. Though the incremental version number difference between 5.2 and 5.5 is small, it represents _major_ improvements. If you are looking for a function or its usage, the documentation on the [php.net][php-docs] website will have the answer. +If you are getting started with PHP, start with the current stable release of [PHP 5.6][php-release]. PHP has added powerful [new features](#language_highlights) over the last few years. Though the incremental version number difference between 5.2 and 5.6 is small, it represents _major_ improvements. If you are looking for a function or its usage, the documentation on the [php.net][php-docs] website will have the answer. [php-release]: http://www.php.net/downloads.php [php-docs]: http://www.php.net/manual/en/ From 923ab4cfb9a8d48d8e0236b898edb0b9e6972393 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Tue, 2 Sep 2014 13:16:43 +0200 Subject: [PATCH 24/29] books and PHP 6 updates --- _posts/14-04-01-Books.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_posts/14-04-01-Books.md b/_posts/14-04-01-Books.md index 5282009..8229067 100644 --- a/_posts/14-04-01-Books.md +++ b/_posts/14-04-01-Books.md @@ -7,7 +7,8 @@ anchor: books There are a lot of books around for PHP but some are sadly now quite old and no longer contain accurate information. There are even books published for "PHP 6" -which does not exist, and might not now ever exist because of those books. +which does not exist, and will not now ever exist. The next major version of PHP +will be named "PHP 7" because of those books. This section aims to be a living document for recommended books on PHP development in general. If you would like your book to be added, send a PR and From 7d81279858e98e168a5a13fd26221eae05926490 Mon Sep 17 00:00:00 2001 From: Kayla Daniels Date: Thu, 4 Sep 2014 10:13:42 -0400 Subject: [PATCH 25/29] Added Phansible under "a little help" --- _posts/01-06-01-Vagrant.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_posts/01-06-01-Vagrant.md b/_posts/01-06-01-Vagrant.md index 53fe397..db10f4c 100644 --- a/_posts/01-06-01-Vagrant.md +++ b/_posts/01-06-01-Vagrant.md @@ -29,6 +29,7 @@ If you need a little help to start using Vagrant there are three services that m - [Puphpet][puphpet]: simple GUI to set up virtual machines for PHP development. **Heavily focused in PHP**. Besides local VMs, can be used to deploy to cloud services as well. The provisioning is made with Puppet. - [Protobox][protobox]: is a layer on top of vagrant and a web GUI to setup virtual machines for web development. A single YAML document controls everything that is installed on the virtual machine. +- [Phansible][phansible]: provides an easy to use interface that helps you generate Ansible Playbooks for PHP based projects. [vagrant]: http://vagrantup.com/ [puppet]: http://www.puppetlabs.com/ @@ -36,3 +37,4 @@ If you need a little help to start using Vagrant there are three services that m [rove]: http://rove.io/ [puphpet]: https://puphpet.com/ [protobox]: http://getprotobox.com/ +[phansible]: http://phansible.com/ From c095d6e6ac2e74a0234e6be31945b9332381f1eb Mon Sep 17 00:00:00 2001 From: Kevin Ji Date: Mon, 15 Sep 2014 01:53:27 -0700 Subject: [PATCH 26/29] Windows Setup: Use English WAMP link --- _posts/01-05-01-Windows-Setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/01-05-01-Windows-Setup.md b/_posts/01-05-01-Windows-Setup.md index f37e75d..6094516 100644 --- a/_posts/01-05-01-Windows-Setup.md +++ b/_posts/01-05-01-Windows-Setup.md @@ -24,5 +24,5 @@ PHP. [zsce]: http://www.zend.com/en/products/server-ce/ [xampp]: http://www.apachefriends.org/en/xampp.html [easyphp]: http://www.easyphp.org/ -[wamp]: http://www.wampserver.com/ +[wamp]: http://www.wampserver.com/en/ [php-iis]: http://php.iis.net/ From ecdb28562e6a8912f5e045f046deaf60f271a89f Mon Sep 17 00:00:00 2001 From: Kevin Ji Date: Mon, 15 Sep 2014 01:57:29 -0700 Subject: [PATCH 27/29] Mac Setup: Adjust MAMP link --- _posts/01-04-01-Mac-Setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/01-04-01-Mac-Setup.md b/_posts/01-04-01-Mac-Setup.md index bcdbb9e..5b2099b 100644 --- a/_posts/01-04-01-Mac-Setup.md +++ b/_posts/01-04-01-Mac-Setup.md @@ -20,6 +20,6 @@ For a complete "all-in-one" package that includes PHP, Apache web server and MyS [mac-compile]: http://www.php.net/manual/en/install.macosx.compile.php [xcode-gcc-substitution]: https://github.com/kennethreitz/osx-gcc-installer [apple-developer]: https://developer.apple.com/downloads -[mamp-downloads]: http://www.mamp.info/en/downloads/index.html +[mamp-downloads]: http://www.mamp.info/en/downloads/ [php-osx-downloads]: http://php-osx.liip.ch/ [xampp]: http://www.apachefriends.org/en/xampp.html From be36a5d6c16b9283965959b19fbf41ad695a543d Mon Sep 17 00:00:00 2001 From: Kevin Ji Date: Mon, 15 Sep 2014 01:58:28 -0700 Subject: [PATCH 28/29] Mac Setup: Adjust spelling of "OS X" --- _posts/01-04-01-Mac-Setup.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_posts/01-04-01-Mac-Setup.md b/_posts/01-04-01-Mac-Setup.md index 5b2099b..8c772cd 100644 --- a/_posts/01-04-01-Mac-Setup.md +++ b/_posts/01-04-01-Mac-Setup.md @@ -5,10 +5,10 @@ anchor: mac_setup ## Mac Setup {#mac_setup_title} -OSX comes prepackaged with PHP but it is normally a little behind the latest stable. Lion comes with PHP 5.3.6, +OS X comes prepackaged with PHP but it is normally a little behind the latest stable. Lion comes with PHP 5.3.6, Mountain Lion has 5.3.10, and Mavericks has 5.4.17. -To update PHP on OSX you can get it installed through a number of Mac [package managers][mac-package-managers], with +To update PHP on OS X you can get it installed through a number of Mac [package managers][mac-package-managers], with [php-osx by Liip][php-osx-downloads] being recommended. You can also [compile it yourself][mac-compile]; if you do, be sure to have installed either Xcode or From 7e298797228bfdaff385842601b7377c4a6f54b5 Mon Sep 17 00:00:00 2001 From: Jason Schein Date: Wed, 17 Sep 2014 19:06:55 -0700 Subject: [PATCH 29/29] Add chef video tutorial to Building-your-Application page. --- _posts/12-05-01-Building-your-Application.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/12-05-01-Building-your-Application.md b/_posts/12-05-01-Building-your-Application.md index 6a9e5bc..b417f9d 100644 --- a/_posts/12-05-01-Building-your-Application.md +++ b/_posts/12-05-01-Building-your-Application.md @@ -49,7 +49,7 @@ Chef resources for PHP developers: * [Three part blog series about deploying a LAMP application with Chef, Vagrant, and EC2](http://www.jasongrimes.org/2012/06/managing-lamp-environments-with-chef-vagrant-and-ec2-1-of-3/) * [Chef Cookbook which installs and configures PHP 5.3 and the PEAR package management system](https://github.com/opscode-cookbooks/php) - +* [Chef video tutorial series by Opscode, the makers of chef](https://www.youtube.com/playlist?list=PLrmstJpucjzWKt1eWLv88ZFY4R1jW8amR) Further reading: * [Automate your project with Apache Ant](http://net.tutsplus.com/tutorials/other/automate-your-projects-with-apache-ant/)