Composer

It’s awesome, isn’t it? For those who don’t know it, “Composer is a tool for dependency management in PHP”. For example, if you are going to use Slim Framework with Twig Templating system, just create a file named ‘composer.json’ in your working folder with the following contents


{
  "require": {
    "slim/slim": "2.*",
    "twig/twig": "1.*"
  }
}

Then run the following command:

$ composer install

It shall download them in a folder named vendor. Include the following code in your PHP script:

require 'vendor/autoload.php';

All libraries just work like magic 😀

Apparently Composer has some sort of repository where people upload their codes. I didn’t want to signup on their website to put my library. I’m sort of a control freak. I wanted to host my code on Github and yet people include my library in the Composer magic. Yes! Composer supports downloading from Github.


{
  "repositories": [
    {
      "url": "https://github.com/Nayar/mera-framework-php",
      "type": "git"
    }
  ],
  "require": {
    "slim/slim": "2.*",
    "twig/twig": "1.*",
    "meraframeworkphp": "*"
  },
}

However i was getting this error when I was initializing composer repositories.

Loading composer repositories with package information
Reading composer.json of meraframeworkphp (master)
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
– The requested package meraframeworkphp could not be found in any version, there may be a typo in the package name.

Potential causes:
– A typo in the package name
– The package is not available in a stable-enough version according to your minimum-stability setting
see for more details.

Read for further common problems.

Composer uses Git tags to actually find the repository version. Ran the following in my library git then it worked awesome:

$ git tag -a v1.0.0 -m 'First release'
$ git push origin v1.0.0

Leave a Reply

Your email address will not be published. Required fields are marked *