diff --git a/_posts/04-01-01-Dependency-Management.md b/_posts/04-01-01-Dependency-Management.md index 19eeb0e..d892a95 100644 --- a/_posts/04-01-01-Dependency-Management.md +++ b/_posts/04-01-01-Dependency-Management.md @@ -4,16 +4,14 @@ anchor: dependency_management # Dependency Management {#dependency_management_title} -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. +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. +That is no longer an issue. -Currently there are two major package management systems for PHP - Composer and PEAR. Which one is right for you? The -answer is both. +Currently there are two major package management systems for PHP - [Composer] and [PEAR]. Composer is +the main package manager to use for PHP, however for a long time PEAR used to fill that role. Knowing what +PEAR is will be a good idea as you may still find references to it, even if you never use it. -* Use **Composer** when managing dependencies for a single project. -* Use **PEAR** when managing dependencies for PHP as a whole on your system. - -In general, Composer packages will be available only in the projects that you explicitly specify whereas a PEAR package -would be available to all of your PHP projects. While PEAR might sound like the easier approach at first glance, there -are advantages to using a project-by-project approach to your dependencies. +[Composer]: /#composer_and_packagist +[PEAR]: /#pear \ 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 77b8245..f1f2e4f 100644 --- a/_posts/04-02-01-Composer-and-Packagist.md +++ b/_posts/04-02-01-Composer-and-Packagist.md @@ -10,7 +10,7 @@ with a few simple commands, Composer will automatically download your project's 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. +"packages" are listed on [Packagist], the official repository for Composer-compatible PHP libraries. ### How to Install Composer @@ -27,14 +27,16 @@ dependencies. code online first to confirm it is safe. #### Installing on Windows -For Windows users the easiest way to get up and running is to use the [ComposerSetup][6] installer, which performs a -global install and sets up your `$PATH` so that you can just call `composer` from any directory in your command line. + +For Windows users the easiest way to get up and running is to use the [ComposerSetup] installer, which +performs a global install and sets up your `$PATH` so that you can just call `composer` from any +directory in your command line. ### 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: +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 @@ -42,19 +44,19 @@ to ensure that: - 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: +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: {% highlight console %} curl -s https://getcomposer.org/composer.phar -o $HOME/local/bin/composer chmod +x $HOME/local/bin/composer {% endhighlight %} -The path `$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. +The path `$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: +When you come across documentation that states to run Composer as `php composer.phar install`, you can +substitute that with: {% highlight console %} composer install @@ -64,25 +66,26 @@ 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 `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. +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] +as a dependency of your project. {% highlight console %} composer require twig/twig:~1.8 {% endhighlight %} -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 `vendor/` 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 `vendor/` directory. This also applies to projects +you've downloaded that already provide a `composer.json` file: {% highlight console %} composer install {% endhighlight %} -Next, add this line to your application's primary PHP file; this will tell PHP to use Composer's autoloader for your -project dependencies. +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 %} pear-channel/Package