<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Fun with ones and zeros - php</title>
<subtitle>Barry&#039;s notes on computer software and hardware</subtitle>
<link href="/blog/tags/php"></link>
<updated>2026-06-17T01:39:00-07:00</updated>
<id>urn:uuid:a0d3fb78-ce57-5763-a0e2-64bca07987a3</id>
<entry>
<title>Named routes in Laravel 4</title>
<link href="/blog/entries/named-routes-laravel-4"></link>
<id>urn:uuid:ef37bbe4-91c7-1335-c252-959feca6da4a</id>
<updated>2013-01-26T14:51:00-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">&lt;body&gt;&lt;p&gt;I&#039;ve been doing some work with PHP &amp;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 &#039;as&#039; key, as in:&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;Route::get(&#039;user/profile&#039;, array(&#039;as&#039; =&amp;gt; &#039;profile&#039;, function(){// code here..}));&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I think it&#039;d be more natural to set the name using a method on the route (similar to adding a where() condition) , something like:&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;Route::get(&#039;user/profile&#039;, function(){// code here..})&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    -&amp;gt;named(&#039;profile&#039;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;gd&quot;&gt;--- a/vendor/laravel/framework/src/Illuminate/Routing/Route.php Fri Jan 25 15:35:04 2013 -0600&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+++ b/vendor/laravel/framework/src/Illuminate/Routing/Route.php Sat Jan 26 16:37:08 2013 -0600&lt;/span&gt;
&lt;span class=&quot;gu&quot;&gt;@@ -411,4 +411,16 @@&lt;/span&gt;
                return $this;
        }

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

&lt;span class=&quot;gi&quot;&gt;+    /**&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+     * Change the name of a route&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+     *&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+     * @param $route&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+     * @param $name&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+     * @return void&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+     */&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+    public function rename($route, $name)&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+    {&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+        foreach($this-&amp;gt;routes-&amp;gt;getIterator() as $n =&amp;gt; $r) {&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+            if ($r === $route) {&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+                $this-&amp;gt;routes-&amp;gt;remove($n);&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+                $this-&amp;gt;routes-&amp;gt;add($name, $r);&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+                return;&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+            }&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+        }&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+    }&lt;/span&gt;
 }
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It&#039;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&#039;d be the one you&#039;re renaming.  But to do that would require also patching Symfony&#039;s &lt;code&gt;RouteCollection&lt;/code&gt; class.&lt;/p&gt;&lt;/body&gt;</content>
</entry>
<entry>
<title>Building additional PHP modules on OSX</title>
<link href="/blog/entries/building-additional-php-modules-osx"></link>
<id>urn:uuid:d6dedaf0-9a55-6a46-528e-44e43df37111</id>
<updated>2008-12-08T20:09:00-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">&lt;body&gt;&lt;p&gt;Normally I try to avoid dealing with PHP if at all possible, but there is now a PHP port of &lt;a href=&quot;/software/py-amqplib&quot;&gt;py-amqplib&lt;/a&gt;
called &lt;a href=&quot;http://code.google.com/p/php-amqplib/&quot;&gt;php-amqplib&lt;/a&gt;, 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 :)&lt;/p&gt;
&lt;p&gt;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&#039;t have the &lt;code&gt;bcmath&lt;/code&gt; extension included, which php-amqplib makes use of.  Turns out building the module wasn&#039;t that difficult.  &lt;a href=&quot;http://kenior.com/macintosh/adding-gd-library-for-mac-os-x-leopard&quot;&gt;This page&lt;/a&gt; got me going - although building &lt;code&gt;bcmath&lt;/code&gt; was much simpler.  Since I had the Apple Developer Tools for 10.5 installed, it was just a matter of ...&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;mkdir /SourceCache&lt;/li&gt;
&lt;li&gt;cd /SourceCache&lt;/li&gt;
&lt;li&gt;fetch &lt;a href=&quot;https://www.php.net/get/php-5.2.6.tar.gz/from/this/mirror&quot;&gt;https://www.php.net/get/php-5.2.6.tar.gz/from/this/mirror&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;tar xzvf php-5.2.6.tar.gz&lt;/li&gt;
&lt;li&gt;cd php-5.2.6/ext/bcmath&lt;/li&gt;
&lt;li&gt;phpize&lt;/li&gt;
&lt;li&gt;./configure&lt;/li&gt;
&lt;li&gt;make&lt;/li&gt;
&lt;li&gt;sudo make install&lt;/li&gt;
&lt;li&gt;cd /etc&lt;/li&gt;
&lt;li&gt;cp php.ini.default php.ini&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And then edit /etc/php.ini to make these two changes:&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;gd&quot;&gt;--- php.ini.default     2008-07-15 14:19:15.000000000 -0500&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+++ php.ini     2008-12-08 21:44:52.000000000 -0600&lt;/span&gt;
&lt;span class=&quot;gu&quot;&gt;@@ -483,7 +483,7 @@&lt;/span&gt;
 user_dir =

 ; Directory in which the loadable extensions (modules) reside.
&lt;span class=&quot;gd&quot;&gt;-extension_dir = &quot;./&quot;&lt;/span&gt;
&lt;span class=&quot;gi&quot;&gt;+;extension_dir = &quot;./&quot;&lt;/span&gt;

 ; 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
&lt;span class=&quot;gu&quot;&gt;@@ -595,6 +595,7 @@&lt;/span&gt;
 ; needs to go here.  Specify the location of the extension with the
 ; extension_dir directive above.

&lt;span class=&quot;gi&quot;&gt;+extension=bcmath.so&lt;/span&gt;

 ; Windows Extensions
 ; Note that ODBC support is built in, so no dll is needed for it.
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After that, I was able to run the &lt;code&gt;amqp_test.php&lt;/code&gt; file for the first time, sending a message and receiving it in py-amqplib&#039;s &lt;code&gt;demo/demo_receive.py&lt;/code&gt;&lt;/p&gt;&lt;/body&gt;</content>
</entry>
</feed>