<?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/category/php/composer-php/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>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>
