{"id":26051,"date":"2016-04-21T11:48:47","date_gmt":"2016-04-21T09:48:47","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=26051"},"modified":"2017-01-31T13:25:28","modified_gmt":"2017-01-31T11:25:28","slug":"adventure-in-composer-private-repositories","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2016\/04\/21\/adventure-in-composer-private-repositories\/","title":{"rendered":"Adventure in composer private repositories"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>First of all, I would like to take this opportunity and wish <a href=\"https:\/\/getcomposer.org\">composer<\/a> a happy birthday and many more years to come. \u00a0It&#8217;s been <a href=\"https:\/\/seld.be\/notes\/composer-goes-gold\">five years<\/a>, and the world of PHP has changed so drastically that not many people remember how it used to be before.<\/p>\n<p>I would have completely missed the birthday if it wasn&#8217;t for all the Google searching I did while working on a weird problem. \u00a0But before I get to the problem, let me set the scene.<\/p>\n<p>The big part of composer success is <a href=\"https:\/\/packagist.org\">Packagist.org<\/a> &#8211; the repository of <strong>almost 100,000 packages<\/strong> (93,572, according to <a href=\"https:\/\/packagist.org\/statistics\">statistics<\/a>, as of this writing, to be precise), which help one to solve pretty much any problem that PHP can be used for.<\/p>\n<p>As good as the Packagist is, there is often a need for a repository or a package elsewhere. \u00a0Whether it&#8217;s a commercial library, or sensitive corporate code, having an ability to store it outside of public eye and handle with the same ease and the same tool as the rest of the dependencies is a very welcome feature.<\/p>\n<p>Now we are getting closer to what actually happened. \u00a0A while back, I&#8217;ve setup deployment and development process for WordPress-based projects. \u00a0WordPress doesn&#8217;t support composer natively, but there are ways to make it work. \u00a0Huge thanks here goes to <a href=\"https:\/\/roots.io\/using-composer-with-wordpress\/\">Roots<\/a>.<\/p>\n<p>So. \u00a0The <em>composer.json<\/em> file was filled with additional repositories and requirements which told composer where from to fetch things, and where to install them. \u00a0Here&#8217;s an example:<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\r\n&quot;repositories&quot;: &#x5B;\r\n    {\r\n        &quot;type&quot;: &quot;package&quot;,\r\n        &quot;package&quot;: {\r\n            &quot;name&quot;: &quot;wordpress&quot;,\r\n            &quot;type&quot;: &quot;webroot&quot;,\r\n            &quot;version&quot;: &quot;4.4.1&quot;,\r\n            &quot;dist&quot;: {\r\n                &quot;type&quot;: &quot;zip&quot;,\r\n                &quot;url&quot;: &quot;https:\/\/github.com\/WordPress\/WordPress\/archive\/4.4.1.zip&quot;\r\n            },\r\n            &quot;require&quot;: {\r\n                &quot;fancyguy\/webroot-installer&quot;: &quot;1.1.0&quot;\r\n            }\r\n        }\r\n    },\r\n    \/\/ ...\r\n<\/pre>\n<p>This got especially useful, when we need to work with commercial plugins, which we couldn&#8217;t push to our public repositories, and which we didn&#8217;t want to re-distribute with every project.<\/p>\n<p>So far so good. Fast-forward to a few month ago. We are setting up similar development and deployment process, but now for CakePHP-based projects. Things are much easier, since <a href=\"http:\/\/book.cakephp.org\/3.0\/en\/installation.html\">CakePHP 3 natively supports composer<\/a> for the application itself and for its plugins.<\/p>\n<p>But we still have the need for private repositories here and there, so we follow the same setup as we did for WordPress. This week, we had an unexpected roadblock, which wasn&#8217;t making much sense to me. When trying to pull a CakePHP plugin from a private repository, we&#8217;d get a nasty exception like this:<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\r\n$ composer update\r\nLoading composer repositories with package information\r\nUpdating dependencies (including require-dev)\r\n  - Installing qobo\/cakephp-test-foo (1.0.1)\r\n    Loading from cache\r\n\r\n\r\n                                                                                                                                              \r\n  &#x5B;RuntimeException]                                                                                                                          \r\n  Unable to get primary namespace for package qobo\/cakephp-test-foo.                                                                          \r\n  Ensure you have added proper 'autoload' section to your plugin's config as stated in README on https:\/\/github.com\/cakephp\/plugin-installer  \r\n                                                                                                                                              \r\n\r\n<\/pre>\n<p>This was confusing. First of all, I&#8217;ve never seen this error before. Secondly, I&#8217;ve read the README and had the autoloader section in the composer.json as instructed. Thirdly, very similar plugins were working fine.<\/p>\n<p>Long story short, the issue wasn&#8217;t related to whether or not the GitHub\/BitBucket repository was private or public. It was related to how the repository was configured in the <em>composer.json<\/em>. Reading and re-reading <a href=\"https:\/\/getcomposer.org\/doc\/05-repositories.md\">composer documentation about Repositories<\/a> finally helped.<\/p>\n<p>You can have a look at our test setup:<\/p>\n<ul>\n<li><a href=\"https:\/\/bitbucket.org\/QoboLtd\/cakephp-project\/src\">cakephp-project<\/a> &#8211; an empty vanilla CakePHP 3 project with no configurations.<\/li>\n<li><a href=\"https:\/\/bitbucket.org\/QoboLtd\/cakephp-test-foo\/src\">cakephp-test-foo<\/a> &#8211; an empty CakePHP 3 plugin, baked by CakePHP itself.<\/li>\n<li><a href=\"https:\/\/bitbucket.org\/QoboLtd\/cakephp-project\/commits\/1f1a2caff363a7f4831026c17fb8194b00307e96\">commit #1f1a2ca<\/a> &#8211; fix for the problem<\/li>\n<\/ul>\n<p>CakePHP plugin installer requires the autoload section in <em>composer.json<\/em>. \u00a0But, when the repository is of type &#8220;<em>package<\/em>&#8220;, for some reason, the autoload section is ignored altogether. \u00a0The RuntimeException &#8220;<em>Unable to get primary namespace for package<\/em>&#8221; is thrown by <a href=\"https:\/\/github.com\/cakephp\/plugin-installer\/\">cakephp\/plugin-installer<\/a> (<a href=\"https:\/\/github.com\/cakephp\/plugin-installer\/blob\/master\/src\/Installer\/PluginInstaller.php#L274\">src\/Installer\/PluginInstaller.php line 274<\/a>). \u00a0The problem is not actually in the cakephp\/plugin-installer, but somewhere in the composer. \u00a0Maybe it&#8217;s intentional or maybe it&#8217;s not. \u00a0I didn&#8217;t have the time to investigate and understand it further.<\/p>\n<p>Switching the repository to type &#8220;<em>vcs<\/em>&#8221; fixes the problem. \u00a0It also simplifies the <em>composer.json<\/em> file and removes the need for multiple version definitions, as now composer is using BitBucket\/GitHub API to fetch available versions.<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>First of all, I would like to take this opportunity and wish composer a happy birthday and many more years to come. \u00a0It&#8217;s been five years, and the world of PHP has changed so drastically that not many people remember how it used to be before. I would have completely missed the birthday if it &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2016\/04\/21\/adventure-in-composer-private-repositories\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Adventure in composer private repositories<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Adventure in composer private repositories #WebDev #PHP","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_links_to":"","_links_to_target":""},"categories":[1,18,62,1334,60],"tags":[1537,3489,38,1330],"keyring_services":[],"class_list":["post-26051","post","type-post","status-publish","format-standard","hentry","category-general","category-programming","category-technology","category-web-work","category-wordpress","tag-cakephp","tag-composer","tag-php","tag-web-development"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":44293,"url":"https:\/\/mamchenkov.net\/wordpress\/2019\/09\/23\/github-adds-php-and-composer-dependency-graphs\/","url_meta":{"origin":26051,"position":0},"title":"GitHub adds PHP and Composer dependency graphs","author":"Leonid Mamchenkov","date":"September 23, 2019","format":false,"excerpt":"Here are some great news from GitHub: Dependency graph support is now available for PHP repositories with Composer dependencies. You may see security alerts on your repositories as dependency graph support rolls out. When there\u2019s a published vulnerability on any of the Composer dependencies that your project lists in\u00a0composer.json\u00a0and\u00a0composer.lock\u00a0files, GitHub\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/09\/github-php-composer.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/09\/github-php-composer.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/09\/github-php-composer.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/09\/github-php-composer.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/09\/github-php-composer.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2019\/09\/github-php-composer.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":21721,"url":"https:\/\/mamchenkov.net\/wordpress\/2014\/04\/29\/composer-for-php-dependency-management\/","url_meta":{"origin":26051,"position":1},"title":"Composer for PHP dependency management","author":"Leonid Mamchenkov","date":"April 29, 2014","format":"status","excerpt":"I am reading about Composer. \u00a0And the more I read, the more I like it.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":28559,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/05\/08\/composer-plugin-qa-composer-plugin-for-php-quality-assurance-tools\/","url_meta":{"origin":26051,"position":2},"title":"composer-plugin-qa &#8211; Composer Plugin for PHP Quality Assurance Tools","author":"Leonid Mamchenkov","date":"May 8, 2018","format":false,"excerpt":"composer-plugin-qa is a Composer plugin which adds all the most popular PHP quality assurance tools as composer scripts, so that you don't have to install and set them up one by one.\u00a0 The list of tools includes the following: PHPUnit: Testing Framework PHPCOV: CLI frontend for the\u00a0PHP_CodeCoverage Paratest: Parallel testing\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2018\/05\/composer-plugin-qa-500x296.jpeg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":28431,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/03\/14\/updating-wordpress-with-composer-and-wp-cli\/","url_meta":{"origin":26051,"position":3},"title":"Updating WordPress with Composer and WP-CLI","author":"Leonid Mamchenkov","date":"March 14, 2018","format":false,"excerpt":"The other day I came across this blog post by\u00a0Mark Jaquith, who is one of the lead contributors to WordPress, in which he describes his process of updating WordPress plugins with WP-CLI and Git.\u00a0 I think a lot of people these days are trying to use Git for version control\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":28394,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/02\/19\/composer-local-packages-for-dummies\/","url_meta":{"origin":26051,"position":4},"title":"Composer Local Packages for Dummies","author":"Leonid Mamchenkov","date":"February 19, 2018","format":false,"excerpt":"Composer (in combination with Packagist) is one technology that has significantly changed the ecosystem of the PHP programming language.\u00a0 Anybody working with PHP in this day and age MUST know how to use composer.\u00a0 However, not everyone does.\u00a0 So here is a nice tutorial on how to get started with\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2018\/02\/composer.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":27280,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/01\/31\/composer-patches-simple-patches-plugin-for-composer\/","url_meta":{"origin":26051,"position":5},"title":"composer-patches &#8211; Simple patches plugin for Composer","author":"Leonid Mamchenkov","date":"January 31, 2017","format":false,"excerpt":"composer-patches is a plugin for Composer which helps with applying patches to the installed dependencies. \u00a0It supports patches from URLs, local files, and from other dependencies. I think this is absolutely brilliant! It's quite often that one finds bugs and issues in external dependencies. \u00a0Once the bug (or even the\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2017\/01\/commit-500x263.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/26051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=26051"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/26051\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=26051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=26051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=26051"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=26051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}