According to wikipedia, COMPOSER is an application-level package manager for PHP, and we will learn few more features about it. Download & Setup
Preferred way:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52
599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061’)
{ echo 'Installer verified'; }
else { echo 'Installer corrupt’;
unlink('composer-setup.php'); } echo PHP_EOL;"
<span style="color: #0000ff;">**php composer-setup.php**</span>
php -r "unlink('composer-setup.php');"
Perhaps you noticed the php execution statement is in blue color. Whats in it? So with these options you can setup composer : php composer-setup.php --install-dir=bin --filename=composerbin --version=1.0.0-alpha8
So how dependencies injected and
Answers are:
Your Need:
Composer solution:
Now its time to show you an example of Composer.json in detail view:
Fig-3 You created a composer.json file for your project, so now its time to install the dependencies [require(for all environment) and require-dev(for debugging environment only)]. The command is: composer install --prefer-source -o ...there are so many arguments you can pass to change the installation procedure and bring stability and so more....I just quoted options from GetComposer.org itself:
source
and dist
. For stable versions Composer will use the dist
by default. The source
is a version control repository. If --prefer-source
is enabled, Composer will install from source
if there is one. This is useful if you want to make a bugfix to a project and get a local git clone of the dependency directly.--prefer-source
, Composer will install from dist
if possible. This can speed up installs substantially on build servers and other use cases where you typically do not run updates of the vendors. It is also a way to circumvent problems with git if you do not have a proper setup.--dry-run
. This will simulate the installation and show you what would happen.require-dev
(this is the default behavior).require-dev
. The autoloader generation skips the autoload-dev
rules.composer.json
.--optimize-autoloader
.php
, hhvm
, lib-*
and ext-*
requirements and force the installation even if the local machine does not fulfill these. See also the platform
config option.Have you observed the script section in Fig-3 right. You can run any number of pre, post and custom scripts with dependency installation. e.g. Symfony 3.4 version does: "symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
.......................
],
"post-install-cmd": [
"@symfony-scripts"
],
"post-update-cmd": [
"@symfony-scripts"
]
So it defines a names script "symfony-script" and running at pre and post installation. Interesting dahh!!! Once your installation process is done, composer will create a lock file.
Likewise for my project the lock file look like: Pretty much done..last and not the least. Why we are installing via composer, aren't those packages not having downloadable links today !!!! Indeed, all these dependencies can be manually downloaded . Composer basically looks a repo list : Packagist. Go and search for "doctrine/doctrine-bundle" and you will see : Go to the details page of the bundle/package.. Notice the homepage url and its github. So you can download it from github easilty. So again why composer..... Simply said, to add the package, in earlier days, you have to use the package namespace as require. But new things evolved. Now psr-4 autoload can do it for you. You notice the below line in composer.json, I am copying as Symfony 3.4 version provides.. "autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
}
so it gives you the bootstrap and there will be a "autoload.php" inside your vendor directory, it will take care the bootstrapping for you. Walla!!!!!!! stay tuned for the next phase of this topic..TC