{"id":89,"date":"2020-02-06T22:12:00","date_gmt":"2020-02-06T22:12:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=89"},"modified":"2024-02-06T08:17:56","modified_gmt":"2024-02-06T13:17:56","slug":"php-package-managers","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/php-package-managers\/","title":{"rendered":"PHP package managers"},"content":{"rendered":"\n<p>PHP has seemingly countless extensions and packages. See http:\/\/www.packagist.org to see the list of packages. Naturally, you would wish to have a software to manage the extensions and packages. Wish granted! PEAR, PECL, and composer are PHP package managers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PEAR<\/h3>\n\n\n\n<p>PEAR was the first PHP package manager. It is designed for systemwide packages so anytime you install a package through PEAR, it is installed in a central repository. The scripts and commands become available from anywhere on the command-line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PECL<\/h3>\n\n\n\n<p>PECL manages compiled extensions to PHP.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Composer<\/h3>\n\n\n\n<p>Composer is used to list project dependencies. Composer make it very easy to list and install dependencies.<\/p>\n\n\n\n<p>Today, the community is actively using all three managers. The choice depends on the project and people working on the project.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Composer on Mac<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -sS https:\/\/getcomposer.org\/installer | php\nmv composer.phar \/usr\/local\/bin\/composer<\/code><\/pre>\n\n\n\n<p>To use composer, simply do<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ composer<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Using Composer<\/h3>\n\n\n\n<ol class=\"wp-block-list\"><li>First create a directory<\/li><li>Run init from inside the directory<\/li><li>composer init will create a new composer.json file<\/li><li>Follow instructions and answer questions<\/li><\/ol>\n\n\n\n<p>Following is what you type on command line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mkdir myproject\n$ cd myproject\n$ composer init\nPackage name: enter\nDescription: my project\nAuthor: Alice Bob &lt;alice@molecularsciences.org>\nMinimum stability: enter\nLicense:  MIT\nDefine your dependencies\n... interactively: Yes\nSearch for a package: markdown<\/code><\/pre>\n\n\n\n<p>Note that all this information is now saved in composer.json file. composer.lock contains information about the packages installed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Writing code<\/h3>\n\n\n\n<p>Following example shows how to code using packages downloaded through composer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>require 'vendor\/autoload.php';\n$x = new \\testdev\\markdown\\MarkdownParser();\nprint $transformMarkdown(file_get_contents('somefile.md'));<\/code><\/pre>\n\n\n\n<p>This code converts a markdown file to html and prints it to screen.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP has seemingly countless extensions and packages. See http:\/\/www.packagist.org to see the list of packages. Naturally, you would wish to have a software to manage the extensions and packages. Wish granted! PEAR, PECL, and composer are PHP package managers. PEAR PEAR was the first PHP package manager. It is designed for systemwide packages so anytime [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[45,24],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-php","tag-package-manager","tag-php"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/89\/revisions\/90"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}