From 27b2e3a20b984197b1bac6db6136092e7a21ee8b Mon Sep 17 00:00:00 2001 From: David Pennington Date: Mon, 9 Jul 2012 15:15:32 -0500 Subject: [PATCH 1/6] Added the MicroMVC micro framework. --- _includes/libraries-and-frameworks.md | 1 + 1 file changed, 1 insertion(+) diff --git a/_includes/libraries-and-frameworks.md b/_includes/libraries-and-frameworks.md index ba32489..33d168d 100644 --- a/_includes/libraries-and-frameworks.md +++ b/_includes/libraries-and-frameworks.md @@ -22,6 +22,7 @@ _You do not need to use a framework for every project_. Sometimes, plain PHP is * [Fat-Free](http://bcosca.github.com/fatfree/) * [Limonade](http://limonade-php.github.com/) +* [MicroMVC](http://micromvc.com/) * [Silex](http://silex.sensiolabs.org/) * [Slim](http://www.slimframework.com/) From d7083f0007a65236d0ebd5f924ab5746656032c6 Mon Sep 17 00:00:00 2001 From: Evan O'Connell Date: Mon, 9 Jul 2012 20:11:22 -0400 Subject: [PATCH 2/6] Internal links only work from the index page. --- _includes/welcome.md | 2 +- _layouts/default.html | 54 +++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/_includes/welcome.md b/_includes/welcome.md index 4a21102..63e6050 100644 --- a/_includes/welcome.md +++ b/_includes/welcome.md @@ -22,4 +22,4 @@ developers know where to find good information! [Back to Top](#top){.top} [1]: https://github.com/codeguy/php-the-right-way/tree/gh-pages -[2]: http://www.phptherightway.com/banners.html +[2]: /banners.html diff --git a/_layouts/default.html b/_layouts/default.html index 15d6ad3..0e67d8e 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -30,48 +30,48 @@
From 9506472e34278fd4fcc7d4e8746032eb9364a209 Mon Sep 17 00:00:00 2001 From: Cory Fowler Date: Mon, 9 Jul 2012 17:12:39 -0700 Subject: [PATCH 3/6] Added Windows Azure to list of PHP PaaS Providers --- _includes/resources.md | 1 + 1 file changed, 1 insertion(+) diff --git a/_includes/resources.md b/_includes/resources.md index 98fd09e..544fd5b 100644 --- a/_includes/resources.md +++ b/_includes/resources.md @@ -22,5 +22,6 @@ * [dotCloud](http://docs.dotcloud.com/services/php/) * [AWS Elastic Beanstalk](http://aws.amazon.com/elasticbeanstalk/) * [cloudControl](https://www.cloudcontrol.com/) +* [Windows Azure](http://www.windowsazure.com/) [Back to Top](#top){.top} From 320be779116f8cc40362b58380d094b8d1da313e Mon Sep 17 00:00:00 2001 From: Kris Jordan Date: Mon, 9 Jul 2012 20:21:06 -0400 Subject: [PATCH 4/6] Restructure includes to posts --- .../01-01-01-Getting-Started.md | 0 .../02-01-01-Code-Style-Guide.md | 0 .../03-01-01-Language-Highlights.md | 0 .../04-01-01-Dependency-Management.md | 0 .../05-01-01-Databases-and-PDO.md | 0 .../06-01-01-Security.md | 0 .../testing.md => _posts/07-01-01-Testing.md | 0 .../08-01-01-Servers-and-Deployment.md | 0 .../09-01-01-Libraries-and-Frameworks.md | 0 .../10-01-01-Resources.md | 0 index.html | 32 ++----------------- 11 files changed, 3 insertions(+), 29 deletions(-) rename _includes/getting-started.md => _posts/01-01-01-Getting-Started.md (100%) rename _includes/code-style-guide.md => _posts/02-01-01-Code-Style-Guide.md (100%) rename _includes/language-highlights.md => _posts/03-01-01-Language-Highlights.md (100%) rename _includes/dependency-management.md => _posts/04-01-01-Dependency-Management.md (100%) rename _includes/databases.md => _posts/05-01-01-Databases-and-PDO.md (100%) rename _includes/security.md => _posts/06-01-01-Security.md (100%) rename _includes/testing.md => _posts/07-01-01-Testing.md (100%) rename _includes/servers-and-deployment.md => _posts/08-01-01-Servers-and-Deployment.md (100%) rename _includes/libraries-and-frameworks.md => _posts/09-01-01-Libraries-and-Frameworks.md (100%) rename _includes/resources.md => _posts/10-01-01-Resources.md (100%) diff --git a/_includes/getting-started.md b/_posts/01-01-01-Getting-Started.md similarity index 100% rename from _includes/getting-started.md rename to _posts/01-01-01-Getting-Started.md diff --git a/_includes/code-style-guide.md b/_posts/02-01-01-Code-Style-Guide.md similarity index 100% rename from _includes/code-style-guide.md rename to _posts/02-01-01-Code-Style-Guide.md diff --git a/_includes/language-highlights.md b/_posts/03-01-01-Language-Highlights.md similarity index 100% rename from _includes/language-highlights.md rename to _posts/03-01-01-Language-Highlights.md diff --git a/_includes/dependency-management.md b/_posts/04-01-01-Dependency-Management.md similarity index 100% rename from _includes/dependency-management.md rename to _posts/04-01-01-Dependency-Management.md diff --git a/_includes/databases.md b/_posts/05-01-01-Databases-and-PDO.md similarity index 100% rename from _includes/databases.md rename to _posts/05-01-01-Databases-and-PDO.md diff --git a/_includes/security.md b/_posts/06-01-01-Security.md similarity index 100% rename from _includes/security.md rename to _posts/06-01-01-Security.md diff --git a/_includes/testing.md b/_posts/07-01-01-Testing.md similarity index 100% rename from _includes/testing.md rename to _posts/07-01-01-Testing.md diff --git a/_includes/servers-and-deployment.md b/_posts/08-01-01-Servers-and-Deployment.md similarity index 100% rename from _includes/servers-and-deployment.md rename to _posts/08-01-01-Servers-and-Deployment.md diff --git a/_includes/libraries-and-frameworks.md b/_posts/09-01-01-Libraries-and-Frameworks.md similarity index 100% rename from _includes/libraries-and-frameworks.md rename to _posts/09-01-01-Libraries-and-Frameworks.md diff --git a/_includes/resources.md b/_posts/10-01-01-Resources.md similarity index 100% rename from _includes/resources.md rename to _posts/10-01-01-Resources.md diff --git a/index.html b/index.html index 1bf79e0..d107b22 100644 --- a/index.html +++ b/index.html @@ -5,32 +5,6 @@ layout: default {% capture welcome_content %}{% include welcome.md %}{% endcapture %} {{ welcome_content|markdownify }} -{% capture getting_started_content %}{% include getting-started.md %}{% endcapture %} -{{ getting_started_content|markdownify }} - -{% capture codestyleguide_content %}{% include code-style-guide.md %}{% endcapture %} -{{ codestyleguide_content|markdownify }} - -{% capture highlights_content %}{% include language-highlights.md %}{% endcapture %} -{{ highlights_content|markdownify }} - -{% capture dependencies_content %}{% include dependency-management.md %}{% endcapture %} -{{ dependencies_content|markdownify }} - -{% capture databases_content %}{% include databases.md %}{% endcapture %} -{{ databases_content|markdownify }} - -{% capture security_content %}{% include security.md %}{% endcapture %} -{{ security_content|markdownify }} - -{% capture testing_content %}{% include testing.md %}{% endcapture %} -{{ testing_content|markdownify }} - -{% capture servers_and_deployment_content %}{% include servers-and-deployment.md %}{% endcapture %} -{{ servers_and_deployment_content|markdownify }} - -{% capture frameworks_content %}{% include libraries-and-frameworks.md %}{% endcapture %} -{{ frameworks_content|markdownify }} - -{% capture resources_content %}{% include resources.md %}{% endcapture %} -{{ resources_content|markdownify }} +{% for post in site.posts reversed %} + {{ post.content }} +{% endfor %} From dc1857b8fa035cf3d524557c02eb60b591910095 Mon Sep 17 00:00:00 2001 From: Kris Jordan Date: Tue, 10 Jul 2012 00:33:25 -0400 Subject: [PATCH 5/6] Moving to Post structure. Lots of changes breaking out subsections into posts and programmatically generating ToC, main page content, and Back to Top links. --- _layouts/default.html | 48 ++------- _posts/01-01-01-Getting-Started.md | 37 ------- ...01-02-01-Use-the-Current-Stable-Version.md | 10 ++ _posts/01-03-01-Built-in-Web-Server.md | 14 +++ _posts/01-04-01-Mac-Setup.md | 13 +++ _posts/01-05-01-Windows-Setup.md | 13 +++ _posts/03-01-01-Language-Highlights.md | 98 ------------------- _posts/03-02-01-Programming-Paradigms.md | 30 ++++++ _posts/03-03-01-Namespaces.md | 19 ++++ _posts/03-04-01-Standard-PHP-Library.md | 12 +++ _posts/03-05-01-Command-Line-Interface.md | 50 ++++++++++ _posts/04-01-01-Dependency-Management.md | 75 -------------- _posts/04-02-01-Composer-and-Packagist.md | 70 +++++++++++++ _posts/04-03-01-PEAR.md | 9 ++ _posts/05-01-01-Databases-and-PDO.md | 2 - _posts/06-01-01-Security.md | 42 -------- _posts/06-02-01-Web-Application-Security.md | 13 +++ .../06-03-01-Password-Hashing-with-Bcrypt.md | 19 ++++ ...06-04-01-Input-Filtering-and-Sanitizing.md | 17 ++++ _posts/07-01-01-Testing.md | 2 - _posts/08-01-01-Servers-and-Deployment.md | 26 ----- _posts/08-02-01-Platform-as-a-Service.md | 8 ++ .../08-03-01-Virtual-or-Dedicated-Servers.md | 19 ++++ _posts/08-04-01-Shared-Servers.md | 7 ++ _posts/09-01-01-Libraries-and-Frameworks.md | 1 - _posts/10-01-01-Resources.md | 2 - index.html | 5 + 27 files changed, 335 insertions(+), 326 deletions(-) create mode 100644 _posts/01-02-01-Use-the-Current-Stable-Version.md create mode 100644 _posts/01-03-01-Built-in-Web-Server.md create mode 100644 _posts/01-04-01-Mac-Setup.md create mode 100644 _posts/01-05-01-Windows-Setup.md create mode 100644 _posts/03-02-01-Programming-Paradigms.md create mode 100644 _posts/03-03-01-Namespaces.md create mode 100644 _posts/03-04-01-Standard-PHP-Library.md create mode 100644 _posts/03-05-01-Command-Line-Interface.md create mode 100644 _posts/04-02-01-Composer-and-Packagist.md create mode 100644 _posts/04-03-01-PEAR.md create mode 100644 _posts/06-02-01-Web-Application-Security.md create mode 100644 _posts/06-03-01-Password-Hashing-with-Bcrypt.md create mode 100644 _posts/06-04-01-Input-Filtering-and-Sanitizing.md create mode 100644 _posts/08-02-01-Platform-as-a-Service.md create mode 100644 _posts/08-03-01-Virtual-or-Dedicated-Servers.md create mode 100644 _posts/08-04-01-Shared-Servers.md diff --git a/_layouts/default.html b/_layouts/default.html index 0e67d8e..5c83b5e 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -31,47 +31,13 @@
Last Updated: {{ site.time }}
diff --git a/_posts/01-01-01-Getting-Started.md b/_posts/01-01-01-Getting-Started.md index 741b7e8..31dd91e 100644 --- a/_posts/01-01-01-Getting-Started.md +++ b/_posts/01-01-01-Getting-Started.md @@ -1,39 +1,2 @@ # Getting Started -## Use the Current Stable Version (5.4) - -If you are just getting started with PHP make sure to start with the current stable release of [PHP 5.4][php-release]. PHP has made great strides adding powerful [new features](#language_highlights) over the last few years. Don't let the minor version number difference between 5.2 and 5.4 fool you, it represents _major_ improvements. - -## Built-in web server - -You can start learning PHP without the hassle of installing and configuring a full-fledged web server (PHP 5.4 required). To start the server, run the following from your terminal in your project's web root: - - > php -S localhost:8000 - -* [Learn about the built-in, command line web server][cli-server] - -[php-release]: http://www.php.net/downloads.php -[cli-server]: http://www.php.net/manual/en/features.commandline.webserver.php - -## Mac Setup - -OS X comes prepackaged with PHP. As of Mountain Lion, it is _not_ the current stable version of PHP, though. You can get the PHP executable through a number of Mac [package managers][mac-package-managers] or [compile it yourself][mac-compile] (if compiling, be sure to have Xcode installed, or Apple's substitute ["Command Line Tools for Xcode" downloadable from Apple's Mac Developer Center][apple-developer]). For a complete Apache, MySQL, and PHP installation check out [MAMP2][mamp-downloads]. - -[mac-package-managers]: http://www.php.net/manual/en/install.macosx.packages.php -[mac-compile]: http://www.php.net/manual/en/install.macosx.compile.php -[xcode-gcc-substitution]: https://github.com/kennethreitz/osx-gcc-installer -[apple-developer]: https://developer.apple.com/downloads -[mamp-downloads]: http://www.mamp.info/en/downloads/index.html - -## Windows Setup - -You can install PHP on windows from an install executable found on the official [PHP Downloads][php-downloads] page. For a complete Apache, MySQL, and PHP installation check out [WAMP][wamp-installer]. - -* [Read more about the official PHP Windows Installer][windows-installer] - -[php-downloads]: http://www.php.net/downloads.php -[windows-installer]: http://www.php.net/manual/en/install.windows.installer.msi.php -[wamp-installer]: http://www.wampserver.com/ - - -[Back to Top](#top){.top} diff --git a/_posts/01-02-01-Use-the-Current-Stable-Version.md b/_posts/01-02-01-Use-the-Current-Stable-Version.md new file mode 100644 index 0000000..6dbaaca --- /dev/null +++ b/_posts/01-02-01-Use-the-Current-Stable-Version.md @@ -0,0 +1,10 @@ +--- +title: Use the Current Stable Version (5.4) +isChild: true +--- + +## Use the Current Stable Version (5.4) + +If you are just getting started with PHP make sure to start with the current stable release of [PHP 5.4][php-release]. PHP has made great strides adding powerful [new features](#language_highlights) over the last few years. Don't let the minor version number difference between 5.2 and 5.4 fool you, it represents _major_ improvements. + +[php-release]: http://www.php.net/downloads.php diff --git a/_posts/01-03-01-Built-in-Web-Server.md b/_posts/01-03-01-Built-in-Web-Server.md new file mode 100644 index 0000000..aa46c77 --- /dev/null +++ b/_posts/01-03-01-Built-in-Web-Server.md @@ -0,0 +1,14 @@ +--- +title: Built-in Web Server +isChild: true +--- + +## Built-in web server + +You can start learning PHP without the hassle of installing and configuring a full-fledged web server (PHP 5.4 required). To start the server, run the following from your terminal in your project's web root: + + > php -S localhost:8000 + +* [Learn about the built-in, command line web server][cli-server] + +[cli-server]: http://www.php.net/manual/en/features.commandline.webserver.php diff --git a/_posts/01-04-01-Mac-Setup.md b/_posts/01-04-01-Mac-Setup.md new file mode 100644 index 0000000..e787667 --- /dev/null +++ b/_posts/01-04-01-Mac-Setup.md @@ -0,0 +1,13 @@ +--- +isChild: true +--- + +## Mac Setup + +OS X comes prepackaged with PHP. As of Mountain Lion, it is _not_ the current stable version of PHP, though. You can get the PHP executable through a number of Mac [package managers][mac-package-managers] or [compile it yourself][mac-compile] (if compiling, be sure to have Xcode installed, or Apple's substitute ["Command Line Tools for Xcode" downloadable from Apple's Mac Developer Center][apple-developer]). For a complete Apache, MySQL, and PHP installation check out [MAMP2][mamp-downloads]. + +[mac-package-managers]: http://www.php.net/manual/en/install.macosx.packages.php +[mac-compile]: http://www.php.net/manual/en/install.macosx.compile.php +[xcode-gcc-substitution]: https://github.com/kennethreitz/osx-gcc-installer +[apple-developer]: https://developer.apple.com/downloads +[mamp-downloads]: http://www.mamp.info/en/downloads/index.html diff --git a/_posts/01-05-01-Windows-Setup.md b/_posts/01-05-01-Windows-Setup.md new file mode 100644 index 0000000..231d899 --- /dev/null +++ b/_posts/01-05-01-Windows-Setup.md @@ -0,0 +1,13 @@ +--- +isChild: true +--- + +## Windows Setup + +You can install PHP on windows from an install executable found on the official [PHP Downloads][php-downloads] page. For a complete Apache, MySQL, and PHP installation check out [WAMP][wamp-installer]. + +* [Read more about the official PHP Windows Installer][windows-installer] + +[php-downloads]: http://www.php.net/downloads.php +[windows-installer]: http://www.php.net/manual/en/install.windows.installer.msi.php +[wamp-installer]: http://www.wampserver.com/ diff --git a/_posts/03-01-01-Language-Highlights.md b/_posts/03-01-01-Language-Highlights.md index b0a86a8..7f662a6 100644 --- a/_posts/03-01-01-Language-Highlights.md +++ b/_posts/03-01-01-Language-Highlights.md @@ -1,99 +1 @@ # Language Highlights - -## Programming Paradigms - -PHP is a flexible, dynamic language that supports a variety of programming techniques. It has evolved dramatically over the years, notably adding a solid object-oriented model in PHP 5.0 (2004), anonymous functions and namespaces in PHP 5.3 (2009), and traits in PHP 5.4 (2012). - -### Object-oriented Programming - -* [Read about Object-oriented PHP][oop] -* [Read about Traits][traits] - -### Functional Programming - -* [Read about Anonymous functions][anonymous-functions] -* [Read about dynamically invoking functions with `call_user_func_array`][call-user-func-array] - -### Meta Programming - -* [Read about Magic Methods][magic-methods] -* [Read about Reflection][reflection] - -## Namespaces - -As mentioned above, the PHP community has a lot of developers creating lots of code. This means that one library's PHP code may use the same class name as another library. When both libraries are used in the same namespace, they collide and cause trouble. - -_Namespaces_ solve this problem. As described in the PHP reference manual, namespaces may be compared to operating system directories that _namespace_ files; two files with the same name may co-exist in separate directories. Likewise, two PHP classes with the same name may co-exist in separate PHP namespaces. It's as simple as that. - -It is important for you to namespace your code so that it may be used by other developers without fear of colliding with other libraries. - -One recommended way to use namespaces is outlined in [PSR-0](psr0), which aims to provide a standard file, class and namespace convention to allow plug-and-play code. - -* [Read about Namespaces][namespaces] -* [Read about PSR-0][psr0] - - -## Standard PHP Library - -The Standard PHP Library (SPL) is packaged with PHP and provides a collection of classes and interfaces. It is made up primarily of commonly needed datastructure classes (stack, queue, heap, and so on), and iterators which can traverse over these datastructures or your own classes which implement SPL interfaces. - -* [Read about the SPL][spl] - -## Command Line Interface - -PHP was created primarily to write web applications, but it's also useful for scripting command line interface (CLI) programs, too. Command line PHP programs can help you automate common tasks like testing, deployment, and application administrativia. - -CLI PHP programs are powerful because you can use your app's code directly without having to create and secure a web GUI for it. Just be sure not to put your CLI PHP scripts in your public web root! - -Try running PHP from your command line: - -{% highlight bash %} - > php -i -{% endhighlight %} - -The `-i` option will print your PHP configuration just like the [`phpinfo`][phpinfo] function. There are a number of other useful [command line options][cli-options], too. - -Let's write a simple "Hello, $name" CLI program. To try it out, create a file named `hello.php`, as below. - -{% highlight php %} - php hello.php - Usage: php hello.php [name] - > php hello.php world - Hello, world -{% endhighlight %} - - - * [Learn about running PHP from the command line][php-cli] - * [Learn about setting up Windows to run PHP from the command line][php-cli-windows] - -[Back to Top](#top){.top} - -[namespaces]: http://php.net/manual/en/language.namespaces.php -[psr0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md -[oop]: http://www.php.net/manual/en/language.oop5.php -[spl]: http://php.net/manual/en/book.spl.php -[anonymous-functions]: http://www.php.net/manual/en/functions.anonymous.php -[magic-methods]: http://php.net/manual/en/language.oop5.magic.php -[reflection]: http://www.php.net/manual/en/intro.reflection.php -[traits]: http://www.php.net/traits -[call-user-func-array]: http://php.net/manual/en/function.call-user-func-array.php - -[phpinfo]: http://php.net/manual/en/function.phpinfo.php -[cli-options]: http://www.php.net/manual/en/features.commandline.options.php -[argc]: http://php.net/manual/en/reserved.variables.argc.php -[argv]: http://php.net/manual/en/reserved.variables.argv.php -[php-cli]: http://php.net/manual/en/features.commandline.php -[php-cli-windows]: http://www.php.net/manual/en/install.windows.commandline.php diff --git a/_posts/03-02-01-Programming-Paradigms.md b/_posts/03-02-01-Programming-Paradigms.md new file mode 100644 index 0000000..e8a39e6 --- /dev/null +++ b/_posts/03-02-01-Programming-Paradigms.md @@ -0,0 +1,30 @@ +--- +isChild: true +--- + +## Programming Paradigms + +PHP is a flexible, dynamic language that supports a variety of programming techniques. It has evolved dramatically over the years, notably adding a solid object-oriented model in PHP 5.0 (2004), anonymous functions and namespaces in PHP 5.3 (2009), and traits in PHP 5.4 (2012). + +### Object-oriented Programming + +* [Read about Object-oriented PHP][oop] +* [Read about Traits][traits] + +### Functional Programming + +* [Read about Anonymous functions][anonymous-functions] +* [Read about dynamically invoking functions with `call_user_func_array`][call-user-func-array] + +### Meta Programming + +* [Read about Magic Methods][magic-methods] +* [Read about Reflection][reflection] + +[namespaces]: http://php.net/manual/en/language.namespaces.php +[oop]: http://www.php.net/manual/en/language.oop5.php +[anonymous-functions]: http://www.php.net/manual/en/functions.anonymous.php +[magic-methods]: http://php.net/manual/en/language.oop5.magic.php +[reflection]: http://www.php.net/manual/en/intro.reflection.php +[traits]: http://www.php.net/traits +[call-user-func-array]: http://php.net/manual/en/function.call-user-func-array.php diff --git a/_posts/03-03-01-Namespaces.md b/_posts/03-03-01-Namespaces.md new file mode 100644 index 0000000..086512e --- /dev/null +++ b/_posts/03-03-01-Namespaces.md @@ -0,0 +1,19 @@ +--- +isChild: true +--- + +## Namespaces + +As mentioned above, the PHP community has a lot of developers creating lots of code. This means that one library's PHP code may use the same class name as another library. When both libraries are used in the same namespace, they collide and cause trouble. + +_Namespaces_ solve this problem. As described in the PHP reference manual, namespaces may be compared to operating system directories that _namespace_ files; two files with the same name may co-exist in separate directories. Likewise, two PHP classes with the same name may co-exist in separate PHP namespaces. It's as simple as that. + +It is important for you to namespace your code so that it may be used by other developers without fear of colliding with other libraries. + +One recommended way to use namespaces is outlined in [PSR-0](psr0), which aims to provide a standard file, class and namespace convention to allow plug-and-play code. + +* [Read about Namespaces][namespaces] +* [Read about PSR-0][psr0] + +[namespaces]: http://php.net/manual/en/language.namespaces.php +[psr0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md diff --git a/_posts/03-04-01-Standard-PHP-Library.md b/_posts/03-04-01-Standard-PHP-Library.md new file mode 100644 index 0000000..22f6a71 --- /dev/null +++ b/_posts/03-04-01-Standard-PHP-Library.md @@ -0,0 +1,12 @@ +--- +title: Standard PHP Library +isChild: true +--- + +## Standard PHP Library + +The Standard PHP Library (SPL) is packaged with PHP and provides a collection of classes and interfaces. It is made up primarily of commonly needed datastructure classes (stack, queue, heap, and so on), and iterators which can traverse over these datastructures or your own classes which implement SPL interfaces. + +* [Read about the SPL][spl] + +[spl]: http://php.net/manual/en/book.spl.php diff --git a/_posts/03-05-01-Command-Line-Interface.md b/_posts/03-05-01-Command-Line-Interface.md new file mode 100644 index 0000000..775941d --- /dev/null +++ b/_posts/03-05-01-Command-Line-Interface.md @@ -0,0 +1,50 @@ +--- +isChild: true +--- + +## Command Line Interface + +PHP was created primarily to write web applications, but it's also useful for scripting command line interface (CLI) programs, too. Command line PHP programs can help you automate common tasks like testing, deployment, and application administrativia. + +CLI PHP programs are powerful because you can use your app's code directly without having to create and secure a web GUI for it. Just be sure not to put your CLI PHP scripts in your public web root! + +Try running PHP from your command line: + +{% highlight bash %} + > php -i +{% endhighlight %} + +The `-i` option will print your PHP configuration just like the [`phpinfo`][phpinfo] function. There are a number of other useful [command line options][cli-options], too. + +Let's write a simple "Hello, $name" CLI program. To try it out, create a file named `hello.php`, as below. + +{% highlight php %} + php hello.php + Usage: php hello.php [name] + > php hello.php world + Hello, world +{% endhighlight %} + + + * [Learn about running PHP from the command line][php-cli] + * [Learn about setting up Windows to run PHP from the command line][php-cli-windows] + +[phpinfo]: http://php.net/manual/en/function.phpinfo.php +[cli-options]: http://www.php.net/manual/en/features.commandline.options.php +[argc]: http://php.net/manual/en/reserved.variables.argc.php +[argv]: http://php.net/manual/en/reserved.variables.argv.php +[php-cli]: http://php.net/manual/en/features.commandline.php +[php-cli-windows]: http://www.php.net/manual/en/install.windows.commandline.php diff --git a/_posts/04-01-01-Dependency-Management.md b/_posts/04-01-01-Dependency-Management.md index bd67b65..46f0d9e 100644 --- a/_posts/04-01-01-Dependency-Management.md +++ b/_posts/04-01-01-Dependency-Management.md @@ -1,78 +1,3 @@ # Dependency Management There are a ton of PHP libraries, frameworks, and components to choose from. Your project will likely use several of them — these are project dependencies. Until recently, PHP did not have a good way to manage these project dependencies. Even if you managed them manually, you still had to worry about autoloaders. No more. - -## Composer and Packagist - -Composer is a **brilliant** dependency manager for PHP. List your project's dependencies in a `composer.json` file and, with a few simple commands, Composer will automatically download your project's dependencies and setup autoloading for you. - -There are already a lot of PHP libraries that are compatible with Composer, ready to be used in your project. These "packages" are listed on [Packagist][1], the official repository for Composer-compatible PHP libraries. - -### How to Install Composer - -You can install Composer locally (in your current working directory; though this is no longer recommended) or globally (e.g. /usr/local/bin). Let's assume you want to install Composer locally. From your project's root directory: - - > curl -s http://getcomposer.org/installer | php - -This will download `composer.phar` (a PHP binary archive). You can run this with `php` to manage your project dependencies. Please Note: If you pipe downloaded code directly into an interpreter, please read the code online first to confirm it is safe. - -### How to Install Composer (manually) - -Manually installing composer is an advanced technique; however, there are various reasons why a developer might prefer this method vs. using the interactive installation routine. The interactive installation checks your PHP installation to ensure that: - -- a sufficient version of PHP is being used -- `.phar` files can be executed correctly -- certain directory permissions are sufficient -- certain problematic extensions are not loaded -- certain `php.ini` settings are set - -Since a manual installation performs none of these checks, you have to decide whether the trade-off is worth it for you. As such, below is how to obtain Composer manually: - - > curl -s http://getcomposer.org/composer.phar -o $HOME/local/bin/composer ; chmod +x $HOME/local/bin/composer - -`$HOME/local/bin` (or a directory of your choice) should be in your `$PATH` environment variable. This will result in a `composer` command being available. - -When you come across documentation that states to run Composer as `php composer.phar install`, you can substitute that with: - - > composer install - -### How to Define and Install Dependencies - -First, create a `composer.json` file in the same directory as `composer.phar`. Here's an example that lists [Twig][2] as a project dependency. - -{% highlight json %} - { - "require": { - "twig/twig": ">=1.8.0,<2.0-dev" - } - } -{% endhighlight %} - -Next, run this command from your project root directory. - -{% highlight bash %} - > php composer.phar install -{% endhighlight %} - -This will download and install the project dependencies into a `vendors/` directory. Next, add this line to your application's primary PHP file; this will tell PHP to use Composer's autoloader for your project dependencies. - -{% highlight php %} - curl -s http://getcomposer.org/installer | php + +This will download `composer.phar` (a PHP binary archive). You can run this with `php` to manage your project dependencies. Please Note: If you pipe downloaded code directly into an interpreter, please read the code online first to confirm it is safe. + +### How to Install Composer (manually) + +Manually installing composer is an advanced technique; however, there are various reasons why a developer might prefer this method vs. using the interactive installation routine. The interactive installation checks your PHP installation to ensure that: + +- a sufficient version of PHP is being used +- `.phar` files can be executed correctly +- certain directory permissions are sufficient +- certain problematic extensions are not loaded +- certain `php.ini` settings are set + +Since a manual installation performs none of these checks, you have to decide whether the trade-off is worth it for you. As such, below is how to obtain Composer manually: + + > curl -s http://getcomposer.org/composer.phar -o $HOME/local/bin/composer ; chmod +x $HOME/local/bin/composer + +`$HOME/local/bin` (or a directory of your choice) should be in your `$PATH` environment variable. This will result in a `composer` command being available. + +When you come across documentation that states to run Composer as `php composer.phar install`, you can substitute that with: + + > composer install + +### How to Define and Install Dependencies + +First, create a `composer.json` file in the same directory as `composer.phar`. Here's an example that lists [Twig][2] as a project dependency. + +{% highlight json %} + { + "require": { + "twig/twig": ">=1.8.0,<2.0-dev" + } + } +{% endhighlight %} + +Next, run this command from your project root directory. + +{% highlight bash %} + > php composer.phar install +{% endhighlight %} + +This will download and install the project dependencies into a `vendors/` directory. Next, add this line to your application's primary PHP file; this will tell PHP to use Composer's autoloader for your project dependencies. + +{% highlight php %} + Date: Tue, 10 Jul 2012 12:55:12 +0300 Subject: [PATCH 6/6] Added Entropy package, which is better at path navigation --- _posts/01-04-01-Mac-Setup.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/_posts/01-04-01-Mac-Setup.md b/_posts/01-04-01-Mac-Setup.md index e787667..740fca9 100644 --- a/_posts/01-04-01-Mac-Setup.md +++ b/_posts/01-04-01-Mac-Setup.md @@ -4,10 +4,13 @@ isChild: true ## Mac Setup -OS X comes prepackaged with PHP. As of Mountain Lion, it is _not_ the current stable version of PHP, though. You can get the PHP executable through a number of Mac [package managers][mac-package-managers] or [compile it yourself][mac-compile] (if compiling, be sure to have Xcode installed, or Apple's substitute ["Command Line Tools for Xcode" downloadable from Apple's Mac Developer Center][apple-developer]). For a complete Apache, MySQL, and PHP installation check out [MAMP2][mamp-downloads]. +OS X comes prepackaged with PHP. As of Mountain Lion, it is _not_ the current stable version of PHP, though. +You can get the PHP executable through a number of Mac [package managers][mac-package-managers] or [compile it yourself][mac-compile] (if compiling, be sure to have Xcode installed, or Apple's substitute ["Command Line Tools for Xcode" downloadable from Apple's Mac Developer Center][apple-developer]). +For a complete LAMP package with GUI try [MAMP2][mamp-downloads], otherwise consider [Entropy 5.4 package][entropy-downloads]. [mac-package-managers]: http://www.php.net/manual/en/install.macosx.packages.php [mac-compile]: http://www.php.net/manual/en/install.macosx.compile.php [xcode-gcc-substitution]: https://github.com/kennethreitz/osx-gcc-installer [apple-developer]: https://developer.apple.com/downloads [mamp-downloads]: http://www.mamp.info/en/downloads/index.html +[entropy-downloads]: http://php-osx.liip.ch/ \ No newline at end of file