diff --git a/_posts/02-01-01-Code-Style-Guide.md b/_posts/02-01-01-Code-Style-Guide.md index f7a6d0c..099d09b 100644 --- a/_posts/02-01-01-Code-Style-Guide.md +++ b/_posts/02-01-01-Code-Style-Guide.md @@ -5,10 +5,10 @@ PHP developers to choose several of these and combine them into a single project (as close as possible) to a common code style to make it easy for developers to mix and match various libraries for their projects. -The [Framework Interop Group][fig] has proposed and approved a series of style recommendations, known as [PSR-0][psr0], -[PSR-1][psr1] and [PSR-2][psr2]. Don't let the funny names confuse you, these recommendations are merely -a set of rules that some projects like Drupal, Zend, Symfony, CakePHP, phpBB, AWS SDK, FuelPHP, Lithium, etc are starting -to adopt. You can use them for your own projects, or continue to use your own personal style. +The [Framework Interop Group][fig] has proposed and approved a series of style recommendations. Not all of them related +to code-style, but those that do are [PSR-0][psr0], [PSR-1][psr1], [PSR-2][psr2] and [PSR-4][psr4]. These recommendations +are merely a set of rules that some projects like Drupal, Zend, Symfony, CakePHP, phpBB, AWS SDK, FuelPHP, Lithium, +etc are starting to adopt. You can use them for your own projects, or continue to use your own personal style. Ideally you should write PHP code that adheres to a known standard. This could be any combination of PSR's, or one of the coding standards made by PEAR or Zend. This means other developers can easily read and work with your code, @@ -17,6 +17,7 @@ and applications that implement the components can have consistency even when wo * [Read about PSR-0][psr0] * [Read about PSR-1][psr1] * [Read about PSR-2][psr2] +* [Read about PSR-4][psr4] * [Read about PEAR Coding Standards][pear-cs] * [Read about Zend Coding Standards][zend-cs] * [Read about Symfony Coding Standards][symfony-cs] @@ -34,6 +35,7 @@ by all current and future parties who may be working on the codebase. [psr0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md [psr1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md [psr2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md +[psr4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md [pear-cs]: http://pear.php.net/manual/en/standards.php [zend-cs]: http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards [symfony-cs]: http://symfony.com/doc/current/contributing/code/standards.html diff --git a/_posts/03-03-01-Namespaces.md b/_posts/03-03-01-Namespaces.md index bc6eed8..23c7280 100644 --- a/_posts/03-03-01-Namespaces.md +++ b/_posts/03-03-01-Namespaces.md @@ -4,16 +4,30 @@ isChild: true ## Namespaces {#namespaces_title} -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. +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. +_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. +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. +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. + +In December 2013 the PHP-FIG created a new autoloading standard: [PSR-4][psr4], which one day will +probably replace PSR-0. Currently both are still usable, as PSR-4 requires PHP 5.3 and many PHP 5.2-only +projects currently implement PSR-0. If you're going to use an autoloader standard for a new application or +package then you almost certainly want to look into PSR-4. * [Read about Namespaces][namespaces] * [Read about PSR-0][psr0] +* [Read about PSR-4][psr4] [namespaces]: http://php.net/manual/en/language.namespaces.php [psr0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md +[psr4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md \ No newline at end of file diff --git a/_posts/04-02-01-Composer-and-Packagist.md b/_posts/04-02-01-Composer-and-Packagist.md index fc67e0b..0d45435 100644 --- a/_posts/04-02-01-Composer-and-Packagist.md +++ b/_posts/04-02-01-Composer-and-Packagist.md @@ -36,16 +36,18 @@ The path `$HOME/local/bin` (or a directory of your choice) should be in your `$P When you come across documentation that states to run Composer as `php composer.phar install`, you can substitute that with: composer install + +This section will assume you have installed composer globally. ### How to Define and Install Dependencies -Composer keeps track of your project's dependencies in a file called `composer.json`. You can manage it by hand if you like, or use Composer itself. The `php composer.phar require` command adds a project dependency and if you don't have a `composer.json` file, one will be created. Here's an example that adds [Twig][2] as a dependency of your project. Run it in your project's root directory where you've downloaded `composer.phar`: +Composer keeps track of your project's dependencies in a file called `composer.json`. You can manage it by hand if you like, or use Composer itself. The `composer require` command adds a project dependency and if you don't have a `composer.json` file, one will be created. Here's an example that adds [Twig][2] as a dependency of your project. - php composer.phar require twig/twig:~1.8 + composer require twig/twig:~1.8 -Alternatively the `php composer.phar init` command will guide you through creating a full `composer.json` file for your project. Either way, once you've created your `composer.json` file you can tell Composer to download and install your dependencies into the `vendors/` directory. This also applies to projects you've downloaded that already provide a `composer.json` file: +Alternatively the `composer init` command will guide you through creating a full `composer.json` file for your project. Either way, once you've created your `composer.json` file you can tell Composer to download and install your dependencies into the `vendors/` directory. This also applies to projects you've downloaded that already provide a `composer.json` file: - php composer.phar install + composer install Next, add this line to your application's primary PHP file; this will tell PHP to use Composer's autoloader for your project dependencies. @@ -62,14 +64,20 @@ Composer creates a file called `composer.lock` which stores the exact version of This is most useful when you define your version requirements flexibly. For instance a version requirement of ~1.8 means "anything newer than 1.8.0, but less than 2.0.x-dev". You can also use the `*` wildcard as in `1.8.*`. Now Composer's `php composer.phar update` command will upgrade all your dependencies to the newest version that fits the restrictions you define. +### Update Notifications + +To receive notifications about new version releases you can sign up for [VersionEye][3], a web service that can monitor +your GitHub and BitBucket accounts for `composer.json` files and send emails with new package releases. + ### Checking your dependencies for security issues -The [Security Advisories Checker][3] is a web service and a command-line tool, both will examine your `composer.lock` file and tell you if you need to update any of your dependencies. +The [Security Advisories Checker][4] is a web service and a command-line tool, both will examine your `composer.lock` file and tell you if you need to update any of your dependencies. -* [Learn about Composer][4] +* [Learn about Composer][5] [1]: http://packagist.org/ [2]: http://twig.sensiolabs.org -[3]: https://security.sensiolabs.org/ -[4]: http://getcomposer.org/doc/00-intro.md +[3]: https://www.versioneye.com/ +[4]: https://security.sensiolabs.org/ +[5]: http://getcomposer.org/doc/00-intro.md diff --git a/_posts/07-01-01-Databases.md b/_posts/07-01-01-Databases.md index 7f37417..17c5e51 100644 --- a/_posts/07-01-01-Databases.md +++ b/_posts/07-01-01-Databases.md @@ -69,10 +69,11 @@ one database system that another is missing from another by wrapping your querie This will of course add a little overhead, but if you are building a portable application that needs to work with MySQL, PostgreSQL and SQLite then a little overhead will be worth it the sake of code cleanliness. -Some abstraction layers have been built using the PSR-0 namespace standard so can be installed in any application you like: +Some abstraction layers have been built using the [PSR-0][psr0] or [PSR-4][psr4] namespace standards so can be installed in any application you like: * [Aura SQL][6] * [Doctrine2 DBAL][2] +* [Propel][7] * [ZF2 Db][4] * [ZF1 Db][3] @@ -82,7 +83,10 @@ Some abstraction layers have been built using the PSR-0 namespace standard so ca [4]: http://packages.zendframework.com/docs/latest/manual/en/index.html#zend-db [5]: http://php.net/manual/en/pdo.connections.php [6]: https://github.com/auraphp/Aura.Sql +[7]: http://propelorm.org/Propel/ [mysql]: http://php.net/mysql [mysqli]: http://php.net/mysqli [pgsql]: http://php.net/pgsql +[psr0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md +[psr4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md diff --git a/_posts/13-01-01-Resources.md b/_posts/13-01-01-Resources.md index 9466aa5..61c42fe 100644 --- a/_posts/13-01-01-Resources.md +++ b/_posts/13-01-01-Resources.md @@ -29,7 +29,7 @@ (PHP support is undocumented but based on stable Facebook partnership [link](http://net.tutsplus.com/tutorials/php/quick-tip-deploy-php-to-heroku-in-seconds/)) * [fortrabbit](http://fortrabbit.com/) * [Engine Yard Cloud](https://www.engineyard.com/products/cloud) -* [Red Hat OpenShift Platform](http://www.redhat.com/products/cloud-computing/openshift/) +* [Red Hat OpenShift Platform](http://openshift.com) * [dotCloud](http://docs.dotcloud.com/services/php/) * [AWS Elastic Beanstalk](http://aws.amazon.com/elasticbeanstalk/) * [cloudControl](https://www.cloudcontrol.com/)