mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-24 06:03:14 +02:00
Merge branch 'gh-pages' of github.com:codeguy/php-the-right-way into gh-pages
This commit is contained in:
@@ -19,6 +19,7 @@ and applications that implement the components can have consistency even when wo
|
||||
* [Read about PSR-2][psr2]
|
||||
* [Read about PEAR Coding Standards][pear-cs]
|
||||
* [Read about Zend Coding Standards][zend-cs]
|
||||
* [Read about Symfony Coding Standards][symfony-cs]
|
||||
|
||||
You can use [PHP_CodeSniffer][phpcs] to check code against any one of these recommendations, and plugins for text editors
|
||||
like [Sublime Text 2][st-cs] to be given real time feedback.
|
||||
@@ -35,6 +36,7 @@ by all current and future parties who may be working on the codebase.
|
||||
[psr2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
|
||||
[pear-cs]: http://pear.php.net/manual/en/standards.php
|
||||
[zend-cs]: http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards
|
||||
[symfony-cs]: http://symfony.com/doc/current/contributing/code/standards.html
|
||||
[phpcs]: http://pear.php.net/package/PHP_CodeSniffer/
|
||||
[st-cs]: https://github.com/benmatselby/sublime-phpcs
|
||||
[phpcsfixer]: http://cs.sensiolabs.org/
|
||||
|
@@ -45,7 +45,7 @@ which will delete all of your users! Instead, you should sanitize the ID input u
|
||||
<?php
|
||||
$pdo = new PDO('sqlite:users.db');
|
||||
$stmt = $pdo->prepare('SELECT name FROM users WHERE id = :id');
|
||||
$stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT); //<-- Automatically sanitized by PDO
|
||||
$stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT); // <-- Automatically sanitized by PDO
|
||||
$stmt->execute();
|
||||
{% endhighlight %}
|
||||
|
||||
|
@@ -22,9 +22,9 @@ require 'password.php';
|
||||
$passwordHash = password_hash('secret-password', PASSWORD_DEFAULT);
|
||||
|
||||
if (password_verify('bad-password', $passwordHash)) {
|
||||
//Correct Password
|
||||
// Correct Password
|
||||
} else {
|
||||
//Wrong password
|
||||
// Wrong password
|
||||
}
|
||||
{% endhighlight %}
|
||||
|
||||
|
@@ -30,10 +30,11 @@ you run a project which accepts pull requests then you should suggest this as a
|
||||
[PHPUnit](http://phpunit.de) is the de-facto testing framework for writing unit tests for PHP
|
||||
applications, but there are several alternatives
|
||||
|
||||
* [SimpleTest](http://simpletest.org)
|
||||
* [Enhance PHP](http://www.enhance-php.com/)
|
||||
* [PUnit](http://punit.smf.me.uk/)
|
||||
* [atoum](https://github.com/atoum/atoum)
|
||||
* [Enhance PHP](https://github.com/Enhance-PHP/Enhance-PHP)
|
||||
* [PUnit](http://punit.smf.me.uk/)
|
||||
* [SimpleTest](http://simpletest.org)
|
||||
|
||||
|
||||
### Integration Testing
|
||||
|
||||
|
@@ -12,7 +12,7 @@
|
||||
* [Derick Rethans](http://twitter.com/derickr)
|
||||
* [Chris Shiflett](http://twitter.com/shiflett)
|
||||
* [Sebastian Bergmann](http://twitter.com/s_bergmann)
|
||||
* [Matthew Weier O'Phinney](http://twitter.com/weierophinney)
|
||||
* [Matthew Weier O'Phinney](http://twitter.com/mwop)
|
||||
* [Pádraic Brady](http://twitter.com/padraicb)
|
||||
* [Anthony Ferrara](http://twitter.com/ircmaxell)
|
||||
* [Nikita Popov](http://twitter.com/nikita_ppv)
|
||||
|
@@ -6,7 +6,7 @@ title: Design Patterns
|
||||
# Design Patterns
|
||||
|
||||
There are numerous ways to structure the code and project for you web application, and you can put as much or as little
|
||||
thought as you like into architecting. But it is usually a good idea to follow to common patterns because it will make
|
||||
thought as you like into architecting. But it is usually a good idea to follow common patterns because it will make
|
||||
your code easier to manage and easier for others to understand.
|
||||
|
||||
* [Architectural pattern on Wikipedia](https://en.wikipedia.org/wiki/Architectural_pattern)
|
||||
@@ -51,7 +51,7 @@ print_r($veyron->get_make_and_model()); // outputs "Bugatti Veyron"
|
||||
{% endhighlight %}
|
||||
|
||||
This code uses a factory to create the Automobile object. There are two possible benefits to building your code this
|
||||
way, the first is that if you need to change, rename, or replace the Automobile class later on you can do so and you
|
||||
way; the first is that if you need to change, rename, or replace the Automobile class later on you can do so and you
|
||||
will only have to modify the code in the factory, instead of every place in your project that uses the Automobile
|
||||
class. The second possible benefit is that if creating the object is a complicated job you can do all of the work in
|
||||
the factory, instead of repeating it every time you want to create a new instance.
|
||||
@@ -250,11 +250,7 @@ and gives you a central place to hook in code that should be run for every reque
|
||||
|
||||
## Model-View-Controller
|
||||
|
||||
The model-view-controller (MVC) pattern and its relatives HMVC and MVVM let you break up code into logical objects that
|
||||
serve very specific purposes. Models serve as a data access layer where data is fetched and returned in formats usable
|
||||
throughout your application. Controllers handle the request, process the data returned from models and load views to
|
||||
send in the response. And views are display templates (markup, xml, etc) that are sent in the response to the web
|
||||
browser.
|
||||
The model-view-controller (MVC) pattern and its relatives HMVC and MVVM lets you break up code into logical objects that serve very specific purposes. Models serve as a data access layer where data is fetched and returned in formats usable throughout your application. Controllers handle the request, process the data returned from models and load views to send in the response. And views are display templates (markup, xml, etc) that are sent in the response to the web browser.
|
||||
|
||||
MVC is the most common architectural pattern used in the popular [PHP frameworks](https://github.com/codeguy/php-the-right-way/wiki/Frameworks).
|
||||
|
||||
|
Reference in New Issue
Block a user