{"id":539,"date":"2022-01-12T13:44:43","date_gmt":"2022-01-12T13:44:43","guid":{"rendered":"https:\/\/amasan.co.uk\/vandragt\/?p=539"},"modified":"2022-01-12T13:50:07","modified_gmt":"2022-01-12T13:50:07","slug":"how-to-develop-a-library-and-a-project-in-php-concurrently","status":"publish","type":"post","link":"https:\/\/2022.vandragt.com\/technology\/how-to-develop-a-library-and-a-project-in-php-concurrently\/","title":{"rendered":"How to develop a library and a project in PHP concurrently"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I keep forgetting the best way to do this, so thought it best to write it down.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose you are building a library and an example project that implements it. You can do this in a single repository with an example folder, for small examples.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But for larger examples you might want to use a separate repository, with it&#8217;s own issues and documentation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This can make it a hassle to work with the library and keep the project in sync.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s say these are <code>mylibrary<\/code> and <code>myproject<\/code> which is using the library. Let&#8217;s assume you&#8217;re using PHP and Composer. <code>mylibrary<\/code> is at version 0.1 but there are newer commits in the <code>develop<\/code> branch.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Require a Git repository<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cd myproject\n$ composer config repositories.me vcs https:\/\/github.com\/me\/mylibrary\n$ composer require me\/mylibrary:0.1 --prefer-source<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>--prefer-source<\/code> means Composer will install from <code>source<\/code> if there is one, the result is a git repository.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Switch to the develop branch<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once installed it&#8217;s then easy to switch to any other branch you want to work on:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cd vendor\/me\/mylibrary; git switch develop<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You don&#8217;t have to register the repository with packagist if you follow this workflow! As a bonus when after you run <code>composer update<\/code> in <code>myproject<\/code> the mylibrary directory sticks with the branch.<\/p>\n<div class=\"syndication-links\"><\/div>","protected":false},"excerpt":{"rendered":"<p>I keep forgetting the best way to do this, so thought it best to write it down. Suppose you are building a library and an example project that implements it. You can do this in a single repository with an example folder, for small examples. But for larger examples you might want to use a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"mf2_syndication":[],"webmentions_disabled_pings":false,"webmentions_disabled":false,"footnotes":""},"categories":[11],"tags":[46,45],"class_list":["post-539","post","type-post","status-publish","format-standard","hentry","category-technology","tag-composer","tag-php"],"_links":{"self":[{"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/posts\/539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/comments?post=539"}],"version-history":[{"count":4,"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/posts\/539\/revisions"}],"predecessor-version":[{"id":543,"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/posts\/539\/revisions\/543"}],"wp:attachment":[{"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/media?parent=539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/categories?post=539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/amasan.co.uk\/vandragt\/wp-json\/wp\/v2\/tags?post=539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}