<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>composer | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/composer/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Fri, 11 Apr 2025 10:10:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Patch dependencies with composer-patches</title>
		<link>https://nerdpress.org/2025/04/11/patch-dependencies-with-composer-patches/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 11 Apr 2025 10:10:56 +0000</pubDate>
				<category><![CDATA[Composer]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[composer]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3406</guid>

					<description><![CDATA[<p>Sometimes, you may encounter a bug or an unwanted functionality in a PHP vendor dependency, and forking the package and maintaining upstream changes can be too cumbersome. In such cases, using composer-patches is a good solution. Composer-patches is a handy Composer plugin that applies diff patches to specific packages during installation. Basically, you store a &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2025/04/11/patch-dependencies-with-composer-patches/" class="more-link">Continue reading<span class="screen-reader-text"> "Patch dependencies with composer-patches"</span></a></p>
The post <a href="https://nerdpress.org/2025/04/11/patch-dependencies-with-composer-patches/">Patch dependencies with composer-patches</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Sometimes, you may encounter a bug or an unwanted functionality in a PHP vendor dependency, and forking the package and maintaining upstream changes can be too cumbersome. In such cases, using <strong><a href="https://github.com/cweagans/composer-patches" target="_blank" rel="noopener" title="">composer-patches</a></strong> is a good solution.</p>



<p><strong>Composer-patches</strong> is a handy Composer plugin that applies diff patches to specific packages during installation.</p>



<p>Basically, you store a diff patch in your project, specify which vendor package it should be applied to in your <code>composer.json</code>, and the plugin will apply the patch to the original code of the vendor package after it got installed by composer.</p>



<span id="more-3406"></span>



<p>The <a href="https://docs.cweagans.net/composer-patches/" target="_blank" rel="noopener" title="">documentation</a> provides detailed instructions on how to set up the plugin.<br />In short, you need:</p>



<ul class="wp-block-list">
<li>Install the plugin (we&#8217;re using the v2 beta) with:<br /><code>composer require cweagans/composer-patches:^2.0.0-beta2</code></li>



<li>Create a patch. The plugin relies on Git as the patcher, so you can use Git to generate the patch file. (See below)<br />However, I recommend using another package to create the patch file:<br /><a class="" href="https://github.com/symplify/vendor-patches">https://github.com/symplify/vendor-patches</a><br />This package provides an opinionated but reasonable way to create and store your patches. <strong>vendor-patches</strong> takes care of the correct paths in the patch file, which might not be immediately obvious: Pathes should be relative to the vendor package root and not relative to your projects root dir.</li>



<li>Add the patch instructions to your <code>composer.json</code> by including a <code>patches</code> section under <code>extra</code>. For example:</li>
</ul>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-string">"extra"</span>: {
  <span class="hljs-string">"patches"</span>: {
    <span class="hljs-string">"oxid-esales/oxideshop-ce"</span>: {
      <span class="hljs-string">"Disable user registration due to spam attacks"</span>: <span class="hljs-string">"./patches/disable-registerUser.patch"</span>
    }
  }
}</code></span></pre>


<p>On your next <code>composer install</code> the vendor package will be patched and the vendor&#8217;s <br />code will be altered according the patch.</p>



<p>Some notes: If you encounter the error:</p>



<pre class="wp-block-preformatted">Could not apply patch! Skipping. The error was: Cannot apply patch disable-registerUser.patch</pre>



<p>You might have incorrect paths in your patch file. As mentioned above, the paths need to be relative to the vendor root directory, not your project&#8217;s root directory.<br />So to manually create the diff patches, run this command:</p>



<pre class="wp-block-preformatted">diff --git a/source/Application/Component/UserComponent.php b/source/Application/Component/UserComponent.php</pre>



<p><br />This is <strong>wrong</strong> usage from project root dir:</p>



<pre class="wp-block-preformatted">diff --git a/vendor/oxid-esales/oxideshop-ce/source/Application/Component/UserComponent.php b/vendor/oxid-esales/oxideshop-ce/source/Application/Component/UserComponent.php</pre>



<p>Happy patching! :)</p>The post <a href="https://nerdpress.org/2025/04/11/patch-dependencies-with-composer-patches/">Patch dependencies with composer-patches</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Composer bump</title>
		<link>https://nerdpress.org/2023/08/21/composer-bump/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 21 Aug 2023 09:36:06 +0000</pubDate>
				<category><![CDATA[Composer]]></category>
		<category><![CDATA[composer]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3265</guid>

					<description><![CDATA[<p>Do you miss that the version numbers of your PHP dependencies are automatically updated in the composer.json file after a composer update?Just like npm or yarn are updating the version numbers in the package.json file. Then upgrade to Composer 2.4 and say hi to composer dump.This version introduced a new command composer bump which will &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2023/08/21/composer-bump/" class="more-link">Continue reading<span class="screen-reader-text"> "Composer bump"</span></a></p>
The post <a href="https://nerdpress.org/2023/08/21/composer-bump/">Composer bump</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Do you miss that the version numbers of your PHP dependencies are automatically updated in the composer.json file after a <code>composer update</code>?<br />Just like npm or yarn are updating the version numbers in the package.json file.</p>



<p>Then upgrade to Composer 2.4 and say hi to<a href="https://getcomposer.org/doc/03-cli.md#bump" target="_blank" rel="noopener" title=""> <code>composer dump</code></a>.<br />This version introduced a new command <code>composer bump</code> which will update your composer.json file to the precise version which is pinned in the composer.lock file.<br />It basically will sync the composer.json with the composer.lock versions and will keep the caret version constraints, so you can still make minor or patch version upgrades.</p>



<span id="more-3265"></span>



<p>This will have the effect that the version constraints are hardenend and you will not be able to install versions lower than the currently installed version.<br />With not updated versions in composer.json file you will not have a precise version base and could install lower versions than actually required.</p>



<p>Another benefit is that you can more easily <em>read</em> the currently installed version number of your dependencies.<br />Otherwise you would need to grep through the composer.lock file which is much less readable and cumbersome.<br />Some IDEs like PHPSTORM are helping here though by adding the installed version behind the dependency constraint in the composer.json file in the editor pane (see below).</p>



<p>Before composer bump:</p>



<figure class="wp-block-image size-full"><a href="https://nerdpress.org/wp-content/uploads/2023/08/composer-version-constraints-before-bump.png"><img fetchpriority="high" decoding="async" width="447" height="201" src="https://nerdpress.org/wp-content/uploads/2023/08/composer-version-constraints-before-bump.png" alt="" class="wp-image-3266" srcset="https://nerdpress.org/wp-content/uploads/2023/08/composer-version-constraints-before-bump.png 447w, https://nerdpress.org/wp-content/uploads/2023/08/composer-version-constraints-before-bump-300x135.png 300w" sizes="(max-width: 447px) 100vw, 447px" /></a><figcaption class="wp-element-caption">Not updated version constraints after composer update.</figcaption></figure>



<p>After composer bump:</p>



<figure class="wp-block-image size-full"><a href="https://nerdpress.org/wp-content/uploads/2023/08/composer-version-constraints-after-bump.png"><img decoding="async" width="437" height="182" src="https://nerdpress.org/wp-content/uploads/2023/08/composer-version-constraints-after-bump.png" alt="" class="wp-image-3267" srcset="https://nerdpress.org/wp-content/uploads/2023/08/composer-version-constraints-after-bump.png 437w, https://nerdpress.org/wp-content/uploads/2023/08/composer-version-constraints-after-bump-300x125.png 300w" sizes="(max-width: 437px) 100vw, 437px" /></a><figcaption class="wp-element-caption">Updated version constraints after composer bump.</figcaption></figure>



<p>Note that <code>composer dump</code> is benefical on projects but should be avoided in libraries because it could accidently limit the versions in which can you use the library.</p>



<p><br />Also it might be a good idea to have a option on <code>composer update</code> to integrate composer bump functionality.</p>The post <a href="https://nerdpress.org/2023/08/21/composer-bump/">Composer bump</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Disable SilverStripe deprecation warnings in PHP8.1</title>
		<link>https://nerdpress.org/2022/04/22/disable-silverstripe-deprecation-warnings-in-php8-1/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 22 Apr 2022 09:58:11 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[composer]]></category>
		<category><![CDATA[Silverstripe]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3129</guid>

					<description><![CDATA[<p>Since SilverStripe 4.10 is not yet fully ready for PHP8.1 you wil receive quite some deprecation warnings in dev mode when you are brave and run it nonetheless on PHP8.1. Unfortunatly we can&#8217;t control the error_reporting from SilverStripe since it is set in the kernel of the framework.So we are forced to hack the Kernel &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2022/04/22/disable-silverstripe-deprecation-warnings-in-php8-1/" class="more-link">Continue reading<span class="screen-reader-text"> "Disable SilverStripe deprecation warnings in PHP8.1"</span></a></p>
The post <a href="https://nerdpress.org/2022/04/22/disable-silverstripe-deprecation-warnings-in-php8-1/">Disable SilverStripe deprecation warnings in PHP8.1</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Since SilverStripe 4.10 is not yet fully ready for PHP8.1 you wil receive quite some deprecation warnings in dev mode when you are brave and run it nonetheless on PHP8.1.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
Deprecated: SilverStripe\Config\Collections\MemoryConfigCollection implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /var/www/html/vendor/silverstripe/config/src/Collections/MemoryConfigCollection.php on line 13
</pre></div>


<p>Unfortunatly we can&#8217;t control the<em> error_reporting</em> from SilverStripe since it is set in the kernel of the framework.<br />So we are forced to hack the Kernel which is rather unfortunate.</p>



<p>In the <a href="https://silverstripe-users.slack.com/">SilverStripe Slack</a> channel someone proposed to use <a href="https://github.com/cweagans/composer-patches" target="_blank" rel="noreferrer noopener">composer-patch</a> which will apply a patch to a given vendor dependency during composer install.<br />This is quite cool because you don&#8217;t need to fork the dependency and take care of getting upstream changes.</p>



<p>So i went this path down and it looks like in this gist:<br /><a href="https://gist.github.com/ivoba/d8c4379236149a8c42e1922ae98a93e3" target="_blank" rel="noreferrer noopener">https://gist.github.com/ivoba/d8c4379236149a8c42e1922ae98a93e3</a></p>



<span id="more-3129"></span>



<p>Basically you have to install composer patch:</p>



<p><code>composer require cweagans/composer-patches</code></p>



<p>Create the patch and add the patch file to your project.<br />You can create a patch by cloning the package i.e. silverstripe/framework into IntelliJ / PHPStorm, apply the change and under Git -&gt; Patch create the patch file.</p>



<p>Then add it to composer.json so the patch can be applied on next <code>composer install</code>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
&quot;extra&quot;: {
       &quot;patches&quot;: {
            &quot;silverstripe/framework&quot;: {
                &quot;Fix SilverStripe deprecations error_reporting for PHP 8.1&quot;: &quot;./fix-deprecation-error_reporting.4.10.4.patch&quot;
            }
       }
    }
</pre></div>


<p>Now we have patched the error_reporting and the deprecation warnings are supressed.<br />Once SilverStripe fully supports PHP8.1 we then can remove this patch.</p>The post <a href="https://nerdpress.org/2022/04/22/disable-silverstripe-deprecation-warnings-in-php8-1/">Disable SilverStripe deprecation warnings in PHP8.1</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PHP package generators</title>
		<link>https://nerdpress.org/2015/09/10/php-package-generators/</link>
					<comments>https://nerdpress.org/2015/09/10/php-package-generators/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Thu, 10 Sep 2015 12:59:19 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[composer]]></category>
		<category><![CDATA[grunt]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[yeoman]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2656</guid>

					<description><![CDATA[<p>For creating PHP packages several best practices has been established, like composer support (ofc) and putting the package on packagist, travis integration, directory organisation, tests, documentation and so on. For further information i recommend these slides https://laravel-news.com/2015/08/hannes-van-de-vreken-package-development-slides/ which describe the situation very well. And as we are all lazy, we like generators that scaffold a &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2015/09/10/php-package-generators/" class="more-link">Continue reading<span class="screen-reader-text"> "PHP package generators"</span></a></p>
The post <a href="https://nerdpress.org/2015/09/10/php-package-generators/">PHP package generators</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>For creating PHP packages several best practices has been established, like composer support (ofc) and putting the package on <a href="https://packagist.org/" target="_blank">packagist</a>, <a href="http://travis-ci.org/" target="_blank">travis</a> integration, directory organisation, tests, documentation and so on.<br />
For further information i recommend these slides <a href="https://laravel-news.com/2015/08/hannes-van-de-vreken-package-development-slides/" target="_blank">https://laravel-news.com/2015/08/hannes-van-de-vreken-package-development-slides/</a> which describe the situation very well.</p>
<p>And as we are all lazy, we like generators that scaffold a basic php package layout and luckily there are several out there.<br />
They all differ a bit, so pick your favorite.<br />
<span id="more-2656"></span><br />
I personally like the <a href="https://github.com/thephpleague/skeleton" target="_blank">https://github.com/thephpleague/skeleton</a> package template.<br />
However its branded for the <a href="http://thephpleague.com/" target="_blank">League</a> and you would have to replace all occurences of phpleague with your namespace, which is kinda cumbersome.</p>
<p>So i wrote a <a href="http://yeoman.io/" target="_blank">yeoman</a> generator which automates this, Check it out here: <a href="https://github.com/ivoba/generator-phpleague-skeleton" target="_blank">https://github.com/ivoba/generator-phpleague-skeleton</a><br />
The generator will inquire your personal and package infos and basically just replace the counterparts in the phpleague skeleton.</p>
<p>If you are a yeoman fanboy, as i am :), there are two more, worth to mention:</p>
<p><a href="https://github.com/T1st3/generator-composer" target="_blank">https://github.com/T1st3/generator-composer</a><br />
and<br />
<a href="https://github.com/juliangut/generator-barephp" target="_blank">https://github.com/juliangut/generator-barephp</a></p>
<p>The package layout here doesnt differ much, the main difference is that they come with a grunt build.<br />
So you can use grunt to run f.e. phpDoc generation, phplint, phpunit or all at once on your package with f.e. <code>grunt test</code>.</p>
<p>If you dont like yeoman and want to keep it PHP, the slides i mentioned above show two alternatives:</p>
<p><a href="https://github.com/jonathantorres/construct" target="_blank">https://github.com/jonathantorres/construct</a><br />
<a href="https://github.com/franzliedke/studio" target="_blank">https://github.com/franzliedke/studio</a></p>
<p><strong>Studio</strong> seems to be more than a normal generator though. Its rather a managment tool for developing packages.<br />
So if you look for a generator only, <strong>Construct</strong> is probably the candidate here.</p>The post <a href="https://nerdpress.org/2015/09/10/php-package-generators/">PHP package generators</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2015/09/10/php-package-generators/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Using forks with composer &#8211; late night edition</title>
		<link>https://nerdpress.org/2015/01/19/using-forks-composer-late-night-edition/</link>
					<comments>https://nerdpress.org/2015/01/19/using-forks-composer-late-night-edition/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 19 Jan 2015 16:21:46 +0000</pubDate>
				<category><![CDATA[Composer]]></category>
		<category><![CDATA[composer]]></category>
		<category><![CDATA[github]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2611</guid>

					<description><![CDATA[<p>Using your forks of certain packages with composer is actually pretty easy: Add the repo of the fork to the repositories block of your composer.json, you might need to change the version to f.e dev-master and thats it. Great. Actually. But there are some traps, especially when you are mentally already weekend bound: When working &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2015/01/19/using-forks-composer-late-night-edition/" class="more-link">Continue reading<span class="screen-reader-text"> "Using forks with composer &#8211; late night edition"</span></a></p>
The post <a href="https://nerdpress.org/2015/01/19/using-forks-composer-late-night-edition/">Using forks with composer – late night edition</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Using your forks of certain packages with <a href="https://getcomposer.org" target="_blank">composer</a> is actually pretty easy:<br />
Add the repo of the fork to the repositories block of your composer.json, you might need to change the version to f.e <b>dev-master</b> and thats it. Great. Actually.</p>
<pre class="brush: jscript; title: ; notranslate">
&quot;repositories&quot;: &#x5B;
        {
            &quot;type&quot;: &quot;vcs&quot;,
            &quot;url&quot;: &quot;https://github.com/ivoba/SomeBundle.log&quot;
        }
    ]
</pre>
<p>But there are some traps, especially when you are mentally already weekend bound:</p>
<p>When working in a team, take care that you dont add your fork as a private repo.<br />
This happens when you use the <b>@</b> notation like &#8216;<b>git@github.com</b>&#8216;. Its tempting because it will be the clone url on github when you are logged in, which is very likely.<br />
If you do so your team mates will get errors like this: </p>
<pre class="brush: plain; title: ; notranslate">Failed to execute git clone --no-checkout 'git@github.com:ivoba/SomeBundle.git' &#x5B;...] &amp;&amp; git remote add composer 'git@github.com:ivoba/SomeBundle.git' &amp;&amp; git fetch composer</pre>
<p><span id="more-2611"></span></p>
<p>So better change it to the notation of public repositories like &#8216;<b>git://github.com</b>&#8216; but take care that you change the whole path and not only the protocol like:</p>
<pre class="brush: plain; title: ; notranslate">git://github.com:ivoba/SomeBundle.git</pre>
<p>This will look in port &#8220;<em>ivoba</em>&#8221; ;) and you will get an error like:</p>
<pre class="brush: plain; title: ; notranslate">fatal: Unable to look up github.com (port ivoba) (Servname not supported for ai_socktype)</pre>
<p>If you try the same with https you will still fail with:</p>
<pre class="brush: plain; title: ; notranslate">Cloning into bare repository &#x5B;...]                                                         
  fatal: Unable to find remote helper for 'https'</pre>
<p>So the correct path for public repos is:</p>
<p><code>git://github.com/ivoba/SomeBundle.git[/code]<br />
or</p>
<pre class="brush: plain; title: ; notranslate">https://github.com/ivoba/SomeBundle.git</pre>
<p>with <b>colon slash slash domain slash </b>!</p>
<p>Stupid mistakes but they happen, though its all written in the docs:<br />
<a href="https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository" target="_blank">https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository</a><br />
and<br />
<a href="https://getcomposer.org/doc/05-repositories.md#using-private-repositories" target="_blank">https://getcomposer.org/doc/05-repositories.md#using-private-repositories</a><br />
but sometimes reading alone isnt sufficient ;).</p>The post <a href="https://nerdpress.org/2015/01/19/using-forks-composer-late-night-edition/">Using forks with composer – late night edition</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2015/01/19/using-forks-composer-late-night-edition/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>git deploy with composer install hook</title>
		<link>https://nerdpress.org/2014/11/14/git-deploy-composer-install-hook/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 14 Nov 2014 07:51:00 +0000</pubDate>
				<category><![CDATA[Composer]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[composer]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[Git]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2572</guid>

					<description><![CDATA[<p>I usually would not recommend deployment via git and running composer on your prod server for several reasons like f.e. the network. I rather believe in builds. But sometimes its just too convenient :) So i have this uncritical smaller API app where the hosting has git, ssh access and i am in full control &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2014/11/14/git-deploy-composer-install-hook/" class="more-link">Continue reading<span class="screen-reader-text"> "git deploy with composer install hook"</span></a></p>
The post <a href="https://nerdpress.org/2014/11/14/git-deploy-composer-install-hook/">git deploy with composer install hook</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>I usually would not recommend deployment via git and running <a href="https://getcomposer.org/">composer</a> on your prod server for several reasons like f.e. the network. I rather believe in builds.<br />
But sometimes its just too convenient :)</p>
<p>So i have this uncritical smaller API app where the hosting has git, ssh access and i am in full control and i decided too keep it simple.<br />
<span id="more-2572"></span></p>
<p>For deploy i login via ssh and make a <strong>git pull</strong> too fetch the code.<br />
Now we need to make a <strong>composer install</strong>, if the composer.lock has changes to fetch all php dependencies.<br />
Therefor i found a handy bash script, tweaked it a bit and installed it as post-merge git hook.</p>
<p>Install the hook:</p>
<pre class="brush: bash; title: ; notranslate">
cd project
nano .git/hooks/post-merge #paste &amp; edit the script
chmod 775 .git/hooks/post-merge 
</pre>
<p>What it does?<br />
After all code from the <strong>git pull</strong> is merged into the working tree, the hook checks if the composer.lock has changed. If so it will run a <strong>composer install</strong>.<br />
Note that it runs with <strong>&#8211;no-dev</strong> since we are on production and dont need f.e. phpunit there.</p>
<p>I know you know, but let it be said again: run <strong>composer install</strong> not <strong>composer update</strong>, as you never should run composer update on production, read why <a href="http://adamcod.es/2013/03/07/composer-install-vs-composer-update.html">here</a>.</p>
<p>So here is the bash:</p>
<pre class="brush: bash; title: ; notranslate">
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# forked by Gianluca Guarini
# phponly by Ivo Bathke ;)
 
changed_files=&quot;$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)&quot;
 
check_run() {
  echo &quot;$changed_files&quot; | grep --quiet &quot;$1&quot; &amp;&amp; eval &quot;$2&quot;
}
 
# `composer install` if the `composer.lock` file gets changed
# to update all the php dependencies
check_run composer.lock &quot;composer install --no-dev&quot;
</pre>
<p>I <a href="https://gist.github.com/ivoba/6dcdff1d8eaed7e53ec6">forked</a> it from <a href="https://gist.github.com/GianlucaGuarini/8001627">here</a>, that forked from <a href="https://gist.github.com/sindresorhus/7996717">there</a>.</p>The post <a href="https://nerdpress.org/2014/11/14/git-deploy-composer-install-hook/">git deploy with composer install hook</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
