{"id":2563,"date":"2015-03-21T22:52:46","date_gmt":"2015-03-21T18:52:46","guid":{"rendered":"http:\/\/nayarweb.com\/blog\/?p=2563"},"modified":"2015-03-21T22:52:46","modified_gmt":"2015-03-21T18:52:46","slug":"composer","status":"publish","type":"post","link":"https:\/\/nayarweb.com\/blog\/2015\/composer\/","title":{"rendered":"Composer"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\" aligncenter\" src=\"https:\/\/getcomposer.org\/img\/logo-composer-transparent.png\" alt=\"\" width=\"300\" height=\"356\" \/><\/p>\n<p>It&#8217;s awesome, isn&#8217;t it? For those who don&#8217;t know it, &#8220;<a href=\"https:\/\/getcomposer.org\/\" target=\"_blank\">Composer<\/a> is a tool for dependency management in PHP&#8221;. For example, if you are going to use <a href=\"http:\/\/www.slimframework.com\/\" target=\"_blank\">Slim Framework<\/a> with <a href=\"http:\/\/twig.sensiolabs.org\/\" target=\"_blank\">Twig<\/a> Templating system, just create a file named &#8216;composer.json&#8217; in your working folder with the following contents<\/p>\n<p><code><br \/>\n{<br \/>\n&nbsp;&nbsp;\"require\": {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\"slim\/slim\": \"2.*\",<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\"twig\/twig\": \"1.*\"<br \/>\n&nbsp;&nbsp;}<br \/>\n} <\/p>\n<p><\/code><\/p>\n<p>Then run the following command:<\/p>\n<p><code>$ composer install<\/code><\/p>\n<p>It shall download them in a folder named vendor. Include the following code in your PHP script:<\/p>\n<p><code>require 'vendor\/autoload.php';<\/code><\/p>\n<p>All libraries just work like magic \ud83d\ude00<\/p>\n<p>Apparently Composer has some sort of repository where people upload their codes. I didn&#8217;t want to signup on their website to put my library. I&#8217;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.<\/p>\n<p><code><br \/>\n{<br \/>\n&nbsp;&nbsp;\"repositories\": [<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"url\": \"https:\/\/github.com\/Nayar\/mera-framework-php\",<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"type\": \"git\"<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;],<br \/>\n&nbsp;&nbsp;\"require\": {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\"slim\/slim\": \"2.*\",<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\"twig\/twig\": \"1.*\",<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\"meraframeworkphp\": \"*\"<br \/>\n&nbsp;&nbsp;},<br \/>\n}<\/code><\/p>\n<p>However i was getting this error when I was initializing composer repositories.<\/p>\n<blockquote><p>Loading composer repositories with package information<br \/>\nReading composer.json of meraframeworkphp (master)<br \/>\nInstalling dependencies (including require-dev)<br \/>\nYour requirements could not be resolved to an installable set of packages.<\/p>\n<p>  Problem 1<br \/>\n    &#8211; The requested package meraframeworkphp could not be found in any version, there may be a typo in the package name.<\/p>\n<p>Potential causes:<br \/>\n &#8211; A typo in the package name<br \/>\n &#8211; The package is not available in a stable-enough version according to your minimum-stability setting<br \/>\n   see <https:\/\/groups.google.com\/d\/topic\/composer-dev\/_g3ASeIFlrc\/discussion> for more details.<\/p>\n<p>Read <http:\/\/getcomposer.org\/doc\/articles\/troubleshooting.md> for further common problems.\n<\/p><\/blockquote>\n<p>Composer uses Git tags to actually find the repository version. Ran the following in my library git then it worked awesome:<\/p>\n<p><code>$ git tag -a v1.0.0 -m 'First release'<br \/>\n$ git push origin v1.0.0<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s awesome, isn&#8217;t it? For those who don&#8217;t know it, &#8220;Composer is a tool for dependency management in PHP&#8221;. For example, if you are going to use Slim Framework with Twig Templating system, just create a file named &#8216;composer.json&#8217; in your working folder with the following contents { &nbsp;&nbsp;&#8220;require&#8221;: { &nbsp;&nbsp;&nbsp;&nbsp;&#8220;slim\/slim&#8221;: &#8220;2.*&#8221;, &nbsp;&nbsp;&nbsp;&nbsp;&#8220;twig\/twig&#8221;: &#8220;1.*&#8221; &nbsp;&nbsp;} &hellip; <a href=\"https:\/\/nayarweb.com\/blog\/2015\/composer\/\" class=\"continue-reading\">Continue reading <span class=\"screen-reader-text\">Composer<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[117],"class_list":["post-2563","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-web-development"],"_links":{"self":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/comments?post=2563"}],"version-history":[{"count":8,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2563\/revisions"}],"predecessor-version":[{"id":2571,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2563\/revisions\/2571"}],"wp:attachment":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/media?parent=2563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/categories?post=2563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/tags?post=2563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}