mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-06 14:06:34 +02:00
Merge pull request #926 from Xymph/fix-spelling-punc-etc
Fix spelling, grammar, punctuation, etc.
This commit is contained in:
@@ -26,7 +26,7 @@ You should read the `CONTRIBUTING.md` file for precise instructions and tips. Bu
|
||||
|
||||
### Contributor Style Guide
|
||||
|
||||
1. Use American English spelling (*primary English repo only*)
|
||||
1. Use American English spelling (*primary English repo only*).
|
||||
2. Use four (4) spaces to indent text; do not use tabs.
|
||||
3. Wrap all text to 120 characters.
|
||||
4. Code samples should adhere to PSR-1 or higher.
|
||||
|
@@ -11,7 +11,7 @@ primarily of commonly needed datastructure classes (stack, queue, heap, and so o
|
||||
over these datastructures or your own classes which implement SPL interfaces.
|
||||
|
||||
* [Read about the SPL][spl]
|
||||
* [SPL video course on Lynda.com(Paid)][spllynda]
|
||||
* [SPL video course on Lynda.com (paid)][spllynda]
|
||||
|
||||
|
||||
[spl]: https://secure.php.net/book.spl
|
||||
|
@@ -32,7 +32,7 @@ don't try this if your project will contain more than a couple of pages.
|
||||
The most classic way and often taken as reference for i18n and l10n is a [Unix tool called `gettext`][gettext]. It dates
|
||||
back to 1995 and is still a complete implementation for translating software. It is easy enough to get running, while
|
||||
still sporting powerful supporting tools. It is about Gettext we will be talking here. Also, to help you not get messy
|
||||
over the command-line, we will be presenting a great GUI application that can be used to easily update your l10n source
|
||||
over the command-line, we will be presenting a great GUI application that can be used to easily update your l10n source.
|
||||
|
||||
### Other tools
|
||||
|
||||
@@ -41,7 +41,7 @@ install or sport additional features or i18n file formats. In this document, we
|
||||
PHP core, but here we list others for completion:
|
||||
|
||||
- [aura/intl][aura-intl]: Provides internationalization (I18N) tools, specifically package-oriented per-locale message
|
||||
translation. It uses array formats for message. Does not provide a message extractor, but does provide advanced
|
||||
translation. It uses array formats for messages. Does not provide a message extractor, but does provide advanced
|
||||
message formatting via the `intl` extension (including pluralized messages).
|
||||
- [oscarotero/Gettext][oscarotero]: Gettext support with an OO interface; includes improved helper functions, powerful
|
||||
extractors for several file formats (some of them not supported natively by the `gettext` command), and can also export
|
||||
@@ -248,7 +248,7 @@ the actual interface. Given that, let's tie together what we have discussed so f
|
||||
- [`gettext()`][func] simply translates a `msgid` into its corresponding `msgstr` for a given language. There's also
|
||||
the shorthand function `_()` that works the same way;
|
||||
- [`ngettext()`][n_func] does the same but with plural rules;
|
||||
- there's also [`dgettext()`][d_func] and [`dngettext()`][dn_func], that allows you to override the domain for a single
|
||||
- There are also [`dgettext()`][d_func] and [`dngettext()`][dn_func], that allow you to override the domain for a single
|
||||
call. More on domain configuration in the next example.
|
||||
|
||||
#### 2. A sample setup file (`i18n_setup.php` as used above), selecting the correct locale and configuring Gettext
|
||||
|
@@ -12,5 +12,5 @@ Locator in to your classes arguably creates a harder dependency on the container
|
||||
It also makes your code much less transparent and ultimately harder to test.
|
||||
|
||||
Most modern frameworks have their own Dependency Injection Container that allows you to wire your dependencies together
|
||||
through configuration. What this means in practice is that you can write application code that is as clean and de-
|
||||
coupled as the framework it is built on.
|
||||
through configuration. What this means in practice is that you can write application code that is as clean and
|
||||
de-coupled as the framework it is built on.
|
||||
|
@@ -33,7 +33,7 @@ The other use for unit tests is contributing to open source. If you can write a
|
||||
which accepts pull requests then you should suggest this as a requirement.
|
||||
|
||||
[PHPUnit](https://phpunit.de/) is the de-facto testing framework for writing unit tests for PHP applications, but there
|
||||
are several alternatives
|
||||
are several alternatives:
|
||||
|
||||
* [atoum](https://github.com/atoum/atoum)
|
||||
* [Kahlan](https://github.com/crysalead/kahlan)
|
||||
|
@@ -49,7 +49,7 @@ Managing and configuring servers can be a daunting task when faced with many ser
|
||||
|
||||
[Ansible] is a tool that manages your infrastructure through YAML files. It's simple to get started with and can manage complex and large scale applications. There is an API for managing cloud instances and it can manage them through a dynamic inventory using certain tools.
|
||||
|
||||
[Puppet] is a tool that has its own language and file types for managing servers and configurations. It can be used in a master/client setup or it can be used in a "master-less" mode. In the master/client mode the clients will poll the central master(s) for new configuration on set intervals and update itself if necessary. In the master-less mode you can push changes to your nodes.
|
||||
[Puppet] is a tool that has its own language and file types for managing servers and configurations. It can be used in a master/client setup or it can be used in a "master-less" mode. In the master/client mode the clients will poll the central master(s) for new configuration on set intervals and update themselves if necessary. In the master-less mode you can push changes to your nodes.
|
||||
|
||||
[Chef] is a powerful Ruby based system integration framework that you can build your whole server environment or virtual boxes with. It integrates well with Amazon Web Services through their service called OpsWorks.
|
||||
|
||||
|
@@ -11,7 +11,7 @@ A typical LAMP application might have three containers: a web server, a PHP-FPM
|
||||
|
||||
You can generate containers from the command line (see example below) or, for ease of maintenance, build a `docker-compose.yml` file for your project specifying which to create and how they communicate with one another.
|
||||
|
||||
Docker may help if you're developing multiple websites and want the separation that comes from installing each on it's own virtual machine, but don't have the necessary disk space or the time to keep everything up to date. It's efficient: the installation and downloads are quicker, you only need to store one copy of each image however often it's used, containers need less RAM and share the same OS kernel, so you can have more servers running simultaneously, and it takes a matter of seconds to stop and start them, no need to wait for a full server boot.
|
||||
Docker may help if you're developing multiple websites and want the separation that comes from installing each on its own virtual machine, but don't have the necessary disk space or the time to keep everything up to date. It's efficient: the installation and downloads are quicker, you only need to store one copy of each image however often it's used, containers need less RAM and share the same OS kernel, so you can have more servers running simultaneously, and it takes a matter of seconds to stop and start them, no need to wait for a full server boot.
|
||||
|
||||
### Example: Running your PHP Applications in Docker
|
||||
|
||||
@@ -22,7 +22,7 @@ The following will download a fully functional Apache installation with the late
|
||||
docker run -d --name my-php-webserver -p 8080:80 -v /path/to/your/php/files:/var/www/html/ php:apache
|
||||
{% endhighlight %}
|
||||
|
||||
This will initialize and launch your container. `-d` makes it runs in the background. To stop and start it, simply run `docker stop my-php-webserver` and `docker start my-php-webserver` (the other parameters are not needed again).
|
||||
This will initialize and launch your container. `-d` makes it run in the background. To stop and start it, simply run `docker stop my-php-webserver` and `docker start my-php-webserver` (the other parameters are not needed again).
|
||||
|
||||
### Learn more about Docker
|
||||
|
||||
|
@@ -9,7 +9,7 @@ title: Other Useful Resources
|
||||
### Cheatsheets
|
||||
|
||||
* [PHP Cheatsheets](http://phpcheatsheets.com/) - for variable comparisons, arithmetics and variable testing in various PHP versions.
|
||||
* [Modern PHP Cheatsheet](https://github.com/smknstd/modern-php-cheatsheet) documents modern (PHP 7.0+) idioms in a unified document.
|
||||
* [Modern PHP Cheatsheet](https://github.com/smknstd/modern-php-cheatsheet) - documents modern (PHP 7.0+) idioms in a unified document.
|
||||
* [OWASP Security Cheatsheets](https://www.owasp.org/index.php/OWASP_Cheat_Sheet_Series) - provides a concise collection of high value information on specific application security topics.
|
||||
|
||||
### More best practices
|
||||
|
@@ -21,7 +21,7 @@ for modern, secure, and fast cryptography.
|
||||
|
||||
* [Build APIs You Won't Hate](https://apisyouwonthate.com/) - Everyone and their dog wants an API,
|
||||
so you should probably learn how to build them.
|
||||
* [Modern PHP](http://shop.oreilly.com/product/0636920033868.do) - covers modern PHP features, best practices, testing, tuning, deployment and setting up a dev environment.
|
||||
* [Modern PHP](http://shop.oreilly.com/product/0636920033868.do) - Covers modern PHP features, best practices, testing, tuning, deployment and setting up a dev environment.
|
||||
* [Building Secure PHP Apps](https://leanpub.com/buildingsecurephpapps) - Learn the security basics that a senior
|
||||
developer usually acquires over years of experience, all condensed down into one quick and easy handbook
|
||||
* [Modernizing Legacy Applications In PHP](https://leanpub.com/mlaphp) - Get your code under control in a series of
|
||||
|
@@ -5,7 +5,7 @@ anchor: elephpants
|
||||
|
||||
## ElePHPants {#elephpants_title}
|
||||
|
||||
[ElePHPant][elephpant] is that beautiful mascot of the PHP project with elephant in their design. It was originally designed for the PHP project in 1998 by [Vincent Pontier][vincent-pontier] - spiritual father of thousands of elePHPants around the world and 10 years later adorable plush elephant toy came to birth as well. Now elePHPants are present at many PHP conferences and with many PHP developers at their computers for fun and inspiration.
|
||||
[ElePHPant][elephpant] is that beautiful mascot of the PHP project with an elephant in its design. It was originally designed for the PHP project in 1998 by [Vincent Pontier][vincent-pontier] - spiritual father of thousands of elePHPants around the world - and ten years later adorable plush elephant toys came to birth as well. Now elePHPants are present at many PHP conferences and with many PHP developers at their computers for fun and inspiration.
|
||||
|
||||
[Interview with Vincent Pontier][vincent-pontier-interview]
|
||||
|
||||
|
@@ -142,8 +142,8 @@ add new output types without affecting the client code.
|
||||
|
||||
You will see how each concrete 'output' class implements an OutputInterface - this serves two purposes, primarily it
|
||||
provides a simple contract which must be obeyed by any new concrete implementations. Secondly by implementing a common
|
||||
interface you will see in the next section that you can now utilise [Type Hinting](http://php.net/language.oop5.typehinting) to ensure that the client which is utilising these behaviours is of the correct type in
|
||||
this case 'OutputInterface'.
|
||||
interface you will see in the next section that you can now utilise [Type Hinting](http://php.net/language.oop5.typehinting) to ensure that the client which is utilising these behaviours is of the correct type,
|
||||
in this case 'OutputInterface'.
|
||||
|
||||
The next snippet of code outlines how a calling client class might use one of these algorithms and even better set the
|
||||
behaviour required at runtime:
|
||||
@@ -166,8 +166,8 @@ class SomeClient
|
||||
}
|
||||
{% endhighlight %}
|
||||
|
||||
The calling client class above has a private property which must be set at runtime and be of type 'OutputInterface'
|
||||
once this property is set a call to loadOutput() will call the load() method in the concrete class of the output type
|
||||
The calling client class above has a private property which must be set at runtime and be of type 'OutputInterface'.
|
||||
Once this property is set a call to loadOutput() will call the load() method in the concrete class of the output type
|
||||
that has been set.
|
||||
|
||||
{% highlight php %}
|
||||
@@ -197,7 +197,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 lets you break up code into logical objects
|
||||
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
|
||||
|
@@ -80,7 +80,7 @@ function test($a)
|
||||
Switch statements are a great way to avoid typing endless if's and elseif's, but there are a few things to be aware of:
|
||||
|
||||
- Switch statements only compare values, and not the type (equivalent to '==')
|
||||
- They Iterate case by case until a match is found. If no match is found, then the default is used (if defined)
|
||||
- They iterate case by case until a match is found. If no match is found, then the default is used (if defined)
|
||||
- Without a 'break', they will continue to implement each case until reaching a break/return
|
||||
- Within a function, using 'return' alleviates the need for 'break' as it ends the function
|
||||
|
||||
@@ -248,7 +248,7 @@ Example of string
|
||||
spanning multiple lines
|
||||
using nowdoc syntax.
|
||||
$a does not parse.
|
||||
EOD; // closing 'EOD' must be on it's own line, and to the left most point
|
||||
EOD; // closing 'EOD' must be on its own line, and to the left most point
|
||||
|
||||
/**
|
||||
* Output:
|
||||
@@ -276,7 +276,7 @@ Example of string
|
||||
spanning multiple lines
|
||||
using heredoc syntax.
|
||||
$a are parsed.
|
||||
EOD; // closing 'EOD' must be on it's own line, and to the left most point
|
||||
EOD; // closing 'EOD' must be on its own line, and to the left most point
|
||||
|
||||
/**
|
||||
* Output:
|
||||
@@ -323,8 +323,8 @@ results can vary. If you are working with a small number of values, concatenatio
|
||||
values, interpolating is minutely faster.
|
||||
|
||||
Regardless of what you are doing with strings, none of the types will ever have any noticeable impact on your
|
||||
application. Trying to rewrite code to use one or the other is always an exercise in futility, so avoid this micro-
|
||||
optimization unless you really understand the meaning and impact of the differences.
|
||||
application. Trying to rewrite code to use one or the other is always an exercise in futility, so avoid this
|
||||
micro-optimization unless you really understand the meaning and impact of the differences.
|
||||
|
||||
* [Disproving the Single Quotes Performance Myth](http://nikic.github.io/2012/01/09/Disproving-the-Single-Quotes-Performance-Myth.html)
|
||||
|
||||
@@ -362,7 +362,7 @@ return ($a == 5) ? 'yay' : 'nope'; // this example will return 'yay'
|
||||
{% endhighlight %}
|
||||
|
||||
It should be noted that you do not need to use a ternary operator for returning a boolean value. An example of this
|
||||
would be.
|
||||
would be:
|
||||
|
||||
{% highlight php %}
|
||||
<?php
|
||||
|
Reference in New Issue
Block a user