20 | * [https://designpatternsphp.readthedocs.io/](https://designpatternsphp.readthedocs.io/en/latest/) ([PDF download](https://www.computer-pdf.com/web-programming/php/924-tutorial-designpatternsphp-documentation.html))
21 |
--------------------------------------------------------------------------------
/_posts/06-01-01-Dependency-Injection.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Dependency Injection
3 | anchor: dependency_injection
4 | ---
5 |
6 | # Dependency Injection {#dependency_injection_title}
7 |
8 | From [Wikipedia](https://wikipedia.org/wiki/Dependency_injection):
9 |
10 | > Dependency injection is a software design pattern that allows the removal of hard-coded dependencies and makes it
11 | > possible to change them, whether at run-time or compile-time.
12 |
13 | This quote makes the concept sound much more complicated than it actually is. Dependency Injection is providing a
14 | component with its dependencies either through constructor injection, method calls or the setting of properties. It is
15 | that simple.
16 |
--------------------------------------------------------------------------------
/_posts/06-02-01-Basic-Concept.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: basic_concept
4 | ---
5 |
6 | ## Basic Concept {#basic_concept_title}
7 |
8 | We can demonstrate the concept with a simple, yet naive example.
9 |
10 | Here we have a `Database` class that requires an adapter to speak to the database. We instantiate the adapter in the
11 | constructor and create a hard dependency. This makes testing difficult and means the `Database` class is very tightly
12 | coupled to the adapter.
13 |
14 | {% highlight php %}
15 | adapter = new MySqlAdapter;
25 | }
26 | }
27 |
28 | class MysqlAdapter {}
29 | {% endhighlight %}
30 |
31 | This code can be refactored to use Dependency Injection and therefore loosen the dependency.
32 | Here, we inject the dependency in a constructor and use the [constructor property promotion][php-constructor-promotion] so it is available as a property across the class:
33 |
34 | {% highlight php %}
35 | query("SELECT some_field FROM some_table");
18 | $row = $statement->fetch(PDO::FETCH_ASSOC);
19 | echo htmlentities($row['some_field']);
20 |
21 | // PDO + SQLite
22 | $pdo = new PDO('sqlite:/path/db/foo.sqlite');
23 | $statement = $pdo->query("SELECT some_field FROM some_table");
24 | $row = $statement->fetch(PDO::FETCH_ASSOC);
25 | echo htmlentities($row['some_field']);
26 | {% endhighlight %}
27 |
28 | PDO will not translate your SQL queries or emulate missing features; it is purely for connecting to multiple types of
29 | database with the same API.
30 |
31 | More importantly, `PDO` allows you to safely inject foreign input (e.g. IDs) into your SQL queries without worrying
32 | about database SQL injection attacks.
33 | This is possible using PDO statements and bound parameters.
34 |
35 | Let's assume a PHP script receives a numeric ID as a query parameter. This ID should be used to fetch a user record
36 | from a database. This is the `wrong` way to do this:
37 |
38 | {% highlight php %}
39 | query("SELECT name FROM users WHERE id = " . $_GET['id']); // <-- NO!
42 | {% endhighlight %}
43 |
44 | This is terrible code. You are inserting a raw query parameter into a SQL query. This will get you hacked in a
45 | heartbeat, using a practice called [SQL Injection]. Just imagine if a hacker passes in an inventive `id` parameter by
46 | calling a URL like `http://domain.com/?id=1%3BDELETE+FROM+users`. This will set the `$_GET['id']` variable to `1;DELETE
47 | FROM users` which will delete all of your users! Instead, you should sanitize the ID input using PDO bound parameters.
48 |
49 | {% highlight php %}
50 | prepare('SELECT name FROM users WHERE id = :id');
53 | $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); // <-- filter your data first (see [Data Filtering](#data_filtering)), especially important for INSERT, UPDATE, etc.
54 | $stmt->bindParam(':id', $id, PDO::PARAM_INT); // <-- Automatically sanitized for SQL by PDO
55 | $stmt->execute();
56 | {% endhighlight %}
57 |
58 | This is correct code. It uses a bound parameter on a PDO statement. This escapes the foreign input ID before it is
59 | introduced to the database preventing potential SQL injection attacks.
60 |
61 | For writes, such as INSERT or UPDATE, it's especially critical to still [filter your data](#data_filtering) first and sanitize it for other things (removal of HTML tags, JavaScript, etc). PDO will only sanitize it for SQL, not for your application.
62 |
63 | * [Learn about PDO][pdo]
64 |
65 | You should also be aware that database connections use up resources and it was not unheard-of to have resources
66 | exhausted if connections were not implicitly closed, however this was more common in other languages. Using PDO you can
67 | implicitly close the connection by destroying the object by ensuring all remaining references to it are deleted, i.e.
68 | set to NULL. If you don't do this explicitly, PHP will automatically close the connection when your script ends -
69 | unless of course you are using persistent connections.
70 |
71 | * [Learn about PDO connections]
72 |
73 |
74 | [pdo]: https://www.php.net/pdo
75 | [SQL Injection]: https://web.archive.org/web/20210413233627/http://wiki.hashphp.org/Validation
76 | [Learn about PDO connections]: https://www.php.net/pdo.connections
77 |
--------------------------------------------------------------------------------
/_posts/07-04-01-Interacting-via-Code.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | title: Interacting with Databases
4 | anchor: databases_interacting
5 | ---
6 |
7 | ## Interacting with Databases {#databases_interacting_title}
8 |
9 | When developers first start to learn PHP, they often end up mixing their database interaction up with their
10 | presentation logic, using code that might look like this:
11 |
12 | {% highlight php %}
13 |
14 | query('SELECT * FROM table') as $row) {
16 | echo "- ".$row['field1']." - ".$row['field1']."
";
17 | }
18 | ?>
19 |
20 | {% endhighlight %}
21 |
22 | This is bad practice for all sorts of reasons, mainly that it's hard to debug, hard to test, hard to read and it is
23 | going to output a lot of fields if you don't put a limit on there.
24 |
25 | While there are many other solutions to doing this - depending on if you prefer [OOP](/#object-oriented-programming) or
26 | [functional programming](/#functional-programming) - there must be some element of separation.
27 |
28 | Consider the most basic step:
29 |
30 | {% highlight php %}
31 | query('SELECT * FROM table');
34 | }
35 |
36 | $results = getAllFoos($db);
37 | foreach ($results as $row) {
38 | echo "".$row['field1']." - ".$row['field1'].""; // BAD!!
39 | }
40 | {% endhighlight %}
41 |
42 | That is a good start. Put those two items in two different files and you've got some clean separation.
43 |
44 | Create a class to place that method in and you have a "Model". Create a simple `.php` file to put the presentation
45 | logic in and you have a "View", which is very nearly [MVC] - a common OOP architecture for most
46 | [frameworks](/#frameworks).
47 |
48 | **foo.php**
49 |
50 | {% highlight php %}
51 | getAllFoos();
61 |
62 | // Show the view
63 | include 'views/foo-list.php';
64 | {% endhighlight %}
65 |
66 |
67 | **models/FooModel.php**
68 |
69 | {% highlight php %}
70 | db->query('SELECT * FROM table');
79 | }
80 | }
81 | {% endhighlight %}
82 |
83 | **views/foo-list.php**
84 |
85 | {% highlight php %}
86 |
87 | = $row['field1'] ?> - = $row['field1'] ?>
88 |
89 | {% endhighlight %}
90 |
91 | This is essentially the same as what most modern frameworks are doing, albeit a little more manual. You might not
92 | need to do all of that every time, but mixing together too much presentation logic and database interaction can be a
93 | real problem if you ever want to [unit-test](/#unit-testing) your application.
94 |
95 |
96 | [MVC]: https://code.tutsplus.com/tutorials/mvc-for-noobs--net-10488
97 |
--------------------------------------------------------------------------------
/_posts/07-05-01-Abstraction-Layers.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | title: Abstraction Layers
4 | anchor: databases_abstraction_layers
5 | ---
6 |
7 | ## Abstraction Layers {#databases_abstraction_layers_title}
8 |
9 | Many frameworks provide their own abstraction layer which may or may not sit on top of [PDO][1]. These will often
10 | emulate features for one database system that is missing from another by wrapping your queries in PHP methods, giving
11 | you actual database abstraction instead of just the connection abstraction that PDO provides. This will of course add a
12 | little overhead, but if you are building a portable application that needs to work with MySQL, PostgreSQL and SQLite
13 | then a little overhead will be worth it for the sake of code cleanliness.
14 |
15 | Some abstraction layers have been built using the [PSR-0][psr0] or [PSR-4][psr4] namespace standards so can be
16 | installed in any application you like:
17 |
18 | * [Atlas][5]
19 | * [Aura SQL][6]
20 | * [Doctrine2 DBAL][2]
21 | * [Medoo][8]
22 | * [Propel][7]
23 | * [laminas-db][4]
24 |
25 |
26 | [1]: https://www.php.net/book.pdo
27 | [2]: https://www.doctrine-project.org/projects/dbal.html
28 | [4]: https://docs.laminas.dev/laminas-db/
29 | [5]: https://atlasphp.io
30 | [6]: https://github.com/auraphp/Aura.Sql
31 | [7]: https://propelorm.org/
32 | [8]: https://medoo.in/
33 | [psr0]: https://www.php-fig.org/psr/psr-0/
34 | [psr4]: https://www.php-fig.org/psr/psr-4/
35 |
--------------------------------------------------------------------------------
/_posts/08-01-01-Templating.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Templating
3 | anchor: templating
4 | ---
5 |
6 | # Templating {#templating_title}
7 |
8 | Templates provide a convenient way of separating your controller and domain logic from your presentation logic.
9 | Templates typically contain the HTML of your application, but may also be used for other formats, such as XML.
10 | Templates are often referred to as "views", which make up **part of** the second component of the
11 | [model–view–controller](/pages/Design-Patterns.html#model-view-controller) (MVC) software architecture pattern.
--------------------------------------------------------------------------------
/_posts/08-02-01-Benefits.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: templating_benefits
4 | ---
5 |
6 | ## Benefits {#templating_benefits_title}
7 |
8 | The main benefit to using templates is the clear separation they create between the presentation logic and the rest of
9 | your application. Templates have the sole responsibility of displaying formatted content. They are not responsible for
10 | data lookup, persistence or other more complex tasks. This leads to cleaner, more readable code which is especially
11 | helpful in a team environment where developers work on the server-side code (controllers, models) and designers work on
12 | the client-side code (markup).
13 |
14 | Templates also improve the organization of presentation code. Templates are typically placed in a "views" folder, each
15 | defined within a single file. This approach encourages code reuse where larger blocks of code are broken into smaller,
16 | reusable pieces, often called partials. For example, your site header and footer can each be defined as templates,
17 | which are then included before and after each page template.
18 |
19 | Finally, depending on the library you use, templates can offer more security by automatically escaping user-generated
20 | content. Some libraries even offer sand-boxing, where template designers are only given access to white-listed
21 | variables and functions.
--------------------------------------------------------------------------------
/_posts/08-03-01-Plain-PHP-Templates.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Plain PHP Templates
3 | isChild: true
4 | anchor: plain_php_templates
5 | ---
6 |
7 | ## Plain PHP Templates {#plain_php_templates_title}
8 |
9 | Plain PHP templates are simply templates that use native PHP code. They are a natural choice since PHP is actually a
10 | template language itself. That simply means that you can combine PHP code within other code, like HTML. This is
11 | beneficial to PHP developers as there is no new syntax to learn, they know the functions available to them, and their
12 | code editors already have PHP syntax highlighting and auto-completion built-in. Further, plain PHP templates tend to be
13 | very fast as no compiling stage is required.
14 |
15 | Every modern PHP framework employs some kind of template system, most of which use plain PHP by default. Outside of
16 | frameworks, libraries like [Plates][plates] or [Aura.View][aura] make working with plain PHP templates easier by
17 | offering modern template functionality such as inheritance, layouts and extensions.
18 |
19 | ### Simple example of a plain PHP template
20 |
21 | Using the [Plates][plates] library.
22 |
23 | {% highlight php %}
24 |
25 |
26 | insert('header', ['title' => 'User Profile']) ?>
27 |
28 | User Profile
29 | Hello, =$this->escape($name)?>
30 |
31 | insert('footer') ?>
32 | {% endhighlight %}
33 |
34 | ### Example of plain PHP templates using inheritance
35 |
36 | Using the [Plates][plates] library.
37 |
38 | {% highlight php %}
39 |
40 |
41 |
42 |
43 | =$title?>
44 |
45 |
46 |
47 |
48 | =$this->section('content')?>
49 |
50 |
51 |
52 |
53 | {% endhighlight %}
54 |
55 | {% highlight php %}
56 |
57 |
58 | layout('template', ['title' => 'User Profile']) ?>
59 |
60 | User Profile
61 | Hello, =$this->escape($name)?>
62 | {% endhighlight %}
63 |
64 |
65 | [plates]: https://platesphp.com/
66 | [aura]: https://github.com/auraphp/Aura.View
67 |
--------------------------------------------------------------------------------
/_posts/08-04-01-Compiled-Templates.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: compiled_templates
4 | ---
5 |
6 | ## Compiled Templates {#compiled_templates_title}
7 |
8 | While PHP has evolved into a mature, object oriented language, it [hasn't improved much][article_templating_engines] as
9 | a templating language. Compiled templates, like [Twig], [Brainy], or [Smarty]*, fill this void by offering a new syntax that has
10 | been geared specifically to templating. From automatic escaping, to inheritance and simplified control structures,
11 | compiled templates are designed to be easier to write, cleaner to read and safer to use. Compiled templates can even be
12 | shared across different languages, [Mustache] being a good example of this. Since these templates must be compiled
13 | there is a slight performance hit, however this is very minimal when proper caching is used.
14 |
15 | **While Smarty offers automatic escaping, this feature is NOT enabled by default.*
16 |
17 | ### Simple example of a compiled template
18 |
19 | Using the [Twig] library.
20 |
21 | {% highlight html+jinja %}
22 | {% raw %}
23 | {% include 'header.html' with {'title': 'User Profile'} %}
24 |
25 | User Profile
26 | Hello, {{ name }}
27 |
28 | {% include 'footer.html' %}
29 | {% endraw %}
30 | {% endhighlight %}
31 |
32 | ### Example of compiled templates using inheritance
33 |
34 | Using the [Twig] library.
35 |
36 | {% highlight html+jinja %}
37 | {% raw %}
38 | // template.html
39 |
40 |
41 |
42 | {% block title %}{% endblock %}
43 |
44 |
45 |
46 |
47 | {% block content %}{% endblock %}
48 |
49 |
50 |
51 |
52 | {% endraw %}
53 | {% endhighlight %}
54 |
55 | {% highlight html+jinja %}
56 | {% raw %}
57 | // user_profile.html
58 |
59 | {% extends "template.html" %}
60 |
61 | {% block title %}User Profile{% endblock %}
62 | {% block content %}
63 | User Profile
64 | Hello, {{ name }}
65 | {% endblock %}
66 | {% endraw %}
67 | {% endhighlight %}
68 |
69 |
70 | [article_templating_engines]: http://fabien.potencier.org/templating-engines-in-php.html
71 | [Twig]: https://twig.symfony.com/
72 | [Brainy]: https://github.com/box/brainy
73 | [Smarty]: https://www.smarty.net/
74 | [Mustache]: https://mustache.github.io/
75 |
--------------------------------------------------------------------------------
/_posts/08-05-01-Further-Reading.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: templating_further_reading
4 | ---
5 |
6 | ## Further Reading {#templating_further_reading_title}
7 |
8 | ### Articles & Tutorials
9 |
10 | * [Templating Engines in PHP](http://fabien.potencier.org/templating-engines-in-php.html)
11 | * [An Introduction to Views & Templating in CodeIgniter](https://code.tutsplus.com/tutorials/an-introduction-to-views-templating-in-codeigniter--net-25648)
12 | * [Getting Started With PHP Templating](https://www.smashingmagazine.com/2011/10/getting-started-with-php-templating/)
13 | * [Roll Your Own Templating System in PHP](https://code.tutsplus.com/tutorials/roll-your-own-templating-system-in-php--net-16596)
14 | * [Master Pages](https://laracasts.com/series/laravel-from-scratch/episodes/7)
15 | * [Working With Templates in Symfony 2](https://code.tutsplus.com/tutorials/working-with-templates-in-symfony-2--cms-21172)
16 | * [Writing Safer Templates](https://github.com/box/brainy/wiki/Writing-Safe-Templates)
17 |
18 | ### Libraries
19 |
20 | * [Aura.View](https://github.com/auraphp/Aura.View) *(native)*
21 | * [Blade](https://laravel.com/docs/blade) *(compiled, framework specific)*
22 | * [Brainy](https://github.com/box/brainy) *(compiled)*
23 | * [Latte](https://github.com/nette/latte) *(compiled)*
24 | * [Mustache](https://github.com/bobthecow/mustache.php) *(compiled)*
25 | * [PHPTAL](https://phptal.org/) *(compiled)*
26 | * [Plates](https://platesphp.com/) *(native)*
27 | * [Smarty](https://www.smarty.net/) *(compiled)*
28 | * [Twig](https://twig.symfony.com/) *(compiled)*
29 | * [laminas-view](https://docs.laminas.dev/laminas-view/) *(native, framework specific)*
30 |
--------------------------------------------------------------------------------
/_posts/09-01-01-Errors-and-Exceptions.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Errors and Exceptions
3 | anchor: errors_and_exceptions
4 | ---
5 |
6 | # Errors and Exceptions {#errors_and_exceptions_title}
7 |
8 |
--------------------------------------------------------------------------------
/_posts/09-02-01-Errors.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: errors
4 | ---
5 |
6 | ## Errors {#errors_title}
7 |
8 | In many "exception-heavy" programming languages, whenever anything goes wrong an exception will be thrown. This is
9 | certainly a viable way to do things, but PHP is an "exception-light" programming language. While it does have
10 | exceptions and more of the core is starting to use them when working with objects, most of PHP itself will try to keep
11 | processing regardless of what happens, unless a fatal error occurs.
12 |
13 | For example:
14 |
15 | {% highlight console %}
16 | $ php -a
17 | php > echo $foo;
18 | Notice: Undefined variable: foo in php shell code on line 1
19 | {% endhighlight %}
20 |
21 | This is only a notice error, and PHP will happily carry on. This can be confusing for those coming from
22 | "exception-heavy" languages, because referencing a missing variable in Python for example will throw an exception:
23 |
24 | {% highlight console %}
25 | $ python
26 | >>> print foo
27 | Traceback (most recent call last):
28 | File "", line 1, in
29 | NameError: name 'foo' is not defined
30 | {% endhighlight %}
31 |
32 | The only real difference is that Python will freak out over any small thing, so that developers can be super sure any
33 | potential issue or edge-case is caught, whereas PHP will keep on processing unless something extreme happens, at which
34 | point it will throw an error and report it.
35 |
36 | ### Error Severity
37 |
38 | PHP has several levels of error severity. The three most common types of messages are errors, notices and warnings.
39 | These have different levels of severity; `E_ERROR`, `E_NOTICE`, and `E_WARNING`. Errors are fatal run-time errors and
40 | are usually caused by faults in your code and need to be fixed as they'll cause PHP to stop executing. Notices are
41 | advisory messages caused by code that may or may not cause problems during the execution of the script, execution is
42 | not halted. Warnings are non-fatal errors, execution of the script will not be halted.
43 |
44 | Another type of error message reported at compile time are `E_STRICT` messages. These messages are used to suggest
45 | changes to your code to help ensure best interoperability and forward compatibility with upcoming versions of PHP.
46 |
47 | ### Changing PHP's Error Reporting Behaviour
48 |
49 | Error Reporting can be changed by using PHP settings and/or PHP function calls. Using the built in PHP function
50 | `error_reporting()` you can set the level of errors for the duration of the script execution by passing one of the
51 | predefined error level constants, meaning if you only want to see Errors and Warnings - but not Notices - then you can
52 | configure that:
53 |
54 | {% highlight php %}
55 | upload->get_error()` to see what went wrong. The problem here is that you have to go
17 | looking for a mistake and check the docs to see what the error method is for this class, instead of having it made
18 | extremely obvious.
19 |
20 | Another problem is when classes automatically throw an error to the screen and exit the process. When you do this you
21 | stop another developer from being able to dynamically handle that error. Exceptions should be thrown to make a
22 | developer aware of an error; they then can choose how to handle this. E.g.:
23 |
24 | {% highlight php %}
25 | subject('My Subject');
28 | $email->body('How the heck are you?');
29 | $email->to('guy@example.com', 'Some Guy');
30 |
31 | try
32 | {
33 | $email->send();
34 | }
35 | catch(Fuel\Email\ValidationFailedException $e)
36 | {
37 | // The validation failed
38 | }
39 | catch(Fuel\Email\SendingFailedException $e)
40 | {
41 | // The driver could not send the email
42 | }
43 | finally
44 | {
45 | // Executed regardless of whether an exception has been thrown, and before normal execution resumes
46 | }
47 | {% endhighlight %}
48 |
49 | ### SPL Exceptions
50 |
51 | The generic `Exception` class provides very little debugging context for the developer; however, to remedy this, it is
52 | possible to create a specialized `Exception` type by sub-classing the generic `Exception` class:
53 |
54 | {% highlight php %}
55 | lot of custom Exceptions, some of which could have been avoided using the SPL Exceptions
61 | provided in the [SPL extension][splext].
62 |
63 | If for example you use the `__call()` Magic Method and an invalid method is requested then instead of throwing a
64 | standard Exception which is vague, or creating a custom Exception just for that, you could just
65 | `throw new BadMethodCallException;`.
66 |
67 | * [Read about Exceptions][exceptions]
68 | * [Read about SPL Exceptions][splexe]
69 | * [Nesting Exceptions In PHP][nesting-exceptions-in-php]
70 |
71 |
72 | [splext]: /#standard_php_library
73 | [exceptions]: https://www.php.net/language.exceptions
74 | [splexe]: https://www.php.net/spl.exceptions
75 | [nesting-exceptions-in-php]: https://www.brandonsavage.net/exceptional-php-nesting-exceptions-in-php/
76 |
--------------------------------------------------------------------------------
/_posts/10-01-01-Security.md:
--------------------------------------------------------------------------------
1 | ---
2 | anchor: security
3 | ---
4 |
5 | # Security {#security_title}
6 |
7 | The best resource I've found on PHP security is [The 2018 Guide to Building Secure PHP Software](https://paragonie.com/blog/2017/12/2018-guide-building-secure-php-software) by
8 | [Paragon Initiative](https://paragonie.com/).
9 |
--------------------------------------------------------------------------------
/_posts/10-02-01-Web-Application-Security.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: web_application_security
4 | ---
5 |
6 | ## Web Application Security {#web_application_security_title}
7 |
8 | It is very important for every PHP developer to learn [the basics of web application security][4], which can be broken
9 | down into a handful of broad topics:
10 |
11 | 1. Code-data separation.
12 | * When data is executed as code, you get SQL Injection, Cross-Site Scripting, Local/Remote File Inclusion, etc.
13 | * When code is printed as data, you get information leaks (source code disclosure or, in the case of C programs,
14 | enough information to bypass [ASLR][5]).
15 | 2. Application logic.
16 | * Missing authentication or authorization controls.
17 | * Input validation.
18 | 3. Operating environment.
19 | * PHP versions.
20 | * Third party libraries.
21 | * The operating system.
22 | 4. Cryptography weaknesses.
23 | * [Weak random numbers][6].
24 | * [Chosen-ciphertext attacks][7].
25 | * [Side-channel information leaks][8].
26 |
27 | There are bad people ready and willing to exploit your web application. It is important that you take necessary
28 | precautions to harden your web application's security. Luckily, the fine folks at
29 | [The Open Web Application Security Project][1] (OWASP) have compiled a comprehensive list of known security issues and
30 | methods to protect yourself against them. This is a must read for the security-conscious developer. [Survive The Deep End: PHP Security][3] by Padraic Brady is also another good web application security guide for PHP.
31 |
32 | * [Read the OWASP Security Guide][2]
33 |
34 |
35 | [1]: https://www.owasp.org/
36 | [2]: https://www.owasp.org/index.php/Guide_Table_of_Contents
37 | [3]: https://phpsecurity.readthedocs.io/en/latest/index.html
38 | [4]: https://paragonie.com/blog/2015/08/gentle-introduction-application-security
39 | [5]: https://www.techtarget.com/searchsecurity/definition/address-space-layout-randomization-ASLR
40 | [6]: https://paragonie.com/blog/2016/01/on-design-and-implementation-stealth-backdoor-for-web-applications
41 | [7]: https://paragonie.com/blog/2015/05/using-encryption-and-authentication-correctly
42 | [8]: https://blog.ircmaxell.com/2014/11/its-all-about-time.html
43 |
--------------------------------------------------------------------------------
/_posts/10-03-01-Password-Hashing.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: password_hashing
4 | ---
5 |
6 | ## Password Hashing {#password_hashing_title}
7 |
8 | Eventually everyone builds a PHP application that relies on user login. Usernames and passwords are stored in a
9 | database and later used to authenticate users upon login.
10 |
11 | It is important that you properly [_hash_][3] passwords before storing them. Hashing and encrypting are [two very different things][7]
12 | that often get confused.
13 |
14 | Hashing is an irreversible, one-way function. This produces a fixed-length string that cannot be feasibly reversed.
15 | This means you can compare a hash against another to determine if they both came from the same source string, but you
16 | cannot determine the original string. If passwords are not hashed and your database is accessed by an unauthorized
17 | third-party, all user accounts are now compromised.
18 |
19 | Unlike hashing, encryption is reversible (provided you have the key). Encryption is useful in other areas, but is a poor
20 | strategy for securely storing passwords.
21 |
22 | Passwords should also be individually [_salted_][5] by adding a random string to each password before hashing. This prevents dictionary attacks and the use of "rainbow tables" (a reverse list of cryptographic hashes for common passwords.)
23 |
24 | Hashing and salting are vital as often users use the same password for multiple services and password quality can be poor.
25 |
26 | Additionally, you should use [a specialized _password hashing_ algorithm][6] rather than fast, general-purpose
27 | cryptographic hash function (e.g. SHA256). The short list of acceptable password hashing algorithms (as of June 2018)
28 | to use are:
29 |
30 | * Argon2 (available in PHP 7.2 and newer)
31 | * Scrypt
32 | * **Bcrypt** (PHP provides this one for you; see below)
33 | * PBKDF2 with HMAC-SHA256 or HMAC-SHA512
34 |
35 | Fortunately, nowadays PHP makes this easy.
36 |
37 | **Hashing passwords with `password_hash`**
38 |
39 | In PHP 5.5 `password_hash()` was introduced. At this time it is using BCrypt, the strongest algorithm currently
40 | supported by PHP. It will be updated in the future to support more algorithms as needed though. The `password_compat`
41 | library was created to provide forward compatibility for PHP >= 5.3.7.
42 |
43 | Below we hash a string, and then check the hash against a new string. Because our two source strings are different
44 | ('secret-password' vs. 'bad-password') this login will fail.
45 |
46 | {% highlight php %}
47 | = 5.3.7 && < 5.5] [2]
63 | * [Learn about hashing in regards to cryptography] [3]
64 | * [Learn about salts] [5]
65 | * [PHP `password_hash()` RFC] [4]
66 |
67 |
68 | [1]: https://www.php.net/function.password-hash
69 | [2]: https://github.com/ircmaxell/password_compat
70 | [3]: https://wikipedia.org/wiki/Cryptographic_hash_function
71 | [4]: https://wiki.php.net/rfc/password_hash
72 | [5]: https://wikipedia.org/wiki/Salt_(cryptography)
73 | [6]: https://paragonie.com/blog/2016/02/how-safely-store-password-in-2016
74 | [7]: https://paragonie.com/blog/2015/08/you-wouldnt-base64-a-password-cryptography-decoded
75 |
76 |
--------------------------------------------------------------------------------
/_posts/10-04-01-Data-Filtering.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: data_filtering
4 | ---
5 |
6 | ## Data Filtering {#data_filtering_title}
7 |
8 | Never ever (ever) trust foreign input introduced to your PHP code. Always sanitize and validate foreign input before
9 | using it in code. The `filter_var()` and `filter_input()` functions can sanitize text and validate text formats (e.g.
10 | email addresses).
11 |
12 | Foreign input can be anything: `$_GET` and `$_POST` form input data, some values in the `$_SERVER` superglobal, and the
13 | HTTP request body via `fopen('php://input', 'r')`. Remember, foreign input is not limited to form data submitted by the
14 | user. Uploaded and downloaded files, session values, cookie data, and data from third-party web services are foreign
15 | input, too.
16 |
17 | While foreign data can be stored, combined, and accessed later, it is still foreign input. Every time you process,
18 | output, concatenate, or include data in your code, ask yourself if the data is filtered properly and can it be trusted.
19 |
20 | Data may be _filtered_ differently based on its purpose. For example, when unfiltered foreign input is passed into HTML
21 | page output, it can execute HTML and JavaScript on your site! This is known as Cross-Site Scripting (XSS) and can be a
22 | very dangerous attack. One way to avoid XSS is to sanitize all user-generated data before outputting it to your page by
23 | removing HTML tags with the `strip_tags()` function or escaping characters with special meaning into their respective
24 | HTML entities with the `htmlentities()` or `htmlspecialchars()` functions.
25 |
26 | Another example is passing options to be executed on the command line. This can be extremely dangerous (and is usually
27 | a bad idea), but you can use the built-in `escapeshellarg()` function to sanitize the executed command's arguments.
28 |
29 | One last example is accepting foreign input to determine a file to load from the filesystem. This can be exploited by
30 | changing the filename to a file path. You need to remove `"/"`, `"../"`, [null bytes][6], or other characters from the
31 | file path so it can't load hidden, non-public, or sensitive files.
32 |
33 | * [Learn about data filtering][1]
34 | * [Learn about `filter_var`][4]
35 | * [Learn about `filter_input`][5]
36 | * [Learn about handling null bytes][6]
37 |
38 | ### Sanitization
39 |
40 | Sanitization removes (or escapes) illegal or unsafe characters from foreign input.
41 |
42 | For example, you should sanitize foreign input before including the input in HTML or inserting it into a raw SQL query.
43 | When you use bound parameters with [PDO](#databases), it will sanitize the input for you.
44 |
45 | Sometimes it is required to allow some safe HTML tags in the input when including it in the HTML page. This is very
46 | hard to do and many avoid it by using other more restricted formatting like Markdown or BBCode, although whitelisting
47 | libraries like [HTML Purifier][html-purifier] exist for this reason.
48 |
49 | [See Sanitization Filters][2]
50 |
51 | ### Unserialization
52 |
53 | It is dangerous to `unserialize()` data from users or other untrusted sources. Doing so can allow malicious users to instantiate objects (with user-defined properties) whose destructors will be executed, **even if the objects themselves aren't used**. You should therefore avoid unserializing untrusted data.
54 |
55 | Use a safe, standard data interchange format such as JSON (via [`json_decode`][json_decode] and [`json_encode`][json_encode]) if you need to pass serialized data to the user.
56 |
57 | ### Validation
58 |
59 | Validation ensures that foreign input is what you expect. For example, you may want to validate an email address, a
60 | phone number, or age when processing a registration submission.
61 |
62 | [See Validation Filters][3]
63 |
64 |
65 | [1]: https://www.php.net/book.filter
66 | [2]: https://www.php.net/filter.filters.sanitize
67 | [3]: https://www.php.net/filter.filters.validate
68 | [4]: https://www.php.net/function.filter-var
69 | [5]: https://www.php.net/function.filter-input
70 | [6]: https://www.php.net/security.filesystem.nullbytes
71 | [html-purifier]: http://htmlpurifier.org/
72 | [json_decode]: https://www.php.net/manual/function.json-decode.php
73 | [json_encode]: https://www.php.net/manual/function.json-encode.php
74 |
--------------------------------------------------------------------------------
/_posts/10-05-01-Configuration-Files.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: configuration_files
4 | ---
5 |
6 | ## Configuration Files {#configuration_files_title}
7 |
8 | When creating configuration files for your applications, best practices recommend that one of the following methods be
9 | followed:
10 |
11 | - It is recommended that you store your configuration information where it cannot be accessed directly and pulled in
12 | via the file system.
13 | - If you must store your configuration files in the document root, name the files with a `.php` extension. This ensures
14 | that, even if the script is accessed directly, it will not be output as plain text.
15 | - Information in configuration files should be protected accordingly, either through encryption or group/user file
16 | system permissions.
17 | - It is a good idea to ensure that you do not commit configuration files containing sensitive information e.g. passwords or API tokens to source control.
18 |
--------------------------------------------------------------------------------
/_posts/10-06-01-Register-Globals.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: register_globals
4 | ---
5 |
6 | ## Register Globals {#register_globals_title}
7 |
8 | **NOTE:** As of PHP 5.4.0 the `register_globals` setting has been removed and can no longer be used. This is only
9 | included as a warning for anyone in the process of upgrading a legacy application.
10 |
11 | When enabled, the `register_globals` configuration setting makes several types of variables (including ones from
12 | `$_POST`, `$_GET` and `$_REQUEST`) available in the global scope of your application. This can easily lead to security
13 | issues as your application cannot effectively tell where the data is coming from.
14 |
15 | For example: `$_GET['foo']` would be available via `$foo`, which can override variables that have been declared.
16 |
17 | If you are using PHP < 5.4.0 __make sure__ that `register_globals` is __off__.
18 |
--------------------------------------------------------------------------------
/_posts/10-07-01-Error-Reporting.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: error_reporting
4 | ---
5 |
6 | ## Error Reporting {#error_reporting_title}
7 |
8 | Error logging can be useful in finding the problem spots in your application, but it can also expose information about
9 | the structure of your application to the outside world. To effectively protect your application from issues that could
10 | be caused by the output of these messages, you need to configure your server differently in development versus
11 | production (live).
12 |
13 | ### Development
14 |
15 | To show every possible error during **development**, configure the following settings in your `php.ini`:
16 |
17 | {% highlight ini %}
18 | display_errors = On
19 | display_startup_errors = On
20 | error_reporting = -1
21 | log_errors = On
22 | {% endhighlight %}
23 |
24 | > Passing in the value `-1` will show every possible error, even when new levels and constants are added in future PHP
25 | > versions. The `E_ALL` constant also behaves this way as of PHP 5.4. -
26 | > [php.net](https://www.php.net/function.error-reporting)
27 |
28 | The `E_STRICT` error level constant was introduced in 5.3.0 and is not part of `E_ALL`, however it became part of
29 | `E_ALL` in 5.4.0. What does this mean? In terms of reporting every possible error in version 5.3 it means you must
30 | use either `-1` or `E_ALL | E_STRICT`.
31 |
32 | **Reporting every possible error by PHP version**
33 |
34 | * < 5.3 `-1` or `E_ALL`
35 | * 5.3 `-1` or `E_ALL | E_STRICT`
36 | * > 5.3 `-1` or `E_ALL`
37 |
38 | ### Production
39 |
40 | To hide errors on your **production** environment, configure your `php.ini` as:
41 |
42 | {% highlight ini %}
43 | display_errors = Off
44 | display_startup_errors = Off
45 | error_reporting = E_ALL
46 | log_errors = On
47 | {% endhighlight %}
48 |
49 | With these settings in production, errors will still be logged to the error logs for the web server, but will not be
50 | shown to the user. For more information on these settings, see the PHP manual:
51 |
52 | * [error_reporting](https://www.php.net/errorfunc.configuration#ini.error-reporting)
53 | * [display_errors](https://www.php.net/errorfunc.configuration#ini.display-errors)
54 | * [display_startup_errors](https://www.php.net/errorfunc.configuration#ini.display-startup-errors)
55 | * [log_errors](https://www.php.net/errorfunc.configuration#ini.log-errors)
56 |
--------------------------------------------------------------------------------
/_posts/11-01-01-Testing.md:
--------------------------------------------------------------------------------
1 | ---
2 | anchor: testing
3 | ---
4 |
5 | # Testing {#testing_title}
6 |
7 | Writing automated tests for your PHP code is considered a best practice and can lead to well-built applications.
8 | Automated tests are a great tool for making sure your application does not break when you are making changes or adding
9 | new functionality and should not be ignored.
10 |
11 | There are several different types of testing tools (or frameworks) available for PHP, which use different approaches -
12 | all of which are trying to avoid manual testing and the need for large Quality Assurance teams, just to make sure
13 | recent changes didn't break existing functionality.
--------------------------------------------------------------------------------
/_posts/11-02-01-Test-Driven-Development.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: test_driven_development
4 | ---
5 |
6 | ## Test Driven Development {#test_driven_development_title}
7 |
8 | From [Wikipedia](https://wikipedia.org/wiki/Test-driven_development):
9 |
10 | > Test-driven development (TDD) is a software development process that relies on the repetition of a very short
11 | > development cycle: first the developer writes a failing automated test case that defines a desired improvement or new
12 | > function, then produces code to pass that test and finally refactors the new code to acceptable standards. Kent Beck,
13 | > who is credited with having developed or 'rediscovered' the technique, stated in 2003 that TDD encourages simple
14 | > designs and inspires confidence.
15 |
16 | There are several different types of testing that you can do for your application:
17 |
18 | ### Unit Testing
19 |
20 | Unit Testing is a programming approach to ensure functions, classes and methods are working as expected, from the point
21 | you build them all the way through the development cycle. By checking values going in and out of various functions and
22 | methods, you can make sure the internal logic is working correctly. By using Dependency Injection and building "mock"
23 | classes and stubs you can verify that dependencies are correctly used for even better test coverage.
24 |
25 | When you create a class or function you should create a unit test for each behavior it must have. At a very basic level
26 | you should make sure it errors if you send it bad arguments and make sure it works if you send it valid arguments. This
27 | will help ensure that when you make changes to this class or function later on in the development cycle that the old
28 | functionality continues to work as expected. The only alternative to this would be `var_dump()` in a test.php, which is
29 | no way to build an application - large or small.
30 |
31 | The other use for unit tests is contributing to open source. If you can write a test that shows broken functionality
32 | (i.e. fails), then fix it, and show the test passing, patches are much more likely to be accepted. If you run a project
33 | which accepts pull requests then you should suggest this as a requirement.
34 |
35 | [PHPUnit](https://phpunit.de/) is the de-facto testing framework for writing unit tests for PHP applications, but there
36 | are several alternatives:
37 |
38 | * [atoum](https://github.com/atoum/atoum)
39 | * [Kahlan](https://github.com/kahlan/kahlan)
40 | * [Peridot](https://peridot-php.github.io/)
41 | * [Pest](https://pestphp.com/)
42 | * [SimpleTest](https://github.com/simpletest/simpletest)
43 |
44 | ### Integration Testing
45 |
46 | From [Wikipedia](https://wikipedia.org/wiki/Integration_testing):
47 |
48 | > Integration testing (sometimes called Integration and Testing, abbreviated "I&T") is the phase in software testing in
49 | > which individual software modules are combined and tested as a group. It occurs after unit testing and before
50 | > validation testing. Integration testing takes as its input modules that have been unit tested, groups them in larger
51 | > aggregates, applies tests defined in an integration test plan to those aggregates, and delivers as its output the
52 | > integrated system ready for system testing.
53 |
54 | Many of the same tools that can be used for unit testing can be used for integration testing as many of the same
55 | principles are used.
56 |
57 | ### Functional Testing
58 |
59 | Sometimes also known as acceptance testing, functional testing consists of using tools to create automated tests that
60 | actually use your application instead of just verifying that individual units of code are behaving correctly and that
61 | individual units can speak to each other correctly. These tools typically work using real data and simulating actual
62 | users of the application.
63 |
64 | #### Functional Testing Tools
65 |
66 | * [Codeception](https://codeception.com/) is a full-stack testing framework that includes acceptance testing tools
67 | * [Cyress](https://www.cypress.io/)
68 | * [Mink](https://mink.behat.org/)
69 | * [Selenium](https://www.selenium.dev/)
70 | * [Storyplayer](https://github.com/MeltwaterArchive/storyplayer) is a full-stack testing framework that includes support for creating and destroying test environments on demand
71 |
--------------------------------------------------------------------------------
/_posts/11-03-01-Behavior-Driven-Development.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: behavior_driven_development
4 | ---
5 |
6 | ## Behavior Driven Development {#behavior_driven_development_title}
7 |
8 | There are two different types of Behavior-Driven Development (BDD): SpecBDD and StoryBDD. SpecBDD focuses on technical
9 | behavior of code, while StoryBDD focuses on business or feature behaviors or interactions. PHP has frameworks for both
10 | types of BDD.
11 |
12 | With StoryBDD, you write human-readable stories that describe the behavior of your application. These stories can then
13 | be run as actual tests against your application. The framework used in PHP applications for StoryBDD is [Behat], which
14 | is inspired by Ruby's [Cucumber] project and implements the Gherkin DSL for describing feature behavior.
15 |
16 | With SpecBDD, you write specifications that describe how your actual code should behave. Instead of testing a function
17 | or method, you are describing how that function or method should behave. PHP offers the [PHPSpec] framework for this
18 | purpose. This framework is inspired by the [RSpec project][Rspec] for Ruby.
19 |
20 | ### BDD Links
21 |
22 | * [Behat], the StoryBDD framework for PHP, inspired by Ruby's [Cucumber] project;
23 | * [PHPSpec], the SpecBDD framework for PHP, inspired by Ruby's [RSpec] project;
24 | * [Codeception] is a full-stack testing framework that uses BDD principles.
25 |
26 |
27 | [Behat]: https://behat.org/
28 | [Cucumber]: https://cucumber.io/
29 | [PHPSpec]: https://phpspec.net/
30 | [RSpec]: https://rspec.info/
31 | [Codeception]: https://codeception.com/
32 |
--------------------------------------------------------------------------------
/_posts/11-04-01-Complementary-Testing-Tools.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: complementary_testing_tools
4 | ---
5 |
6 | ## Complementary Testing Tools {#complementary_testing_tools_title}
7 |
8 | Besides individual testing and behavior driven frameworks, there are also a number of generic frameworks and helper
9 | libraries useful for any preferred approach taken.
10 |
11 | ### Tool Links
12 |
13 | * [Selenium] is a browser automation tool which can be [integrated with PHPUnit]
14 | * [Mockery] is a Mock Object Framework which can be integrated with [PHPUnit] or [PHPSpec]
15 | * [Prophecy] is a highly opinionated yet very powerful and flexible PHP object mocking framework. It's integrated with
16 | [PHPSpec] and can be used with [PHPUnit].
17 | * [php-mock] is a library to help to mock PHP native functions.
18 | * [Infection] is a PHP implementation of [Mutation Testing] to help to measure the effectiveness of your tests.
19 | * [PHPUnit Polyfills] is a library that allows for creating PHPUnit cross-version compatible tests when a test suite needs to run against a range of PHPUnit versions.
20 |
21 |
22 | [Selenium]: https://www.selenium.dev/
23 | [integrated with PHPUnit]: https://github.com/giorgiosironi/phpunit-selenium/
24 | [Mockery]: https://github.com/padraic/mockery
25 | [PHPUnit]: https://phpunit.de/
26 | [PHPSpec]: https://phpspec.net/
27 | [Prophecy]: https://github.com/phpspec/prophecy
28 | [php-mock]: https://github.com/php-mock/php-mock
29 | [Infection]: https://github.com/infection/infection
30 | [Mutation Testing]: https://en.wikipedia.org/wiki/Mutation_testing
31 | [PHPUnit Polyfills]: https://github.com/Yoast/PHPUnit-Polyfills
32 |
--------------------------------------------------------------------------------
/_posts/12-01-01-Servers-and-Deployment.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Servers and Deployment
3 | anchor: servers_and_deployment
4 | ---
5 |
6 | # Servers and Deployment {#servers_and_deployment_title}
7 |
8 | PHP applications can be deployed and run on production web servers in a number of ways.
9 |
--------------------------------------------------------------------------------
/_posts/12-02-01-Platform-as-a-Service.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Platform as a Service (PaaS)
3 | isChild: true
4 | anchor: platform_as_a_service
5 | ---
6 |
7 | ## Platform as a Service (PaaS) {#platform_as_a_service_title}
8 |
9 | PaaS provides the system and network architecture necessary to run PHP applications on the web. This means little to no
10 | configuration for launching PHP applications or PHP frameworks.
11 |
12 | Recently PaaS has become a popular method for deploying, hosting, and scaling PHP applications of all sizes. You can
13 | find a list of [PHP PaaS "Platform as a Service" providers](#php_paas_providers) in our [resources section](#resources).
--------------------------------------------------------------------------------
/_posts/12-03-01-Virtual-or-Dedicated-Servers.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Virtual or Dedicated Servers
3 | isChild: true
4 | anchor: virtual_or_dedicated_servers
5 | ---
6 |
7 | ## Virtual or Dedicated Servers {#virtual_or_dedicated_servers_title}
8 |
9 | If you are comfortable with systems administration, or are interested in learning it, virtual or dedicated servers give
10 | you complete control of your application's production environment.
11 |
12 | ### nginx and PHP-FPM
13 |
14 | PHP, via PHP's built-in FastCGI Process Manager (FPM), pairs really nicely with [nginx], which is a lightweight,
15 | high-performance web server. It uses less memory than Apache and can better handle more concurrent requests. This is
16 | especially important on virtual servers that don't have much memory to spare.
17 |
18 | * [Read more on nginx][nginx]
19 | * [Read more on PHP-FPM][phpfpm]
20 | * [Read more on setting up nginx and PHP-FPM securely][secure-nginx-phpfpm]
21 |
22 | ### Apache and PHP
23 |
24 | PHP and Apache have a long history together. Apache is wildly configurable and has many available
25 | [modules][apache-modules] to extend functionality. It is a popular choice for shared servers and an easy setup for PHP
26 | frameworks and open source apps like WordPress. Unfortunately, Apache uses more resources than nginx by default and
27 | cannot handle as many visitors at the same time.
28 |
29 | Apache has several possible configurations for running PHP. The most common and easiest to setup is the [prefork MPM]
30 | with `mod_php`. While it isn't the most memory efficient, it is the simplest to get working and to use. This is probably
31 | the best choice if you don't want to dig too deeply into the server administration aspects. Note that if you use
32 | `mod_php` you MUST use the prefork MPM.
33 |
34 | Alternatively, if you want to squeeze more performance and stability out of Apache then you can take advantage of the
35 | same FPM system as nginx and run the [worker MPM] or [event MPM] with mod_fastcgi or mod_fcgid. This configuration will
36 | be significantly more memory efficient and much faster but it is more work to set up.
37 |
38 | If you are running Apache 2.4 or later, you can use [mod_proxy_fcgi] to get great performance that is easy to setup.
39 |
40 | * [Read more on Apache][apache]
41 | * [Read more on Multi-Processing Modules][apache-MPM]
42 | * [Read more on mod_fastcgi][mod_fastcgi]
43 | * [Read more on mod_fcgid][mod_fcgid]
44 | * [Read more on mod_proxy_fcgi][mod_proxy_fcgi]
45 | * [Read more on setting up Apache and PHP-FPM with mod_proxy_fcgi][tutorial-mod_proxy_fcgi]
46 |
47 |
48 | [nginx]: https://nginx.org/
49 | [phpfpm]: https://www.php.net/install.fpm
50 | [secure-nginx-phpfpm]: https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/
51 | [apache-modules]: https://httpd.apache.org/docs/2.4/mod/
52 | [prefork MPM]: https://httpd.apache.org/docs/2.4/mod/prefork.html
53 | [worker MPM]: https://httpd.apache.org/docs/2.4/mod/worker.html
54 | [event MPM]: https://httpd.apache.org/docs/2.4/mod/event.html
55 | [apache]: https://httpd.apache.org/
56 | [apache-MPM]: https://httpd.apache.org/docs/2.4/mod/mpm_common.html
57 | [mod_fastcgi]: https://blogs.oracle.com/opal/post/php-fpm-fastcgi-process-manager-with-apache-2
58 | [mod_fcgid]: https://httpd.apache.org/mod_fcgid/
59 | [mod_proxy_fcgi]: https://httpd.apache.org/docs/current/mod/mod_proxy_fcgi.html
60 | [tutorial-mod_proxy_fcgi]: https://serversforhackers.com/video/apache-and-php-fpm
61 |
--------------------------------------------------------------------------------
/_posts/12-04-01-Shared-Servers.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: shared_servers
4 | ---
5 |
6 | ## Shared Servers {#shared_servers_title}
7 |
8 | PHP has shared servers to thank for its popularity. It is hard to find a host without PHP installed, but be sure it's
9 | the latest version. Shared servers allow you and other developers to deploy websites to a single machine. The upside to
10 | this is that it has become a cheap commodity. The downside is that you never know what kind of a ruckus your
11 | neighboring tenants are going to create; loading down the server or opening up security holes are the main concerns. If
12 | your project's budget can afford to avoid shared servers, you should.
13 |
14 | Make sure your shared servers are offering the latest versions of PHP.
15 |
--------------------------------------------------------------------------------
/_posts/12-05-01-Building-your-Application.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: building_and_deploying_your_application
4 | ---
5 |
6 | ## Building and Deploying your Application {#building_and_deploying_your_application_title}
7 |
8 | If you find yourself doing manual database schema changes or running your tests manually before updating your files
9 | (manually), think twice! With every additional manual task needed to deploy a new version of your app, the chances for
10 | potentially fatal mistakes increase. Whether you're dealing with a simple update, a comprehensive build process or even
11 | a continuous integration strategy, [build automation][buildautomation] is your friend.
12 |
13 | Among the tasks you might want to automate are:
14 |
15 | * Dependency management
16 | * Compilation, minification of your assets
17 | * Running tests
18 | * Creation of documentation
19 | * Packaging
20 | * Deployment
21 |
22 |
23 | ### Deployment Tools
24 |
25 | Deployment tools can be described as a collection of scripts that handle common tasks of software deployment. The deployment tool is not a part of your software, it acts on your software from 'outside'.
26 |
27 | There are many open source tools available to help you with build automation and deployment, some are written in PHP others aren't. This shouldn't hold you back from using them, if they're better suited for the specific job. Here are a few examples:
28 |
29 | [Phing] can control your packaging, deployment or testing process from within a XML build file. Phing (which is based on [Apache Ant]) provides a rich set of tasks usually needed to install or update a web application and can be extended with additional custom tasks, written in PHP. It's a solid and robust tool and has been around for a long time, however the tool could be perceived as a bit old fashioned because of the way it deals with configuration (XML files).
30 |
31 | [Capistrano] is a system for *intermediate-to-advanced programmers* to execute commands in a structured, repeatable way on one or more remote machines. It is pre-configured for deploying Ruby on Rails applications, however you can successfully deploy PHP systems with it. Successful use of Capistrano depends on a working knowledge of Ruby and Rake.
32 |
33 | [Ansistrano] is a couple of Ansible roles to easily manage the deployment process (deploy and rollback) for scripting applications such as PHP, Python and Ruby. It's an Ansible port for [Capistrano]. It's been used by quite a lot of PHP companies already.
34 |
35 | [Deployer] is a deployment tool written in PHP. It's simple and functional. Features include running tasks in parallel, atomic deployment and keeping consistency between servers. Recipes of common tasks for Symfony, Laravel, Zend Framework and Yii are available. Younes Rafie's article [Easy Deployment of PHP Applications with Deployer][phpdeploy_deployer] is a great tutorial for deploying your application with the tool.
36 |
37 | [Magallanes] is another tool written in PHP with simple configuration done in YAML files. It has support for multiple servers and environments, atomic deployment, and has some built in tasks that you can leverage for common tools and frameworks.
38 |
39 | #### Further reading:
40 |
41 | * [Automate your project with Apache Ant][apache_ant_tutorial]
42 | * [Deploying PHP Applications][deploying_php_applications] - paid book on best practices and tools for PHP deployment.
43 |
44 | ### Server Provisioning
45 |
46 | Managing and configuring servers can be a daunting task when faced with many servers. There are tools for dealing with this so you can automate your infrastructure to make sure you have the right servers and that they're configured properly. They often integrate with the larger cloud hosting providers (Amazon Web Services, Heroku, DigitalOcean, etc) for managing instances, which makes scaling an application a lot easier.
47 |
48 | [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.
49 |
50 | [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.
51 |
52 | [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.
53 |
54 | #### Further reading:
55 |
56 | * [An Ansible Tutorial][an_ansible_tutorial]
57 | * [Ansible for DevOps][ansible_for_devops] - paid book on everything Ansible
58 | * [Ansible for AWS][ansible_for_aws] - paid book on integrating Ansible and Amazon Web Services
59 | * [Three part blog series about deploying a LAMP application with Chef, Vagrant, and EC2][chef_vagrant_and_ec2]
60 | * [Chef Cookbook which installs and configures PHP and the PEAR package management system][Chef_cookbook]
61 | * [Chef video tutorial series][Chef_tutorial]
62 |
63 | ### Continuous Integration
64 |
65 | > Continuous Integration is a software development practice where members of a team integrate their work frequently,
66 | > usually each person integrates at least daily — leading to multiple integrations per day. Many teams find that this
67 | > approach leads to significantly reduced integration problems and allows a team to develop cohesive software more
68 | > rapidly.
69 |
70 | *-- Martin Fowler*
71 |
72 | There are different ways to implement continuous integration for PHP. [Travis CI] has done a great job of
73 | making continuous integration a reality even for small projects. Travis CI is a hosted continuous integration service.
74 | It can be integrated with GitHub and offers support for many languages including PHP.
75 | GitHub has continuous integration workflows with [GitHub Actions][github_actions].
76 |
77 | #### Further reading:
78 |
79 | * [Continuous Integration with Jenkins][Jenkins]
80 | * [Continuous Integration with PHPCI][PHPCI]
81 | * [Continuous Integration with PHP Censor][PHP Censor]
82 | * [Continuous Integration with Teamcity][Teamcity]
83 |
84 | [buildautomation]: https://wikipedia.org/wiki/Build_automation
85 | [Phing]: https://www.phing.info/
86 | [Apache Ant]: https://ant.apache.org/
87 | [Capistrano]: https://capistranorb.com/
88 | [Ansistrano]: https://ansistrano.com
89 | [phpdeploy_deployer]: https://www.sitepoint.com/deploying-php-applications-with-deployer/
90 | [Chef]: https://www.chef.io/
91 | [chef_vagrant_and_ec2]: https://web.archive.org/web/20190307220000/http://www.jasongrimes.org/2012/06/managing-lamp-environments-with-chef-vagrant-and-ec2-1-of-3/
92 | [Chef_cookbook]: https://github.com/sous-chefs/php
93 | [Chef_tutorial]: https://www.youtube.com/playlist?list=PL11cZfNdwNyNYcpntVe6js-prb80LBZuc
94 | [apache_ant_tutorial]: https://code.tutsplus.com/tutorials/automate-your-projects-with-apache-ant--net-18595
95 | [Travis CI]: https://www.travis-ci.com/
96 | [Jenkins]: https://jenkins.io/
97 | [PHPCI]: https://github.com/dancryer/phpci
98 | [PHP Censor]: https://github.com/php-censor/php-censor
99 | [Teamcity]: https://www.jetbrains.com/teamcity/
100 | [Deployer]: https://deployer.org/
101 | [Magallanes]: https://www.magephp.com/
102 | [deploying_php_applications]: https://deployingphpapplications.com/
103 | [Ansible]: https://www.ansible.com/
104 | [Puppet]: https://puppet.com/
105 | [ansible_for_devops]: https://leanpub.com/ansible-for-devops
106 | [ansible_for_aws]: https://leanpub.com/ansible-for-aws
107 | [an_ansible_tutorial]: https://serversforhackers.com/an-ansible-tutorial
108 | [github_actions]: https://docs.github.com/en/actions
109 |
--------------------------------------------------------------------------------
/_posts/13-01-01-Virtualization.md:
--------------------------------------------------------------------------------
1 | ---
2 | anchor: virtualization
3 | ---
4 |
5 | # Virtualization {#virtualization_title}
6 |
7 | Running your application on different environments in development and production can lead to strange bugs popping up
8 | when you go live. It's also tricky to keep different development environments up to date with the same version for all
9 | libraries used when working with a team of developers.
10 |
11 | If you are developing on Windows and deploying to Linux (or anything non-Windows) or are developing in a team, you
12 | should consider using a virtual machine. This sounds tricky, but besides the widely known virtualization environments
13 | like VMware or VirtualBox, there are additional tools that may help you setting up a virtual environment in a few easy
14 | steps.
15 |
--------------------------------------------------------------------------------
/_posts/13-02-01-Vagrant.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: vagrant
4 | ---
5 |
6 | ## Vagrant {#vagrant_title}
7 |
8 | [Vagrant] helps you build your virtual boxes on top of the known virtual environments and will configure these
9 | environments based on a single configuration file. These boxes can be set up manually, or you can use "provisioning"
10 | software such as [Puppet] or [Chef] to do this for you. Provisioning the base box is a great way to ensure that
11 | multiple boxes are set up in an identical fashion and removes the need for you to maintain complicated "set up"
12 | command lists. You can also "destroy" your base box and recreate it without many manual steps, making it easy to create
13 | a "fresh" installation.
14 |
15 | Vagrant creates folders for sharing your code between your host and your virtual machine, which means that you can
16 | create and edit your files on your host machine and then run the code inside your virtual machine.
17 |
18 |
19 | [Vagrant]: https://www.vagrantup.com/
20 | [Puppet]: https://puppet.com/
21 | [Chef]: https://www.chef.io/
22 |
--------------------------------------------------------------------------------
/_posts/13-03-01-Docker.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: docker
4 | ---
5 |
6 | ## Docker {#docker_title}
7 |
8 | [Docker] - a lightweight alternative to a full virtual machine - is so called because it's all about "containers". A container is a building block which, in the simplest case, does one specific job, e.g. running a web server. An "image" is the package you use to build the container - Docker has a repository full of them.
9 |
10 | A typical LAMP application might have three containers: a web server, a PHP-FPM process and MySQL. As with shared folders in Vagrant, you can leave your application files where they are and tell Docker where to find them.
11 |
12 | 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.
13 |
14 | 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.
15 |
16 | ### Example: Running your PHP Applications in Docker
17 |
18 | After [installing docker][docker-install] on your machine, you can start a web server with one command.
19 | The following will download a fully functional Apache installation with the latest PHP version, map `/path/to/your/php/files` to the document root, which you can view at `http://localhost:8080`:
20 |
21 | {% highlight console %}
22 | docker run -d --name my-php-webserver -p 8080:80 -v /path/to/your/php/files:/var/www/html/ php:apache
23 | {% endhighlight %}
24 |
25 | 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).
26 |
27 | ### Learn more about Docker
28 |
29 | The command above shows a quick way to run a basic server. There's much more you can do (and thousands of pre-built images in the [Docker Hub][docker-hub]). Take time to learn the terminology and read the [Docker User Guide][docker-doc] to get the most from it, and don't run random code you've downloaded without checking it's safe – unofficial images may not have the latest security patches. If in doubt, stick to the [official repositiories][docker-hub-official].
30 |
31 | The [PHPDocker.io] site will auto-generate all the files you need for a fully-featured LAMP/LEMP stack, including your choice of PHP version and extensions.
32 |
33 | * [Docker Website][Docker]
34 | * [Docker Installation][docker-install]
35 | * [Docker User Guide][docker-doc]
36 | * [Docker Hub][docker-hub]
37 | * [Docker Hub - official images][docker-hub-official]
38 |
39 | [Docker]: https://www.docker.com/
40 | [docker-hub]: https://hub.docker.com/
41 | [docker-hub-official]: https://hub.docker.com/explore/
42 | [docker-install]: https://docs.docker.com/get-docker/
43 | [docker-doc]: https://docs.docker.com/
44 | [PHPDocker.io]: https://phpdocker.io/
45 |
--------------------------------------------------------------------------------
/_posts/14-01-01-Caching.md:
--------------------------------------------------------------------------------
1 | ---
2 | anchor: caching
3 | ---
4 |
5 | # Caching {#caching_title}
6 |
7 | PHP is pretty quick by itself, but bottlenecks can arise when you make remote connections, load files, etc.
8 | Thankfully, there are various tools available to speed up certain parts of your application, or reduce the number of times these various time-consuming tasks need to run.
9 |
--------------------------------------------------------------------------------
/_posts/14-02-01-Opcode-Cache.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: opcode_cache
4 | ---
5 |
6 | ## Opcode Cache {#opcode_cache_title}
7 |
8 | When a PHP file is executed, it must first be compiled into [opcodes](https://php-legacy-docs.zend.com/manual/php4/en/internals2.opcodes) (machine language instructions for the CPU). If the source code is unchanged, the opcodes will be the same, so this compilation step becomes a waste of CPU resources.
9 |
10 | An opcode cache prevents redundant compilation by storing opcodes in memory and reusing them on successive calls. It will typically check signature or modification time of the file first, in case there have been any changes.
11 |
12 | It's likely an opcode cache will make a significant speed improvement to your application. Since PHP 5.5 there is one built in - [Zend OPcache][opcache-book]. Depending on your PHP package/distribution, it's usually turned on by default - check [opcache.enable](https://www.php.net/manual/opcache.configuration.php#ini.opcache.enable) and the output of `phpinfo()` to make sure. For earlier versions there's a PECL extension.
13 |
14 | Read more about opcode caches:
15 |
16 | * [Zend OPcache][opcache-book] (bundled with PHP since 5.5)
17 | * Zend OPcache (formerly known as Zend Optimizer+) is now [open source][Zend Optimizer+]
18 | * [WinCache] (extension for MS Windows Server)
19 | * [list of PHP accelerators on Wikipedia][PHP_accelerators]
20 | * [PHP Preloading] - PHP >= 7.4
21 |
22 |
23 | [opcache-book]: https://www.php.net/book.opcache
24 | [Zend Optimizer+]: https://github.com/zendtech/ZendOptimizerPlus
25 | [WinCache]: https://www.iis.net/downloads/microsoft/wincache-extension
26 | [PHP_accelerators]: https://wikipedia.org/wiki/List_of_PHP_accelerators
27 | [PHP Preloading]: https://www.php.net/opcache.preloading
28 |
--------------------------------------------------------------------------------
/_posts/14-03-01-Object-Caching.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: object_caching
4 | ---
5 |
6 | ## Object Caching {#object_caching_title}
7 |
8 | There are times when it can be beneficial to cache individual objects in your code, such as with data that is expensive
9 | to get or database calls where the result is unlikely to change. You can use object caching software to hold these
10 | pieces of data in memory for extremely fast access later on. If you save these items to a data store after you retrieve
11 | them, then pull them directly from the cache for following requests, you can gain a significant improvement in
12 | performance as well as reduce the load on your database servers.
13 |
14 | Many of the popular bytecode caching solutions let you cache custom data as well, so there's even more reason to take
15 | advantage of them. APCu and WinCache both provide APIs to save data from your PHP code to their memory cache.
16 |
17 | The most commonly used memory object caching systems are APCu and memcached. APCu is an excellent choice for object
18 | caching, it includes a simple API for adding your own data to its memory cache and is very easy to setup and use. The
19 | one real limitation of APCu is that it is tied to the server it's installed on. Memcached on the other hand is
20 | installed as a separate service and can be accessed across the network, meaning that you can store objects in a
21 | hyper-fast data store in a central location and many different systems can pull from it.
22 |
23 | Note that whether the cache is shared across PHP processes depends on how PHP is used. When running PHP via PHP-FPM,
24 | the cache is shared across all processes of all pools. When running PHP as a (Fast-)CGI application inside your
25 | webserver, the cache is not shared, i.e every PHP process will have its own APCu data. When running PHP on the command
26 | line, the cache is not shared and will only exist for the duration of the command, so you have to be mindful of your
27 | situation and goals. You might want to consider using memcached instead, as it's not tied to the PHP processes.
28 |
29 | In a networked configuration APCu will usually outperform memcached in terms of access speed, but memcached will be
30 | able to scale up faster and further. If you do not expect to have multiple servers running your application, or do not
31 | need the extra features that memcached offers then APCu is probably your best choice for object caching.
32 |
33 | Example logic using APCu:
34 |
35 | {% highlight php %}
36 |
18 | * @link https://docs.phpdoc.org/
19 | */
20 | class DateTimeHelper
21 | {
22 | /**
23 | * @param mixed $anything Anything that we can convert to a \DateTime object
24 | *
25 | * @throws \InvalidArgumentException
26 | *
27 | * @return \DateTime
28 | */
29 | public function dateTimeFromAnything($anything)
30 | {
31 | $type = gettype($anything);
32 |
33 | switch ($type) {
34 | // Some code that tries to return a \DateTime object
35 | }
36 |
37 | throw new \InvalidArgumentException(
38 | "Failed Converting param of type '{$type}' to DateTime object"
39 | );
40 | }
41 |
42 | /**
43 | * @param mixed $date Anything that we can convert to a \DateTime object
44 | *
45 | * @return void
46 | */
47 | public function printISO8601Date($date)
48 | {
49 | echo $this->dateTimeFromAnything($date)->format('c');
50 | }
51 |
52 | /**
53 | * @param mixed $date Anything that we can convert to a \DateTime object
54 | */
55 | public function printRFC2822Date($date)
56 | {
57 | echo $this->dateTimeFromAnything($date)->format('r');
58 | }
59 | }
60 | {% endhighlight %}
61 |
62 | The documentation for the class as a whole has the [@author] tag and a [@link] tag. The [@author] tag is used to
63 | document the author of the code and can be repeated for documenting several authors. The [@link] tag is used to link to a website indicating a relationship between the website and the code.
64 |
65 | Inside the class, the first method has a [@param] tag documenting the type, name and description of the parameter
66 | being passed to the method. Additionally it has the [@return] and [@throws] tags for documenting the return type, and any exceptions that could be thrown respectively.
67 |
68 | The second and third methods are very similar and have a single [@param] tag as did the first method. The important
69 | difference between the second and third methods' doc block is the inclusion/exclusion of the [@return] tag.
70 | `@return void` explicitly informs us that there is no return; historically omitting the `@return void` statement also results in the same (no return) action.
71 |
72 |
73 | [tags]: https://docs.phpdoc.org/guide/references/phpdoc/tags/
74 | [PHPDoc manual]: https://docs.phpdoc.org/
75 | [@author]: https://docs.phpdoc.org/guide/references/phpdoc/tags/author.html
76 | [@link]: https://docs.phpdoc.org/guide/references/phpdoc/tags/link.html
77 | [@param]: https://docs.phpdoc.org/guide/references/phpdoc/tags/param.html
78 | [@return]: https://docs.phpdoc.org/guide/references/phpdoc/tags/return.html
79 | [@throws]: https://docs.phpdoc.org/guide/references/phpdoc/tags/throws.html
80 |
--------------------------------------------------------------------------------
/_posts/16-01-01-Resources.md:
--------------------------------------------------------------------------------
1 | ---
2 | anchor: resources
3 | ---
4 |
5 | # Resources {#resources_title}
6 |
--------------------------------------------------------------------------------
/_posts/16-02-01-From-the-Source.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: From the Source
3 | isChild: true
4 | anchor: from_the_source
5 | ---
6 |
7 | ## From the Source {#from_the_source_title}
8 |
9 | * [PHP Website](https://www.php.net/)
10 | * [PHP Documentation](https://www.php.net/docs.php)
11 |
--------------------------------------------------------------------------------
/_posts/16-03-01-People-to-Follow.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: People to Follow
3 | isChild: true
4 | anchor: people_to_follow
5 | ---
6 |
7 | ## People to Follow {#people_to_follow_title}
8 |
9 | It's difficult to find interesting and knowledgeable PHP
10 | community members when you are first starting out. You can
11 | find an abbreviated list of PHP community members to get you started at:
12 |
13 | *
14 | *
15 |
--------------------------------------------------------------------------------
/_posts/16-05-01-PHP-PaaS-Providers.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: PHP PaaS Providers
3 | isChild: true
4 | anchor: php_paas_providers
5 | ---
6 |
7 | ## PHP PaaS Providers {#php_paas_providers_title}
8 |
9 | * [Amezmo](https://www.amezmo.com)
10 | * [AWS Elastic Beanstalk](https://aws.amazon.com/elasticbeanstalk/)
11 | * [Bref Cloud](https://bref.sh/cloud)
12 | * [Cloudways](https://www.cloudways.com/)
13 | * [DigitalOcean App Platform](https://www.digitalocean.com/products/app-platform)
14 | * [Divio](https://www.divio.com/)
15 | * [Engine Yard Cloud](https://www.engineyard.com/)
16 | * [fortrabbit](https://www.fortrabbit.com/)
17 | * [Google App Engine](https://cloud.google.com/appengine/docs/php/)
18 | * [Heroku](https://devcenter.heroku.com/categories/php-support)
19 | * [IBM Cloud](https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-prep#prep_php)
20 | * [Lumen](https://www.lumen.com/)
21 | * [Microsoft Azure](https://azure.microsoft.com/)
22 | * [Pivotal Web Services](https://network.pivotal.io/)
23 | * [Platform.sh](https://platform.sh/)
24 | * [Red Hat OpenShift](https://www.openshift.com/)
25 | * [Virtuozzo](https://www.virtuozzo.com/application-platform-partners/)
26 |
--------------------------------------------------------------------------------
/_posts/16-06-01-Frameworks.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: frameworks
4 | ---
5 |
6 | ## Frameworks {#frameworks_title}
7 |
8 | Rather than re-invent the wheel, many PHP developers use frameworks to build out web applications. Frameworks abstract
9 | away many of the low-level concerns and provide helpful, easy-to-use interfaces to complete common tasks.
10 |
11 | You do not need to use a framework for every project. Sometimes plain PHP is the right way to go, but if you do need a
12 | framework then there are three main types available:
13 |
14 | * Micro Frameworks
15 | * Full-Stack Frameworks
16 | * Component Frameworks
17 |
18 | Micro-frameworks are essentially a wrapper to route a HTTP request to a callback, controller, method, etc as quickly as
19 | possible, and sometimes come with a few extra libraries to assist development such as basic database wrappers and the
20 | like. They are prominently used to build remote HTTP services.
21 |
22 | Many frameworks add a considerable number of features on top of what is available in a micro-framework; these are
23 | called Full-Stack Frameworks. These often come bundled with ORMs, Authentication packages, etc.
24 |
25 | Component-based frameworks are collections of specialized and single-purpose libraries. Disparate component-based
26 | frameworks can be used together to make a micro- or full-stack framework.
27 |
--------------------------------------------------------------------------------
/_posts/16-07-01-Components.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: components
4 | ---
5 |
6 | ## Components {#components_title}
7 |
8 | As mentioned above "Components" are another approach to the common goal of creating, distributing and implementing
9 | shared code. Various component repositories exist, the main two of which are:
10 |
11 | * [Packagist]
12 | * [PEAR]
13 |
14 | Both of these repositories have command line tools associated with them to help the installation and upgrade processes,
15 | and have been explained in more detail in the [Dependency Management] section.
16 |
17 | There are also component-based frameworks and component-vendors that offer no framework at all. These projects provide
18 | another source of packages which ideally have little to no dependencies on other packages, or specific frameworks.
19 |
20 | For example, you can use the [FuelPHP Validation package], without needing to use the FuelPHP framework itself.
21 |
22 | * [Aura]
23 | * CakePHP Components
24 | * [Collection]
25 | * [Database]
26 | * [Datasource]
27 | * [Event]
28 | * [I18n]
29 | * [ORM]
30 | * [FuelPHP]
31 | * [Hoa Project]
32 | * [Symfony Components]
33 | * [The League of Extraordinary Packages]
34 | * Laravel's Illuminate Components
35 | * [IoC Container]
36 | * [Eloquent ORM]
37 | * [Queue]
38 |
39 | _Laravel's [Illuminate components] will become better decoupled from the Laravel framework. For now, only the
40 | components best decoupled from the Laravel framework are listed above._
41 |
42 |
43 | [Packagist]: /#composer_and_packagist
44 | [PEAR]: /#pear
45 | [Dependency Management]: /#dependency_management
46 | [FuelPHP Validation package]: https://github.com/fuelphp/validation
47 | [Aura]: https://auraphp.com/framework/
48 | [FuelPHP]: https://github.com/fuelphp
49 | [Hoa Project]: https://github.com/hoaproject
50 | [Symfony Components]: https://symfony.com/components
51 | [The League of Extraordinary Packages]: https://thephpleague.com/
52 | [IoC Container]: https://github.com/illuminate/container
53 | [Eloquent ORM]: https://github.com/illuminate/database
54 | [Queue]: https://github.com/illuminate/queue
55 | [Illuminate components]: https://github.com/illuminate
56 | [Collection]: https://github.com/cakephp/collection
57 | [Database]: https://github.com/cakephp/database
58 | [Datasource]: https://github.com/cakephp/datasource
59 | [Event]: https://github.com/cakephp/event
60 | [I18n]: https://github.com/cakephp/i18n
61 | [ORM]: https://github.com/cakephp/orm
62 |
--------------------------------------------------------------------------------
/_posts/16-08-01-Sites.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: other_resources
4 | title: Other Useful Resources
5 | ---
6 |
7 | ## Other Useful Resources {#other_resources_title}
8 |
9 | ### Cheatsheets
10 |
11 | * [PHP Cheatsheets](https://phpcheatsheets.com/) - for variable comparisons, arithmetics and variable testing in various PHP versions.
12 | * [Modern PHP Cheatsheet](https://github.com/smknstd/modern-php-cheatsheet) - documents modern (PHP 7.0+) idioms in a unified document.
13 | * [OWASP Security Cheatsheets](https://owasp.org/www-project-cheat-sheets/) - provides a concise collection of high value information on specific application security topics.
14 |
15 | ### More best practices
16 |
17 | * [PHP Best Practices](https://phpbestpractices.org/)
18 | * [Why You Should Be Using Supported PHP Versions](https://kinsta.com/blog/php-versions/)
19 |
20 | ### News around the PHP and web development communities
21 |
22 | You can subscribe to weekly newsletters to keep yourself informed on new libraries, latest news, events and general
23 | announcements, as well as additional resources being published every now and then:
24 |
25 | * [PHP Weekly](https://www.phpweekly.com)
26 | * [JavaScript Weekly](https://javascriptweekly.com/)
27 | * [Frontend Focus](https://frontendfoc.us/)
28 | * [Mobile Web Weekly](https://mobiledevweekly.com/)
29 |
30 | There are also Weeklies on other platforms you might be interested in; here's [a list of some](https://github.com/jondot/awesome-weekly).
31 |
32 | ### PHP universe
33 |
34 | * [PHP Developer blog](https://blog.phpdeveloper.org/)
35 |
--------------------------------------------------------------------------------
/_posts/16-09-01-Videos.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: videos
4 | title: Video Tutorials
5 | ---
6 |
7 | ## Video Tutorials {#videos}
8 |
9 | ### YouTube Channels
10 |
11 | * [Learn PHP The Right Way Series](https://github.com/ggelashvili/learnphptherightway-outline)
12 | * [PHP Academy](https://www.youtube.com/user/phpacademy)
13 | * [The New Boston](https://www.youtube.com/user/thenewboston)
14 | * [Sherif Ramadan](https://www.youtube.com/user/businessgeek)
15 | * [Level Up Tuts](https://www.youtube.com/user/LevelUpTuts)
16 |
17 | ### Paid Videos
18 |
19 | * [Standards and Best practices](https://teamtreehouse.com/library/php-standards-and-best-practices)
20 | * [PHP Training on Pluralsight](https://www.pluralsight.com/search?q=php)
21 | * [PHP Training on LinkedIn.com](https://www.linkedin.com/learning/search?trk=lynda_redirect_learning&sortBy=RELEVANCE&softwareNames=PHP)
22 | * [PHP Training on Tutsplus](https://code.tutsplus.com/categories/php/courses)
23 | * [Laracasts](https://laracasts.com/)
24 | * [SymfonyCasts](https://symfonycasts.com/)
25 |
--------------------------------------------------------------------------------
/_posts/16-10-01-Books.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: books
4 | ---
5 |
6 | ## Books {#books_title}
7 |
8 | There are many PHP books; sadly some are now quite old and no longer accurate. In particular, avoid books on "PHP 6", a version that will now never exist. The next major release of PHP after 5.6 was "PHP 7", [partly because of this](https://wiki.php.net/rfc/php6).
9 |
10 | This section aims to be a living document for recommended books on PHP development in general. If you would like your
11 | book to be added, send a PR and it will be reviewed for relevancy.
12 |
13 | ### Free Books
14 |
15 | * [PHP Pandas](https://daylerees.com/php-pandas/) - Aims to teach everyone how to be a web developer.
16 | * [PHP The Right Way](https://leanpub.com/phptherightway/) - This website is available as a book completely for free.
17 | * [Using Libsodium in PHP Projects](https://paragonie.com/book/pecl-libsodium) - Guide to using Libsodium PHP extension
18 | for modern, secure, and fast cryptography.
19 |
20 | ### Paid Books
21 |
22 | * [PHP & MySQL](https://phpandmysql.com/) - PHP book with excellent illustrations that covers all the fundamentals of PHP and MySQL with practical examples.
23 | * [Build APIs You Won't Hate](https://apisyouwonthate.com/) - Everyone and their dog wants an API,
24 | so you should probably learn how to build them.
25 | * [Modern PHP](https://www.oreilly.com/library/view/modern-php/9781491905173/) - Covers modern PHP features, best practices, testing, tuning, deployment and setting up a dev environment.
26 | * [Building Secure PHP Apps](https://leanpub.com/buildingsecurephpapps) - Learn the security basics that a senior
27 | developer usually acquires over years of experience, all condensed down into one quick and easy handbook.
28 | * [Modernizing Legacy Applications In PHP](https://leanpub.com/mlaphp) - Get your code under control in a series of
29 | small, specific steps.
30 | * [Securing PHP: Core Concepts](https://leanpub.com/securingphp-coreconcepts) - A guide to some of the most common
31 | security terms and provides some examples of them in every day PHP.
32 | * [Scaling PHP](https://www.scalingphpbook.com/) - Stop playing sysadmin and get back to coding.
33 | * [Signaling PHP](https://leanpub.com/signalingphp) - PCNLT signals are a great help when writing PHP scripts that
34 | run from the command line.
35 | * [Minimum Viable Tests](https://leanpub.com/minimumviabletests) - Long-time PHP testing evangelist Chris Hartjes goes over what he feels is the minimum you need to know to get started.
36 | * [Domain-Driven Design in PHP](https://leanpub.com/ddd-in-php) - See real examples written in PHP showcasing Domain-Driven Design Architectural Styles (Hexagonal Architecture, CQRS or Event Sourcing), Tactical Design Patterns, and Bounded Context Integration.
37 |
--------------------------------------------------------------------------------
/_posts/17-01-01-Community.md:
--------------------------------------------------------------------------------
1 | ---
2 | anchor: community
3 | ---
4 |
5 | # Community {#community_title}
6 |
7 | The PHP community is as diverse as it is large, and its members are ready and willing to support new PHP programmers.
8 | Consider joining your local PHP user group (PUG) or attending larger PHP conferences to learn more about the best
9 | practices shown here. You can hang out on IRC in the #phpc channel on [irc.libera.chat][php-irc] and follow the
10 | @phpc, on [Discord][php-discord], on [X][phpc-x] or [Mastodon][phpc-mastodon]. Get out there, meet new developers, learn new topics, and above all, make new
11 | friends! Other community resources include [StackOverflow][php-so].
12 |
13 | [Read the Official PHP Events Calendar][php-calendar]
14 |
15 |
16 | [php-irc]: https://web.libera.chat/#phpc
17 | [php-discord]: https://phpc.chat/
18 | [phpc-x]: https://x.com/phpc
19 | [phpc-mastodon]: https://phpc.social/
20 | [php-so]: https://stackoverflow.com/questions/tagged/php
21 | [php-calendar]: https://www.php.net/cal.php
22 |
--------------------------------------------------------------------------------
/_posts/17-02-01-User-Groups.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: user_groups
4 | ---
5 |
6 | ## PHP User Groups {#user_groups_title}
7 |
8 | If you live in a larger city, odds are there's a PHP user group nearby. You can easily find your local PUG at
9 | [PHP.ug][php-ug]. Alternate sources might be [Meetup.com][meetup] or a search for ```php user group near me```
10 | using your favorite search engine (i.e. [Google][google]). If you live in a smaller town, there may not be a
11 | local PUG; if that's the case, start one!
12 |
13 | Special mention should be made of two global user groups: [NomadPHP] and [PHPWomen]. [NomadPHP] offers twice monthly
14 | online user group meetings with presentations by some of the top speakers in the PHP community.
15 | [PHPWomen] is a non-exclusive user group originally targeted towards the women in the PHP world. Membership is open to
16 | everyone who supports a more diverse community. PHPWomen provide a network for support, mentorship and education, and
17 | generally promote the creating of a "female friendly" and professional atmosphere.
18 |
19 | [Read about User Groups on the PHP Wiki][php-wiki]
20 |
21 | [google]: https://www.google.com/search?q=php+user+group+near+me
22 | [meetup]: https://www.meetup.com/find/
23 | [php-ug]: https://php.ug/
24 | [NomadPHP]: https://nomadphp.com/
25 | [PHPWomen]: https://x.com/PHPWomen
26 | [php-wiki]: https://wiki.php.net/usergroups
27 |
--------------------------------------------------------------------------------
/_posts/17-03-01-Conferences.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: conferences
4 | ---
5 |
6 | ## PHP Conferences {#conferences_title}
7 |
8 | The PHP community also hosts larger regional and national conferences in many countries around the world. Well-known
9 | members of the PHP community usually speak at these larger events, so it's a great opportunity to learn directly from
10 | industry leaders.
11 |
12 | [Find a PHP Conference][php-conf]
13 |
14 |
15 | [php-conf]: https://www.php.net/conferences/index.php
16 |
--------------------------------------------------------------------------------
/_posts/17-04-01-Elephpants.md:
--------------------------------------------------------------------------------
1 | ---
2 | isChild: true
3 | anchor: elephpants
4 | ---
5 |
6 | ## ElePHPants {#elephpants_title}
7 |
8 | [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.
9 |
10 | [Interview with Vincent Pontier][vincent-pontier-interview]
11 |
12 |
13 | [elephpant]: https://www.php.net/elephpant.php
14 | [vincent-pontier-interview]: https://7php.com/elephpant/
15 | [vincent-pontier]: http://www.elroubio.net/
16 |
--------------------------------------------------------------------------------
/banners.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: page
3 | title: Website Banners
4 | description: "Spread the word! Use these banner to let new PHP programmers know about PHP: The Right Way"
5 | sitemap: true
6 | ---
7 |
8 | # Web Banners
9 |
10 | Spread the word with _PHP: The Right Way_ banner images! Show new PHP developers where to find good information.
11 |
12 | ## Button 1 (120x90)
13 |
14 | 
15 |
16 | {% highlight html %}
17 |
18 |
19 |
20 | {% endhighlight %}
21 |
22 | ## Button 2 (120x60)
23 |
24 | 
25 |
26 | {% highlight html %}
27 |
28 |
29 |
30 | {% endhighlight %}
31 |
32 | ## Leaderboard (728x90)
33 |
34 | 
35 |
36 | {% highlight html %}
37 |
38 |
39 |
40 | {% endhighlight %}
41 |
42 | ## Large Rectangle (386x280)
43 |
44 | 
45 |
46 | {% highlight html %}
47 |
48 |
49 |
50 | {% endhighlight %}
51 |
52 | ## Medium Rectangle (300x250)
53 |
54 | 
55 |
56 | {% highlight html %}
57 |
58 |
59 |
60 | {% endhighlight %}
61 |
62 | ## Rectangle (180x150)
63 |
64 | 
65 |
66 | {% highlight html %}
67 |
68 |
69 |
70 | {% endhighlight %}
71 |
72 | ## Square Button (125x125)
73 |
74 | 
75 |
76 | {% highlight html %}
77 |
78 |
79 |
80 | {% endhighlight %}
81 |
82 | ## Vertical Rectangle (240x400)
83 |
84 | 
85 |
86 | {% highlight html %}
87 |
88 |
89 |
90 | {% endhighlight %}
91 |
--------------------------------------------------------------------------------
/images/banners/btn1-120x90.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/banners/btn1-120x90.png
--------------------------------------------------------------------------------
/images/banners/btn2-120x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/banners/btn2-120x60.png
--------------------------------------------------------------------------------
/images/banners/leaderboard-728x90.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/banners/leaderboard-728x90.png
--------------------------------------------------------------------------------
/images/banners/lg-rect-386x280.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/banners/lg-rect-386x280.png
--------------------------------------------------------------------------------
/images/banners/med-rect-300x250.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/banners/med-rect-300x250.png
--------------------------------------------------------------------------------
/images/banners/rect-180x150.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/banners/rect-180x150.png
--------------------------------------------------------------------------------
/images/banners/sq-btn-125x125.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/banners/sq-btn-125x125.png
--------------------------------------------------------------------------------
/images/banners/vert-rect-240x400.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/banners/vert-rect-240x400.png
--------------------------------------------------------------------------------
/images/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/favicon.png
--------------------------------------------------------------------------------
/images/nmc-logo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/nmc-logo.gif
--------------------------------------------------------------------------------
/images/og-image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/og-image.png
--------------------------------------------------------------------------------
/images/og-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeguy/php-the-right-way/966c88ac7aede793fc0d1a5c2a4b540656bd6f1f/images/og-logo.png
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | sitemap: true
4 | ---
5 |
6 | {% capture welcome_content %}{% include welcome.md %}{% endcapture %}
7 |
8 | {{ welcome_content|markdownify }}
9 |
10 |
11 | {% capture backtotop %}[Back to Top](#top){:.top}{% endcapture %}
12 | {% for post in site.posts reversed %}
13 | {% if post.isChild != true and loop.first != true %}{{ backtotop|markdownify }}
{% endif %}
14 |
15 | {{ post.content }}
16 |
17 | {% endfor %}
18 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "php-the-right-way",
3 | "version": "2.0.0",
4 | "devDependencies": {
5 | "grunt": "~0.4.5",
6 | "grunt-contrib-less": "~1.0.1",
7 | "grunt-contrib-watch": "~0.6.1",
8 | "grunt-postcss": "^0.6.0",
9 | "autoprefixer": "^6.0.3"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/pages/Functional-Programming.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: page
3 | title: Functional Programming in PHP
4 | sitemap: true
5 | ---
6 |
7 | # Functional Programming in PHP
8 |
9 | PHP supports first-class functions, meaning that a function can be assigned to a variable. Both user-defined and
10 | built-in functions can be referenced by a variable and invoked dynamically. Functions can be passed as arguments to
11 | other functions and a function can return other functions (a feature called higher-order functions).
12 |
13 | Recursion, a feature that allows a function to call itself, is supported by the language, but most of the PHP code
14 | focus is on iteration.
15 |
16 | Anonymous functions (with support for closures) have been present since PHP 5.3 (2009).
17 |
18 | PHP 5.4 added the ability to bind closures to an object's scope and also improved support for callables such that they
19 | can be used interchangeably with anonymous functions in almost all cases.
20 |
21 | The most common usage of higher-order functions is when implementing a strategy pattern. The built-in `array_filter()`
22 | function asks both for the input array (data) and a function (a strategy or a callback) used as a filter function on
23 | each array item.
24 |
25 | {% highlight php %}
26 | $min
56 | *
57 | * Returns a single filter out of a family of "greater than n" filters
58 | */
59 | function criteria_greater_than($min)
60 | {
61 | return function($item) use ($min) {
62 | return $item > $min;
63 | };
64 | }
65 |
66 | $input = array(1, 2, 3, 4, 5, 6);
67 |
68 | // Use array_filter on a input with a selected filter function
69 | $output = array_filter($input, criteria_greater_than(3));
70 |
71 | print_r($output); // items > 3
72 | {% endhighlight %}
73 |
74 | Each filter function in the family accepts only elements greater than some minimum value. The single filter returned by
75 | `criteria_greater_than` is a closure with `$min` argument closed by the value in the scope (given as an argument when
76 | `criteria_greater_than` is called).
77 |
78 | Early binding is used by default for importing `$min` variable into the created function. For true closures with late
79 | binding one should use a reference when importing. Imagine a templating or input validation library, where a closure is
80 | defined to capture variables in scope and access them later when the anonymous function is evaluated.
81 |
82 | * [Read about Anonymous functions][anonymous-functions]
83 | * [More details in the Closures RFC][closures-rfc]
84 | * [Read about dynamically invoking functions with `call_user_func_array()`][call-user-func-array]
85 |
86 |
87 | [anonymous-functions]: https://www.php.net/functions.anonymous
88 | [closures-rfc]: https://wiki.php.net/rfc/closures
89 | [call-user-func-array]: https://www.php.net/function.call-user-func-array
90 |
--------------------------------------------------------------------------------
/pages/example.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: page
3 | title: Example Stand-Alone Page
4 | ---
5 |
6 | # Page Title
7 |
8 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
9 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
10 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
11 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
12 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
13 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
14 |
15 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
16 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
17 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
18 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
19 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
20 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
21 |
22 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
23 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
24 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
25 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
26 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
27 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
28 |
--------------------------------------------------------------------------------
/scripts/setup.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | // Attach FastClick
3 | var attachFastClick = Origami.fastclick;
4 | attachFastClick(document.body);
5 |
6 | // Mobile TOC menu
7 | var $window = $(window),
8 | $nav = $('.site-navigation');
9 | $nav.click(function (e) {
10 | var $target = $(e.target);
11 | if ($target.is($nav) && $window.width() <= 375) {
12 | $nav.toggleClass('open');
13 | }
14 | if ($target.is('a')) {
15 | $nav.removeClass('open');
16 | }
17 | });
18 | })(jQuery);
19 |
--------------------------------------------------------------------------------
/styles/all.less:
--------------------------------------------------------------------------------
1 | /* ==========================================================================
2 | NMC Bootstrap
3 |
4 | This LESS file imports all other LESS files. You should compile
5 | and minify this file before site launch.
6 | ========================================================================== */
7 |
8 | /* Import NMC bootstrap */
9 |
10 | @import "base/all";
11 |
12 | /* Import site-specific styles */
13 |
14 | @import "site/site-header.less";
15 | @import "site/site-navigation.less";
16 | @import "site/site-content.less";
17 | @import "site/site-footer.less";
18 |
19 | /* Tablets and Smartphones */
20 |
21 | @media only screen and (max-width : 1024px) {
22 | .build-date{
23 | text-align: center;
24 | }
25 | .site-header{
26 | height: 220px;
27 | position: absolute;
28 | top: 20px;
29 | left: 0;
30 | width: 100%;
31 | }
32 | .fork-me img{
33 | height: 110px;
34 | width: 110px;
35 | }
36 | .site-navigation{
37 | margin-top: 240px;
38 | padding: 20px;
39 | position: relative;
40 | width: auto;
41 |
42 | ul{
43 | border: 1px solid #999;
44 | border-bottom: none;
45 | }
46 | li{
47 | .man;
48 | .pan;
49 | }
50 | a{
51 | background: #CCC;
52 | display: block;
53 | border-bottom: 1px solid #999;
54 | padding: 10px;
55 | text-decoration: none;
56 | }
57 | ul ul{
58 | border: none;
59 | .man;
60 | .pan;
61 | }
62 | ul ul a{
63 | background: transparent;
64 | }
65 | }
66 | .site-content{
67 | padding: 20px;
68 | }
69 | .top{
70 | display: inline-block;
71 | float: none;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/styles/base/all.less:
--------------------------------------------------------------------------------
1 | @import "reset";
2 | @import "prefixer";
3 | @import "spacing";
4 | @import "typography";
5 | @import "idioms";
6 | @import "grid";
7 | @import "bars-buttons";
8 | @import "buttons";
--------------------------------------------------------------------------------
/styles/base/bars-buttons.less:
--------------------------------------------------------------------------------
1 | .button() {
2 | .border-box;
3 | cursor: pointer;
4 | display: inline-block;
5 | .phh;
6 | text-align: center;
7 | font-weight: bold;
8 | }
9 | .button-hover(){
10 | text-decoration: none;
11 | }
12 | .bar() {
13 | display: block;
14 | .pah;
15 | text-align: center;
16 | font-weight: bold;
17 | }
18 |
19 | /* Sizes */
20 |
21 | .btn-size(@scale){
22 | height: @baseline * @scale !important;
23 | padding-bottom: 0 !important;
24 | padding-top: 0 !important;
25 | line-height: @baseline * (@scale * 0.9);
26 | }
27 | .btn-half{
28 | .btn-size(1);
29 | font-size: 0.8em;
30 | }
31 | .btn-single{
32 | .btn-size(1.5);
33 | font-size: 1em;
34 | }
35 | .btn-double{
36 | .btn-size(2);
37 | font-size: 1.1em;
38 | }
39 |
40 | /* Shapes */
41 |
42 | .bb-shape-square() {
43 | .border-radius(0);
44 | }
45 | .bb-shape-rounded(@rad:3px) {
46 | .border-radius(@rad);
47 | }
48 | .bb-shape-round() {
49 | .border-radius(@baseline);
50 | }
51 |
52 | /* Text */
53 |
54 | .bb-text-dark(){
55 | color: #333;
56 | text-shadow: 0 1px 0 #fff;
57 | }
58 | .bb-text-light(){
59 | color: #fff;
60 | text-shadow: 0 -1px 0 rgba(0,0,0,.3);
61 | }
62 | .bb-text-color(@color){
63 |
64 | }
65 |
66 | /* Color */
67 |
68 | .bb-color-plain(@color){
69 | background: @color;
70 | }
71 | .bb-color-gradient(@color){
72 | .gradient(@color,lighten(@color,10%),darken(@color,10%));
73 | }
74 | .bb-color-soft(@color){
75 | .gradient(@color,lighten(@color,5%),darken(@color,5%));
76 | }
77 | .bb-color-gloss(@color){
78 | @topStart: desaturate(lighten(@color,40%),20%);
79 | @topStop: desaturate(lighten(@color,20%),40%);
80 | @bottomStart: desaturate(lighten(@color,10%),30%);
81 | @bottomStop: desaturate(lighten(@color,15%),30%);
82 | .linear-gradient-top(@color,@topStart,0%,@topStop,50%,@bottomStart,50%,@bottomStop,100%);
83 | }
84 |
85 | /* Border */
86 |
87 | .bb-border-noborder(){
88 | border: none;
89 | }
90 | .bb-border-plain(@color){
91 | border: 1px solid darken(@color,10%);
92 | }
93 | .bb-border-contrast(@color){
94 | border: 1px solid darken(@color,15%);
95 | .box-shadow(inset 0 0 1px 1px lighten(@color,15%));
96 | }
97 | .bb-border-meta(@color){
98 | border: 1px solid darken(@color,15%);
99 | .box-shadow(inset 0 2px 1px -1px lighten(@color,20%));
100 | }
101 |
102 | /* Minimal */
103 |
104 | .button-minimal(@color) {
105 | .button();
106 | .bb-shape-rounded();
107 | .bb-color-plain(@color);
108 | .bb-border-contrast(@color);
109 | .bb-text-dark();
110 | }
111 | .button-minimal-hover(@color){
112 | .button-minimal(darken(@color,5%));
113 | .button-hover();
114 | }
115 | .button-minimal-active(@color){
116 | .button-minimal-hover(darken(@color,5%));
117 | }
118 | .bar-minimal(@color) {
119 | .button-minimal(@color);
120 | .bar();
121 | }
122 |
123 | /* Clean */
124 |
125 | .button-clean(@color) {
126 | .button();
127 | .bb-shape-rounded();
128 | .bb-color-gradient(@color);
129 | .bb-border-plain(darken(@color,5%));
130 | .bb-text-dark();
131 | }
132 | .button-clean-hover(@color){
133 | .button-clean(darken(@color,5%));
134 | .button-hover();
135 | }
136 | .button-clean-active(@color){
137 | .button-clean-hover(darken(@color,5%));
138 | }
139 | .bar-clean(@color){
140 | .button-clean(@color);
141 | .bar();
142 | }
143 |
144 | /* Soft */
145 |
146 | .button-soft(@color) {
147 | .button();
148 | .bb-shape-rounded();
149 | .bb-color-soft(@color);
150 | .bb-border-meta(darken(@color,5%));
151 | .bb-text-light();
152 | }
153 | .button-soft-hover(@color){
154 | .button-soft(darken(@color,5%));
155 | .button-hover();
156 | }
157 | .button-soft-active(@color){
158 | .button-soft-hover(darken(@color,5%));
159 | }
160 | .bar-soft(@color){
161 | .button-soft(@color);
162 | .bar();
163 | }
164 |
165 | /* Pill */
166 |
167 | .button-pill(@color) {
168 | .button();
169 | .bb-shape-round();
170 | .bb-color-soft(@color);
171 | .bb-border-meta(darken(@color,5%));
172 | .bb-text-light();
173 | }
174 | .button-pill-hover(@color){
175 | .button-pill(darken(@color,5%));
176 | .button-hover();
177 | }
178 | .button-pill-active(@color){
179 | .button-pill-hover(darken(@color,5%));
180 | }
181 | .bar-pill(@color){
182 | .button-pill(@color);
183 | .bar();
184 | }
185 |
186 | /* Gloss */
187 |
188 | .button-gloss(@color) {
189 | .button();
190 | .bb-shape-rounded(5px);
191 | .bb-color-gloss(@color);
192 | .bb-border-plain(darken(@color,5%));
193 | .box-shadow(inset 0 1px 0 0 rgba(255,255,255,.5));
194 | .bb-text-light();
195 | }
196 | .button-gloss-hover(@color){
197 | .button-gloss(darken(@color,5%));
198 | .box-shadow(inset 0 1px 0 0 rgba(255,255,255,.3));
199 | .button-hover();
200 | }
201 | .button-gloss-active(@color){
202 | .button-gloss-hover(darken(@color,5%));
203 | .box-shadow(inset 0 0 5px 0 rgba(0,0,0,.3));
204 | }
205 | .bar-gloss(@color){
206 | .button-gloss(@color);
207 | .bar();
208 | }
209 |
210 | @btn-minimal-color: #eee;
211 | .btn-minimal { .button-minimal(@btn-minimal-color); }
212 | .btn-minimal:hover { .button-minimal-hover(@btn-minimal-color); }
213 | .btn-minimal:active { .button-minimal-active(@btn-minimal-color); }
214 |
215 | @btn-clean-color: #eee;
216 | .btn-clean { .button-clean(@btn-clean-color); }
217 | .btn-clean:hover { .button-clean-hover(@btn-clean-color); }
218 | .btn-clean:active { .button-clean-active(@btn-clean-color); }
219 |
220 | @btn-soft-color: #6C84AB;
221 | .btn-soft { .button-soft(@btn-soft-color); }
222 | .btn-soft:hover { .button-soft-hover(@btn-soft-color); }
223 | .btn-soft:active { .button-soft-active(@btn-soft-color); }
224 |
225 | @btn-pill-color: #6C84AB;
226 | .btn-pill { .button-pill(@btn-pill-color); }
227 | .btn-pill:hover { .button-pill-hover(@btn-pill-color); }
228 | .btn-pill:active { .button-pill-active(@btn-pill-color); }
229 |
230 | @btn-gloss-color: #172D6E;
231 | .btn-gloss { .button-gloss(@btn-gloss-color); }
232 | .btn-gloss:hover { .button-gloss-hover(@btn-gloss-color); }
233 | .btn-gloss:active { .button-gloss-active(@btn-gloss-color); }
234 |
235 |
236 | .bar-minimal { .bar-minimal(@btn-minimal-color); }
237 | .bar-clean { .bar-clean(@btn-clean-color); }
238 | .bar-soft { .bar-soft(@btn-soft-color); }
239 | .bar-pill { .bar-pill(@btn-pill-color); }
240 | .bar-gloss { .bar-gloss(@btn-gloss-color); }
--------------------------------------------------------------------------------
/styles/base/buttons.less:
--------------------------------------------------------------------------------
1 | /* ==========================================================================
2 | Settings
3 | ========================================================================== */
4 |
5 | @import 'variables.less';
6 |
7 | /*
8 | @baseline: @baseline;
9 | @button-color: @button-color;
10 | @button-primary-color: @button-primary-color;
11 | @button-info-color: @button-info-color;
12 | @button-success-color: @button-success-color;
13 | @button-warning-color: @button-warning-color;
14 | @button-danger-color: @button-danger-color;
15 | */
16 |
17 | /* ==========================================================================
18 | Default
19 | ========================================================================== */
20 |
21 | .btn{
22 | .btn-s;
23 | background-clip: border-box !important;
24 | background-repeat: repeat-x;
25 | border: 1px solid rgba(0, 0, 0, 0.25);
26 | .border-box;
27 | .border-radius(4px);
28 | box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
29 | cursor: pointer;
30 | display: inline-block;
31 | .gradient(@button-color, lighten(@button-color, 10%), @button-color);
32 | .phh;
33 | .pvn;
34 | .transition(background-position linear 0.1s);
35 | vertical-align: middle;
36 | color: #333;
37 | font-family: @body-font-family;
38 | text-decoration: none !important;
39 | text-shadow: rgba(255,255,255,0.75) 0 1px 0;
40 |
41 | &:hover{
42 | background-position: 0 -15px;
43 | }
44 | }
45 |
46 | /* ==========================================================================
47 | Styles
48 | ========================================================================== */
49 |
50 | .btn-primary,
51 | .btn-info,
52 | .btn-success,
53 | .btn-warning,
54 | .btn-danger{
55 | color: #FFF !important;
56 | text-shadow: rgba(0,0,0,0.25) 0 -1px 0 !important;
57 | }
58 | .btn-primary{
59 | .btn;
60 | .gradient(@button-primary-color, lighten(@button-primary-color, 10%), @button-primary-color);
61 | }
62 | .btn-info{
63 | .btn;
64 | .gradient(@button-info-color, lighten(@button-info-color, 10%), @button-info-color);
65 | }
66 | .btn-success{
67 | .btn;
68 | .gradient(@button-success-color, lighten(@button-success-color, 10%), @button-success-color);
69 | }
70 | .btn-warning{
71 | .btn;
72 | .gradient(@button-warning-color, lighten(@button-warning-color, 10%), @button-warning-color);
73 | }
74 | .btn-danger{
75 | .btn;
76 | .gradient(@button-danger-color, lighten(@button-danger-color, 10%), @button-danger-color);
77 | }
78 |
79 | /* ==========================================================================
80 | Sizes (Half = h, Single = s, Double = d)
81 | ========================================================================== */
82 |
83 | .btn-h, .btn-half{
84 | height: @baseline;
85 | font-size: @baseline * 0.6;
86 | line-height: @baseline;
87 | }
88 | .btn-s, .btn-single{
89 | height: @baseline * 1.5;
90 | font-size: @baseline * 0.75;
91 | line-height: @baseline * 1.5;
92 | }
93 | .btn-d, .btn-double{
94 | height: @baseline * 2;
95 | font-size: @baseline;
96 | line-height: @baseline * 2;
97 | }
--------------------------------------------------------------------------------
/styles/base/grid.less:
--------------------------------------------------------------------------------
1 | /**
2 | * Hybrid Grid Sytem
3 | *
4 | * Blend of the Semantic Grid System and Zurb Foundation with a little Twitter Bootstrap
5 | */
6 |
7 | /* Settings */
8 |
9 | @import 'variables.less';
10 |
11 | /*
12 | @fixed-column-width: 40px;
13 | @fixed-gutter-width: 20px;
14 | @fixed-columns: 12;
15 |
16 | @fluid-column-width: 4.3%;
17 | @fluid-gutter-width: 4.4%;
18 | @fluid-columns: 12;
19 |
20 | @mobile-break-width: 480px;
21 | @mobile-column-width: 8.6%;
22 | @mobile-gutter-width: 8.8%;
23 | @mobile-columns: 6;
24 | */
25 |
26 | /* Grid */
27 |
28 | #grid {
29 |
30 | .cols(@cols,@width,@gutter){
31 | .border-box();
32 | width: ((@cols * @width) + ((@cols - 1) * @gutter));
33 | margin-left: @gutter;
34 | position: relative;
35 | display: inline;
36 | float: left;
37 | min-height: 1px;
38 | &:first-child {
39 | margin-left: 0;
40 | }
41 | &:last-child {
42 | float: right;
43 | }
44 | }
45 |
46 | }
47 |
48 | .grid-fixed,.grid-fluid {
49 | .clearfix;
50 | .row {
51 | .border-box();
52 | display: block;
53 | width: 100%;
54 | margin: 0 auto;
55 | .clearfix;
56 |
57 | .center,.center:last-child {
58 | float: none;
59 | display: block;
60 | margin: 0 auto;
61 | }
62 | }
63 | }
64 |
65 | .grid-fixed {
66 | @total-width: (@fixed-column-width*@fixed-columns) + (@fixed-gutter-width*(@fixed-columns - 1));
67 | @column-width: @fixed-column-width;
68 | @gutter-width: @fixed-gutter-width;
69 | @columns: @fixed-columns;
70 | width: @total-width;
71 |
72 | /* This is duplicated in both classes. Unavoidable. */
73 | .colX (@index) when (@index > 0) {
74 | (~".col@{index}") {
75 | #grid > .cols(@index,@column-width,@gutter-width);
76 | }
77 | .colX(@index - 1);
78 | }
79 | .colX (0) {}
80 | .colX(@columns);
81 |
82 | .offsetX (@index) when (@index > 0) {
83 | (~".offset@{index}") {
84 | margin-left: (@index * @column-width) + ((@index + 1) * @gutter-width);
85 | }
86 | .offsetX(@index - 1);
87 | }
88 | .offsetX (0) {}
89 | .offsetX(@columns - 1);
90 |
91 | .pushX (@index) when (@index > 0) {
92 | (~".push@{index}") {
93 | left: @index * (@column-width + @gutter-width);
94 | }
95 | .pushX(@index - 1);
96 | }
97 | .pushX (0) {}
98 | .pushX(@columns - 1);
99 |
100 | .pullX (@index) when (@index > 0) {
101 | (~".pull@{index}") {
102 | right: @index * (@column-width + @gutter-width);
103 | }
104 | .pullX(@index - 1);
105 | }
106 | .pullX (0) {}
107 | .pullX(@columns - 1);
108 | }
109 |
110 |
111 | .grid-fluid {
112 | @total-width: 100%;
113 | @column-width: @fluid-column-width;
114 | @gutter-width: @fluid-gutter-width;
115 | @columns: @fluid-columns;
116 | width: @total-width;
117 |
118 | /* This is duplicated in both classes. Unavoidable. */
119 | .colX (@index) when (@index > 0) {
120 | (~".col@{index}") {
121 | #grid > .cols(@index,@column-width,@gutter-width);
122 | }
123 | .colX(@index - 1);
124 | }
125 | .colX (0) {}
126 | .colX(@columns);
127 |
128 | .offsetX (@index) when (@index > 0) {
129 | (~".offset@{index}") {
130 | margin-left: (@index * @column-width) + ((@index + 1) * @gutter-width);
131 | }
132 | .offsetX(@index - 1);
133 | }
134 | .offsetX (0) {}
135 | .offsetX(@columns - 1);
136 |
137 | .pushX (@index) when (@index > 0) {
138 | (~".push@{index}") {
139 | left: @index * (@column-width + @gutter-width);
140 | }
141 | .pushX(@index - 1);
142 | }
143 | .pushX (0) {}
144 | .pushX(@columns - 1);
145 |
146 | .pullX (@index) when (@index > 0) {
147 | (~".pull@{index}") {
148 | right: @index * (@column-width + @gutter-width);
149 | }
150 | .pullX(@index - 1);
151 | }
152 | .pullX (0) {}
153 | .pullX(@columns - 1);
154 | }
155 |
156 |
157 | @media all and (max-width: @mobile-break-width) {
158 |
159 | // Reset all columns to full width
160 | .grid-fixed {
161 | .colX (@index) when (@index > 0) {
162 | (~".col@{index}") {
163 | width: 100%;
164 | margin: 0;
165 | left: 0;
166 | right: 0;
167 | }
168 | .colX(@index - 1);
169 | }
170 | .colX (0) {}
171 | .colX(@fixed-columns);
172 | }
173 | .grid-fluid {
174 | .colX (@index) when (@index > 0) {
175 | (~".col@{index}") {
176 | width: 100%;
177 | margin: 0;
178 | left: 0;
179 | right: 0;
180 | }
181 | .colX(@index - 1);
182 | }
183 | .colX (0) {}
184 | .colX(@fluid-columns);
185 | }
186 |
187 | .grid-fixed, .grid-fluid {
188 | @total-width: 100%;
189 | @column-width: @mobile-column-width;
190 | @gutter-width: @mobile-gutter-width;
191 | @columns: @mobile-columns;
192 | width: @total-width;
193 |
194 | .m-colX (@index) when (@index > 0) {
195 | (~".m-col@{index}") {
196 | #grid > .cols(@index,@column-width,@gutter-width);
197 | }
198 | .m-colX(@index - 1);
199 | }
200 | .m-colX (0) {}
201 | .m-colX(@mobile-columns);
202 |
203 | .m-offsetX (@index) when (@index > 0) {
204 | (~".m-offset@{index}") {
205 | margin-left: (@index * @column-width) + ((@index + 1) * @gutter-width);
206 | }
207 | .m-offsetX(@index - 1);
208 | }
209 | .m-offsetX (0) {}
210 | .m-offsetX(@columns - 1);
211 |
212 | .m-pushX (@index) when (@index > 0) {
213 | (~".m-push@{index}") {
214 | left: @index * (@column-width + @gutter-width);
215 | }
216 | .m-pushX(@index - 1);
217 | }
218 | .m-pushX (0) {}
219 | .m-pushX(@columns - 1);
220 |
221 | .m-pullX (@index) when (@index > 0) {
222 | (~".m-pull@{index}") {
223 | right: @index * (@column-width + @gutter-width);
224 | }
225 | .m-pullX(@index - 1);
226 | }
227 | .m-pullX (0) {}
228 | .m-pullX(@columns - 1);
229 | }
230 |
231 | }
232 |
--------------------------------------------------------------------------------
/styles/base/idioms.less:
--------------------------------------------------------------------------------
1 | /**
2 | * New Media Campaigns Idioms
3 | *
4 | * These are common patterns we use in all of our
5 | * projects. They are consolidated here to keep code DRY.
6 | *
7 | * Listing
8 | * * .no-text, .text-replace
9 | * * .no-list
10 | * * .no-form
11 | * * .fixed-width(@width)
12 | * * .column-width(@width)
13 | * * .column-left(@width)
14 | * * .column-right(@width)
15 | * * .full-size
16 | * * .absolute-default
17 | * * .absolute-fullsize
18 | * * .clearfix
19 | */
20 |
21 | /* Hides text when using image replacement */
22 | .no-text, .text-replace{
23 | overflow: hidden;
24 | text-indent: 100%;
25 | white-space: nowrap;
26 | }
27 |
28 | /* Removes bullets, margin, and padding from list */
29 | .no-list{
30 | list-style: none;
31 | margin: 0;
32 | padding: 0;
33 | }
34 |
35 | /* Removes webkit styling from form element */
36 | .no-form{
37 | border: none;
38 | margin: 0;
39 | padding: 0;
40 | -webkit-appearance: none;
41 | }
42 |
43 | /* Center a fixed width container */
44 | .fixed-width(@width) {
45 | margin: 0 auto;
46 | width: @width;
47 | }
48 |
49 | /* Adds left or right columns (e.g. content and sidebar) */
50 | .column-width(@width){
51 | display: inline;
52 | width: @width;
53 | }
54 | .column-left(@width){
55 | .column-width(@width);
56 | float: left;
57 | }
58 | .column-right(@width){
59 | .column-width(@width);
60 | float: right;
61 | }
62 |
63 | /* Set width and height of element to that of its parent */
64 | .full-size{
65 | height: 100%;
66 | width: 100%;
67 | }
68 |
69 | /* Position element absolutely to 0,0 */
70 | .absolute-default{
71 | position: absolute;
72 | left: 0;
73 | top: 0;
74 | }
75 |
76 | /* Position element absolutely and set its width and height to that of its parent (useful for slideshows) */
77 | .absolute-fullsize{
78 | .absolute-default;
79 | .full-size;
80 | }
81 |
82 | /* The micro clearfix http://nicolasgallagher.com/micro-clearfix-hack/ */
83 | .clearfix {
84 | *zoom:1;
85 |
86 | &:before,
87 | &:after {
88 | content:"";
89 | display:table;
90 | }
91 | &:after {
92 | clear:both;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/styles/base/reset.less:
--------------------------------------------------------------------------------
1 | /**
2 | * html5doctor.com Reset Stylesheet
3 | * v1.6.1
4 | * Last Updated: 2010-09-17
5 | * Author: Richard Clark - http://richclarkdesign.com
6 | * Twitter: @rich_clark
7 | */
8 |
9 | html, body, div, span, object, iframe,
10 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
11 | abbr, address, cite, code,
12 | del, dfn, em, img, ins, kbd, q, samp,
13 | small, strong, sub, sup, var,
14 | b, i,
15 | dl, dt, dd, ol, ul, li,
16 | fieldset, form, label, legend,
17 | table, caption, tbody, tfoot, thead, tr, th, td,
18 | article, aside, canvas, details, figcaption, figure,
19 | footer, header, hgroup, menu, nav, section, summary,
20 | time, mark, audio, video {
21 | margin:0;
22 | padding:0;
23 | border:0;
24 | outline:0;
25 | font-size:100%;
26 | vertical-align:baseline;
27 | background:transparent;
28 | }
29 |
30 | body {
31 | line-height:1;
32 | }
33 |
34 | article,aside,details,figcaption,figure,
35 | footer,header,hgroup,menu,nav,section {
36 | display:block;
37 | }
38 |
39 | nav ul {
40 | list-style:none;
41 | }
42 |
43 | blockquote, q {
44 | quotes:none;
45 | }
46 |
47 | blockquote:before, blockquote:after,
48 | q:before, q:after {
49 | content:'';
50 | content:none;
51 | }
52 |
53 | a {
54 | margin:0;
55 | padding:0;
56 | font-size:100%;
57 | vertical-align:baseline;
58 | background:transparent;
59 | }
60 |
61 | /* change colours to suit your needs */
62 | ins {
63 | background-color:#ff9;
64 | color:#000;
65 | text-decoration:none;
66 | }
67 |
68 | /* change colours to suit your needs */
69 | mark {
70 | background-color:#ff9;
71 | color:#000;
72 | font-style:italic;
73 | font-weight:bold;
74 | }
75 |
76 | del {
77 | text-decoration: line-through;
78 | }
79 |
80 | abbr[title], dfn[title] {
81 | border-bottom:1px dotted;
82 | cursor:help;
83 | }
84 |
85 | table {
86 | border-collapse:collapse;
87 | border-spacing:0;
88 | }
89 |
90 | /* change border colour to suit your needs */
91 | hr {
92 | display:block;
93 | height:1px;
94 | border:0;
95 | border-top:1px solid #cccccc;
96 | margin:1em 0;
97 | padding:0;
98 | }
99 |
100 | input, select {
101 | vertical-align:middle;
102 | }
--------------------------------------------------------------------------------
/styles/base/spacing.less:
--------------------------------------------------------------------------------
1 | /**
2 | * Spacing
3 | *
4 | * This LESS file defines margins and paddings for block-level
5 | * elements. Helper classes are included for use elsewhere
6 | * in site styles.
7 | */
8 |
9 | /* Settings */
10 |
11 | @import 'variables.less';
12 |
13 | /*
14 | @baseline: @baseline;
15 | */
16 |
17 | /**
18 | * Spacing
19 | * p, m, lh = padding, margin, line-height
20 | * a, t, r, b, l, h, v = all, top, right, bottom, left, horizontal, vertical
21 | * n, h, s, d = none(0px), half(@baseline / 2), single(@baseline), double(@baseline * 2), none(0px)
22 | */
23 |
24 | .ptn, .pvn, .pan{
25 | padding-top: 0 !important
26 | }
27 | .pth, .pvh, .pah{
28 | padding-top: @baseline / 2 !important
29 | }
30 | .pts, .pvs, .pas{
31 | padding-top: @baseline !important
32 | }
33 | .ptd, .pvd, .pad{
34 | padding-top: @baseline * 2 !important
35 | }
36 | .prn, .phn, .pan{
37 | padding-right: 0 !important
38 | }
39 | .prh, .phh, .pah{
40 | padding-right: @baseline / 2 !important
41 | }
42 | .prs, .phs, .pas{
43 | padding-right: @baseline !important
44 | }
45 | .prd, .phd, .pad{
46 | padding-right: @baseline * 2 !important
47 | }
48 | .pbn, .pvn, .pan{
49 | padding-bottom: 0 !important
50 | }
51 | .pbh, .pvh, .pah{
52 | padding-bottom: @baseline / 2 !important
53 | }
54 | .pbs, .pvs, .pas{
55 | padding-bottom: @baseline !important
56 | }
57 | .pbd, .pvd, .pad{
58 | padding-bottom: @baseline * 2 !important
59 | }
60 | .pln, .phn, .pan{
61 | padding-left: 0 !important
62 | }
63 | .plh, .phh, .pah{
64 | padding-left: @baseline / 2 !important
65 | }
66 | .pls, .phs, .pas{
67 | padding-left: @baseline !important
68 | }
69 | .pld, .phd, .pad{
70 | padding-left: @baseline * 2 !important
71 | }
72 | .mtn, .mvn, .man{
73 | margin-top: 0 !important
74 | }
75 | .mth, .mvh, .mah{
76 | margin-top: @baseline / 2 !important
77 | }
78 | .mts, .mvs, .mas{
79 | margin-top: @baseline !important
80 | }
81 | .mtd, .mvd, .mad{
82 | margin-top: @baseline * 2 !important
83 | }
84 | .mrn, .mhn, .man{
85 | margin-right: 0 !important
86 | }
87 | .mrh, .mhh, .mah{
88 | margin-right: @baseline / 2 !important
89 | }
90 | .mrs, .mhs, .mas{
91 | margin-right: @baseline !important
92 | }
93 | .mrd, .mhd, .mad{
94 | margin-right: @baseline * 2 !important
95 | }
96 | .mbn, .mvn, .man{
97 | margin-bottom: 0 !important
98 | }
99 | .mbh, .mvh, .mah{
100 | margin-bottom: @baseline / 2 !important
101 | }
102 | .mbs, .mvs, .mas{
103 | margin-bottom: @baseline !important
104 | }
105 | .mbd, .mvd, .mad{
106 | margin-bottom: @baseline * 2 !important
107 | }
108 | .mln, .mhn, .man{
109 | margin-left: 0 !important
110 | }
111 | .mlh, .mhh, .mah{
112 | margin-left: @baseline / 2 !important
113 | }
114 | .mls, .mhs, .mas{
115 | margin-left: @baseline !important
116 | }
117 | .mld, .mhd, .mad{
118 | margin-left: @baseline * 2 !important
119 | }
120 | .lhh {
121 | line-height: @baseline / 2 !important;
122 | }
123 | .lhs {
124 | line-height: @baseline !important;
125 | }
126 | .lhd {
127 | line-height: @baseline * 2 !important;
128 | }
129 | .lhn {
130 | line-height: 0 !important;
131 | }
132 |
--------------------------------------------------------------------------------
/styles/base/variables.less:
--------------------------------------------------------------------------------
1 | /* ==========================================================================
2 | Spacing
3 | ========================================================================== */
4 |
5 | @baseline: 20px;
6 |
7 | /* ==========================================================================
8 | Typography
9 | ========================================================================== */
10 |
11 | @body-color: #555;
12 | @body-font-family: "Helvetica Neue", "HelveticaNeue", Helvetica, Arial, "Lucida Grande", sans-serif;
13 | @body-font-size: 14px;
14 | @body-accent-color: #f00;
15 |
16 | @header-color: #000;
17 | @header-font-family: "Helvetica Neue", "HelveticaNeue", Helvetica, Arial, "Lucida Grande", sans-serif;
18 | @header-font-weight: bold;
19 |
20 | /* ==========================================================================
21 | Grid
22 | ========================================================================== */
23 |
24 | @fixed-column-width: 40px;
25 | @fixed-gutter-width: 20px;
26 | @fixed-columns: 12;
27 |
28 | @fluid-column-width: 4.3%;
29 | @fluid-gutter-width: 4.4%;
30 | @fluid-columns: 12;
31 |
32 | @mobile-break-width: 480px;
33 | @mobile-column-width: 20%;
34 | @mobile-gutter-width: 6.6666%;
35 | @mobile-columns: 4;
36 |
37 | /* ==========================================================================
38 | Buttons
39 | ========================================================================== */
40 |
41 | @button-color: #DDD;
42 | @button-primary-color: #0055CC;
43 | @button-info-color: #2F96B4;
44 | @button-success-color: #51A351;
45 | @button-warning-color: #FAA732;
46 | @button-danger-color: #BD362F;
47 |
48 | /* ==========================================================================
49 | Site Variables
50 | ========================================================================== */
51 |
52 | @import "../site/variables";
--------------------------------------------------------------------------------
/styles/print.css:
--------------------------------------------------------------------------------
1 | body, .site-title, h1, h2, h3{
2 | font-family: 'Georgia' !important;
3 | }
4 |
5 |
6 | nav.site-navigation, a.fork-me, a.top{
7 | display:none;
8 | }
9 |
10 | div.site-content{
11 | padding: 20px 40px 40px 20px;
12 | }
--------------------------------------------------------------------------------
/styles/site/site-content.less:
--------------------------------------------------------------------------------
1 | .site-content{
2 | padding: 20px 40px 40px 320px;
3 |
4 | h1{
5 | clear: both;
6 | }
7 | }
8 | .interior-site-content{
9 | .pad;
10 | }
11 | .top{
12 | background: #333;
13 | display: inline-block;
14 | float: right;
15 | margin-right: -40px;
16 | padding: 4px 8px;
17 | color: #FFF;
18 | font-size: 12px;
19 | text-decoration: none !important;
20 | }
21 |
--------------------------------------------------------------------------------
/styles/site/site-footer.less:
--------------------------------------------------------------------------------
1 | .site-footer{
2 | clear: both;
3 | .ptd;
4 | font-size: 13px;
5 | text-align: center;
6 | }
7 | .site-footer img{
8 | margin-left: 2px;
9 | position: relative;
10 | top: -2px;
11 | vertical-align: middle;
12 | }
13 | .site-footer ul{
14 | list-style: none;
15 | .mhn;
16 | .phn;
17 | }
18 |
--------------------------------------------------------------------------------
/styles/site/site-header.less:
--------------------------------------------------------------------------------
1 | .site-header{
2 | position: relative;
3 | z-index: 1;
4 | text-align: center;
5 | }
6 | .site-title{
7 | .mbn;
8 | font-family: 'Alfa Slab One';
9 | font-size: @baseline * 4;
10 | font-weight: normal !important;
11 | line-height: @baseline * 5 !important;
12 |
13 | a{
14 | text-decoration: none;
15 | }
16 | }
17 | .site-slogan{
18 | font-weight: normal;
19 | }
20 | .fork-me, .fork-me img{
21 | position: absolute;
22 | top: 0;
23 | right: 0;
24 | }
25 | .fork-me{
26 | z-index: 2;
27 | }
28 |
29 | .interior-site-header{
30 | background: #EEE;
31 | .inner-shadow(fade(#000, 7%) 0 0 40px);
32 | .pas;
33 | text-align: center;
34 |
35 | .site-title{
36 | font-size: @baseline * 2;
37 | line-height: @baseline * 2 !important;
38 | }
39 | .site-slogan{
40 | .mbs;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/styles/site/site-navigation.less:
--------------------------------------------------------------------------------
1 | .site-navigation{
2 | background: #EEE;
3 | .inner-shadow(fade(#000, 7%) 0 0 40px);
4 | .pas;
5 | position: fixed;
6 | top: 0;
7 | bottom: 0;
8 | overflow: auto;
9 | width: 240px;
10 | }
11 | .build-date{
12 | .mbs;
13 | color: #AAA;
14 | font-family: Helvetica, Arial, sans-serif;
15 | font-size: 11px;
16 | }
17 | .site-navigation ul{
18 | .man;
19 | .pan;
20 | .no-list;
21 | font-size: 16px;
22 | margin-bottom: 10px;
23 | }
24 | .site-navigation > ul > li{
25 | margin-bottom: 10px;
26 | }
27 | .site-navigation a{
28 | text-decoration: underline;
29 |
30 | &:hover{
31 | text-decoration: none;
32 | }
33 | }
34 | .site-navigation a.active{
35 | background-color: #ff9;
36 | }
37 | .site-navigation ul ul{
38 | .mls;
39 | .pth;
40 | font-size: 12px;
41 |
42 | a{
43 | text-decoration: none;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/styles/site/variables.less:
--------------------------------------------------------------------------------
1 | /* ==========================================================================
2 | Spacing
3 | ========================================================================== */
4 |
5 | @baseline: 20px;
6 |
7 | /* ==========================================================================
8 | Typography
9 | ========================================================================== */
10 |
11 | @body-color: #666;
12 | @body-font-family: "Droid Serif", Georgia, "Times New Roman", Times, serif;
13 | @body-font-size: 14px;
14 | @body-accent-color: #000;
15 |
16 | @header-color: #111;
17 | @header-font-family: "Droid Serif", Georgia, "Times New Roman", Times, serif;
18 | @header-font-weight: 700;
19 |
20 | /* ==========================================================================
21 | Grid
22 | ========================================================================== */
23 |
24 | @fixed-column-width: 60px;
25 | @fixed-gutter-width: 20px;
26 | @fixed-columns: 12;
27 |
28 | @fluid-column-width: 4.3%;
29 | @fluid-gutter-width: 4.4%;
30 | @fluid-columns: 12;
31 |
32 | @mobile-break-width: 480px;
33 | @mobile-column-width: 20%;
34 | @mobile-gutter-width: 6.6666%;
35 | @mobile-columns: 4;
36 |
37 | /* ==========================================================================
38 | Buttons
39 | ========================================================================== */
40 |
41 | @button-color: #DDD;
42 | @button-primary-color: #0055CC;
43 | @button-info-color: #2F96B4;
44 | @button-success-color: #51A351;
45 | @button-warning-color: #FAA732;
46 | @button-danger-color: #BD362F;
47 |
--------------------------------------------------------------------------------
/styles/syntax.css:
--------------------------------------------------------------------------------
1 | .highlight { background: #ffffff; margin: 0 4px; font-size: 0.8em; }
2 | .highlight .c { color: #999988; font-style: italic } /* Comment */
3 | .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
4 | .highlight .k { font-weight: bold } /* Keyword */
5 | .highlight .o { font-weight: bold } /* Operator */
6 | .highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
7 | .highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
8 | .highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
9 | .highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
10 | .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
11 | .highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
12 | .highlight .ge { font-style: italic } /* Generic.Emph */
13 | .highlight .gr { color: #aa0000 } /* Generic.Error */
14 | .highlight .gh { color: #999999 } /* Generic.Heading */
15 | .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
16 | .highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
17 | .highlight .go { color: #888888 } /* Generic.Output */
18 | .highlight .gp { color: #555555 } /* Generic.Prompt */
19 | .highlight .gs { font-weight: bold } /* Generic.Strong */
20 | .highlight .gu { color: #aaaaaa } /* Generic.Subheading */
21 | .highlight .gt { color: #aa0000 } /* Generic.Traceback */
22 | .highlight .kc { font-weight: bold } /* Keyword.Constant */
23 | .highlight .kd { font-weight: bold } /* Keyword.Declaration */
24 | .highlight .kp { font-weight: bold } /* Keyword.Pseudo */
25 | .highlight .kr { font-weight: bold } /* Keyword.Reserved */
26 | .highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
27 | .highlight .m { color: #009999 } /* Literal.Number */
28 | .highlight .s { color: #d14 } /* Literal.String */
29 | .highlight .na { color: #008080 } /* Name.Attribute */
30 | .highlight .nb { color: #0086B3 } /* Name.Builtin */
31 | .highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
32 | .highlight .no { color: #008080 } /* Name.Constant */
33 | .highlight .ni { color: #800080 } /* Name.Entity */
34 | .highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
35 | .highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
36 | .highlight .nn { color: #555555 } /* Name.Namespace */
37 | .highlight .nt { color: #000080 } /* Name.Tag */
38 | .highlight .nv { color: #008080 } /* Name.Variable */
39 | .highlight .ow { font-weight: bold } /* Operator.Word */
40 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */
41 | .highlight .mf { color: #009999 } /* Literal.Number.Float */
42 | .highlight .mh { color: #009999 } /* Literal.Number.Hex */
43 | .highlight .mi { color: #009999 } /* Literal.Number.Integer */
44 | .highlight .mo { color: #009999 } /* Literal.Number.Oct */
45 | .highlight .sb { color: #d14 } /* Literal.String.Backtick */
46 | .highlight .sc { color: #d14 } /* Literal.String.Char */
47 | .highlight .sd { color: #d14 } /* Literal.String.Doc */
48 | .highlight .s2 { color: #d14 } /* Literal.String.Double */
49 | .highlight .se { color: #d14 } /* Literal.String.Escape */
50 | .highlight .sh { color: #d14 } /* Literal.String.Heredoc */
51 | .highlight .si { color: #d14 } /* Literal.String.Interpol */
52 | .highlight .sx { color: #d14 } /* Literal.String.Other */
53 | .highlight .sr { color: #009926 } /* Literal.String.Regex */
54 | .highlight .s1 { color: #d14 } /* Literal.String.Single */
55 | .highlight .ss { color: #990073 } /* Literal.String.Symbol */
56 | .highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
57 | .highlight .vc { color: #008080 } /* Name.Variable.Class */
58 | .highlight .vg { color: #008080 } /* Name.Variable.Global */
59 | .highlight .vi { color: #008080 } /* Name.Variable.Instance */
60 | .highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
--------------------------------------------------------------------------------