<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>Fun with ones and zeros - php</title>
<description><![CDATA[Barry's notes on computer software and hardware]]></description>
<link>/blog/tags/php</link>
<lastBuildDate>Wed, 17 Jun 2026 04:02:59 -0700</lastBuildDate>
<item>
<title>Named routes in Laravel 4</title>
<link>/blog/entries/named-routes-laravel-4</link>
<pubDate>Sat, 26 Jan 2013 14:51:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<body><p>I've been doing some work with PHP &amp; Laravel 4, and had an idea to make naming routes a bit nicer syntactically.  Currently, to name a route you wrap the 2nd parameter in an array and add an item with an 'as' key, as in:</p>
<div class="source"><pre><span></span><span class="x">Route::get('user/profile', array('as' =&gt; 'profile', function(){// code here..}));</span>
</pre></div>
<p>I think it'd be more natural to set the name using a method on the route (similar to adding a where() condition) , something like:</p>
<div class="source"><pre><span></span><span class="x">Route::get('user/profile', function(){// code here..})</span>
<span class="x">    -&gt;named('profile');</span>
</pre></div>
<p>After a bit of poking around, I found this could be done fairly easily with a couple
small additions to Route and Router to allow for renaming a route:</p>
<div class="source"><pre><span></span><span class="gd">--- a/vendor/laravel/framework/src/Illuminate/Routing/Route.php Fri Jan 25 15:35:04 2013 -0600</span>
<span class="gi">+++ b/vendor/laravel/framework/src/Illuminate/Routing/Route.php Sat Jan 26 16:37:08 2013 -0600</span>
<span class="gu">@@ -411,4 +411,16 @@</span>
                return $this;
        }

<span class="gd">-}</span>
<span class="gi">+    /**</span>
<span class="gi">+     * Change the name for this route.</span>
<span class="gi">+     *</span>
<span class="gi">+     * @param string $name New Name</span>
<span class="gi">+     * @return Illuminate\Routing\Route</span>
<span class="gi">+     */</span>
<span class="gi">+    public function named($name)</span>
<span class="gi">+    {</span>
<span class="gi">+        $this-&gt;router-&gt;rename($this, $name);</span>
<span class="gi">+</span>
<span class="gi">+        return $this;</span>
<span class="gi">+    }</span>
<span class="gi">+}</span>
\ No newline at end of file
<span class="gh">diff -r 50adf81e2f0f vendor/laravel/framework/src/Illuminate/Routing/Router.php</span>
<span class="gd">--- a/vendor/laravel/framework/src/Illuminate/Routing/Router.php        Fri Jan 25 15:35:04 2013 -0600</span>
<span class="gi">+++ b/vendor/laravel/framework/src/Illuminate/Routing/Router.php        Sat Jan 26 16:37:08 2013 -0600</span>
<span class="gu">@@ -1159,4 +1159,21 @@</span>
                $this-&gt;container = $container;
        }

<span class="gi">+    /**</span>
<span class="gi">+     * Change the name of a route</span>
<span class="gi">+     *</span>
<span class="gi">+     * @param $route</span>
<span class="gi">+     * @param $name</span>
<span class="gi">+     * @return void</span>
<span class="gi">+     */</span>
<span class="gi">+    public function rename($route, $name)</span>
<span class="gi">+    {</span>
<span class="gi">+        foreach($this-&gt;routes-&gt;getIterator() as $n =&gt; $r) {</span>
<span class="gi">+            if ($r === $route) {</span>
<span class="gi">+                $this-&gt;routes-&gt;remove($n);</span>
<span class="gi">+                $this-&gt;routes-&gt;add($name, $r);</span>
<span class="gi">+                return;</span>
<span class="gi">+            }</span>
<span class="gi">+        }</span>
<span class="gi">+    }</span>
 }
</pre></div>
<p>It's not the most efficient thing in the world to be iterating over all the previous routes.  A small optimization would be to check the last-added route first, in the example usage that'd be the one you're renaming.  But to do that would require also patching Symfony's <code>RouteCollection</code> class.</p></body>]]></description>
</item>
<item>
<title>Building additional PHP modules on OSX</title>
<link>/blog/entries/building-additional-php-modules-osx</link>
<pubDate>Mon, 08 Dec 2008 20:09:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<body><p>Normally I try to avoid dealing with PHP if at all possible, but there is now a PHP port of <a href="/software/py-amqplib">py-amqplib</a>
called <a href="http://code.google.com/p/php-amqplib/">php-amqplib</a>, and I offered to help out with it a bit.  Maybe partially out of guilt for having
written the mess of Python code it was based on :)</p>
<p>I thought it would be handy to work on it using my MacBook.  OS X 10.5 (Leopard) has PHP 5.2.6 built in standard, but unfortunately it doesn't have the <code>bcmath</code> extension included, which php-amqplib makes use of.  Turns out building the module wasn't that difficult.  <a href="http://kenior.com/macintosh/adding-gd-library-for-mac-os-x-leopard">This page</a> got me going - although building <code>bcmath</code> was much simpler.  Since I had the Apple Developer Tools for 10.5 installed, it was just a matter of ...</p>
<ul>
<li>mkdir /SourceCache</li>
<li>cd /SourceCache</li>
<li>fetch <a href="https://www.php.net/get/php-5.2.6.tar.gz/from/this/mirror">https://www.php.net/get/php-5.2.6.tar.gz/from/this/mirror</a></li>
<li>tar xzvf php-5.2.6.tar.gz</li>
<li>cd php-5.2.6/ext/bcmath</li>
<li>phpize</li>
<li>./configure</li>
<li>make</li>
<li>sudo make install</li>
<li>cd /etc</li>
<li>cp php.ini.default php.ini</li>
</ul>
<p>And then edit /etc/php.ini to make these two changes:</p>
<div class="source"><pre><span></span><span class="gd">--- php.ini.default     2008-07-15 14:19:15.000000000 -0500</span>
<span class="gi">+++ php.ini     2008-12-08 21:44:52.000000000 -0600</span>
<span class="gu">@@ -483,7 +483,7 @@</span>
 user_dir =

 ; Directory in which the loadable extensions (modules) reside.
<span class="gd">-extension_dir = "./"</span>
<span class="gi">+;extension_dir = "./"</span>

 ; Whether or not to enable the dl() function.  The dl() function does NOT work
 ; properly in multithreaded servers, such as IIS or Zeus, and is automatically
<span class="gu">@@ -595,6 +595,7 @@</span>
 ; needs to go here.  Specify the location of the extension with the
 ; extension_dir directive above.

<span class="gi">+extension=bcmath.so</span>

 ; Windows Extensions
 ; Note that ODBC support is built in, so no dll is needed for it.
</pre></div>
<p>After that, I was able to run the <code>amqp_test.php</code> file for the first time, sending a message and receiving it in py-amqplib's <code>demo/demo_receive.py</code></p></body>]]></description>
</item>
</channel>
</rss>