<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Separating Local Code Customizations in PHP</title>
	<atom:link href="http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/</link>
	<description>Knowledge Sharing from Falvey&#039;s Technology Team</description>
	<lastBuildDate>Thu, 14 Mar 2013 19:32:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Demian Katz</title>
		<link>http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/#comment-324</link>
		<dc:creator>Demian Katz</dc:creator>
		<pubDate>Thu, 14 Mar 2013 19:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.library.villanova.edu/libtech/?p=72#comment-324</guid>
		<description><![CDATA[An update -- while I am not using this approach in VuFind 2.0 (the Zend Framework &quot;service locator&quot; mechanism provides greater flexibility), in case anyone else finds it useful in another context, keep in mind that PHP 5.3+ adds a class_alias() function which can be used to map one class to multiple names without resorting to the ugly eval() hack I originally proposed.]]></description>
		<content:encoded><![CDATA[<p>An update &#8212; while I am not using this approach in VuFind 2.0 (the Zend Framework &#8220;service locator&#8221; mechanism provides greater flexibility), in case anyone else finds it useful in another context, keep in mind that PHP 5.3+ adds a class_alias() function which can be used to map one class to multiple names without resorting to the ugly eval() hack I originally proposed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tulie Amichal</title>
		<link>http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/#comment-39</link>
		<dc:creator>Tulie Amichal</dc:creator>
		<pubDate>Tue, 11 Oct 2011 14:24:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.library.villanova.edu/libtech/?p=72#comment-39</guid>
		<description><![CDATA[I Like the new direction. Having the option to extend the core classes and extend them selectively is a great direction.]]></description>
		<content:encoded><![CDATA[<p>I Like the new direction. Having the option to extend the core classes and extend them selectively is a great direction.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Dueber</title>
		<link>http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/#comment-37</link>
		<dc:creator>Bill Dueber</dc:creator>
		<pubDate>Sat, 08 Oct 2011 15:35:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.library.villanova.edu/libtech/?p=72#comment-37</guid>
		<description><![CDATA[PHP, unfortunately, makes it hard to keep stuff in configuration and out of code. You could, however, have a system where (a) the same empty class is always loaded, but (b) users are expected to change where that class inherits from. 

So:

    $a = new TheInstantiatedClass() # in  code


...where the class def looks like

   class TheInstatiatedClass extend TheCoreClass
   {
   }

If you want to override TheCoreClass, the rule is that you do it by changing the &quot;extend&quot; clause and allow the auto-load stuff you explained above to take care of finding it.

It&#039;s more of a BFMI (Brute Force, Massive Ignorance) approach, but has simplicity on its side and doesn&#039;t mess around with what PHP calls metaprogramming. The downside is that it makes it impossible to use both unmodified and modified classes at once.]]></description>
		<content:encoded><![CDATA[<p>PHP, unfortunately, makes it hard to keep stuff in configuration and out of code. You could, however, have a system where (a) the same empty class is always loaded, but (b) users are expected to change where that class inherits from. </p>
<p>So:</p>
<p>    $a = new TheInstantiatedClass() # in  code</p>
<p>&#8230;where the class def looks like</p>
<p>   class TheInstatiatedClass extend TheCoreClass<br />
   {<br />
   }</p>
<p>If you want to override TheCoreClass, the rule is that you do it by changing the &#8220;extend&#8221; clause and allow the auto-load stuff you explained above to take care of finding it.</p>
<p>It&#8217;s more of a BFMI (Brute Force, Massive Ignorance) approach, but has simplicity on its side and doesn&#8217;t mess around with what PHP calls metaprogramming. The downside is that it makes it impossible to use both unmodified and modified classes at once.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Demian Katz</title>
		<link>http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/#comment-35</link>
		<dc:creator>Demian Katz</dc:creator>
		<pubDate>Fri, 07 Oct 2011 12:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.library.villanova.edu/libtech/?p=72#comment-35</guid>
		<description><![CDATA[Just to be sure we&#039;re on the same page, you can instantiate an object of a class using a variable with no problem:

$class = &#039;MyClass&#039;;
$object = new $class();

...but you can&#039;t define a class with a variable:

$parent = &#039;MyClass&#039;;
class SubClass extends $parent { /* ... */ }

It&#039;s the latter case that gets in the way for VuFind...  but if you don&#039;t need to do that, you can probably get away with using variables.]]></description>
		<content:encoded><![CDATA[<p>Just to be sure we&#8217;re on the same page, you can instantiate an object of a class using a variable with no problem:</p>
<p>$class = &#8216;MyClass&#8217;;<br />
$object = new $class();</p>
<p>&#8230;but you can&#8217;t define a class with a variable:</p>
<p>$parent = &#8216;MyClass&#8217;;<br />
class SubClass extends $parent { /* &#8230; */ }</p>
<p>It&#8217;s the latter case that gets in the way for VuFind&#8230;  but if you don&#8217;t need to do that, you can probably get away with using variables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke O'Sullivan</title>
		<link>http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/#comment-33</link>
		<dc:creator>Luke O'Sullivan</dc:creator>
		<pubDate>Fri, 07 Oct 2011 10:03:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.library.villanova.edu/libtech/?p=72#comment-33</guid>
		<description><![CDATA[Thanks for this post Demian - I think it explains the proposed changes very well. However complex the &quot;backend&quot; of the changes are, what a system administrator / programmer will have to do is actually relatively simple - create a custom class / function. This is exactly what they have been doing for VuFind 1.x.

The way that the record drivers and ILS drivers currently work is relatively straight forward when it comes to modifying methods but here we have the option of naming the new php class we wish to call. It would be pretty tedious if we had to do that for every custom class!

Of course, the benefits of the change are much cleaner and non-conflicting code so in essence, it&#039;s a no-brainer.

As you point out and as Jonathan says, I see the code eval() and I immediately think of hell and damnation but as long as one considers the advice given by Uncle Ben to Peter Parker &quot;With great power comes great responsibility&quot;, I&#039;m sure I can get over that.]]></description>
		<content:encoded><![CDATA[<p>Thanks for this post Demian &#8211; I think it explains the proposed changes very well. However complex the &#8220;backend&#8221; of the changes are, what a system administrator / programmer will have to do is actually relatively simple &#8211; create a custom class / function. This is exactly what they have been doing for VuFind 1.x.</p>
<p>The way that the record drivers and ILS drivers currently work is relatively straight forward when it comes to modifying methods but here we have the option of naming the new php class we wish to call. It would be pretty tedious if we had to do that for every custom class!</p>
<p>Of course, the benefits of the change are much cleaner and non-conflicting code so in essence, it&#8217;s a no-brainer.</p>
<p>As you point out and as Jonathan says, I see the code eval() and I immediately think of hell and damnation but as long as one considers the advice given by Uncle Ben to Peter Parker &#8220;With great power comes great responsibility&#8221;, I&#8217;m sure I can get over that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Rochkind</title>
		<link>http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/#comment-32</link>
		<dc:creator>Jonathan Rochkind</dc:creator>
		<pubDate>Thu, 06 Oct 2011 23:54:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.library.villanova.edu/libtech/?p=72#comment-32</guid>
		<description><![CDATA[If you can&#039;t instantiate a class with a name in a string without using &#039;eval&#039;, then that would for me eliminate that technique right off the bat, so there you go. 

I think how you&#039;ve done is probably the neatest way to do it in PHP.]]></description>
		<content:encoded><![CDATA[<p>If you can&#8217;t instantiate a class with a name in a string without using &#8216;eval&#8217;, then that would for me eliminate that technique right off the bat, so there you go. </p>
<p>I think how you&#8217;ve done is probably the neatest way to do it in PHP.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Demian Katz</title>
		<link>http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/#comment-31</link>
		<dc:creator>Demian Katz</dc:creator>
		<pubDate>Thu, 06 Oct 2011 18:52:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.library.villanova.edu/libtech/?p=72#comment-31</guid>
		<description><![CDATA[I had originally thought about the &quot;class name as variable&quot; approach you suggest -- in fact, Zend Framework provides plugin management tools that will return the most appropriate class name given certain parameters and which might help with that sort of implementation.

Two things made me eventually reject that idea, though:

1.) It puts its footprints all over the code -- lots of extra variables everywhere, and potentially extra calls to populate those variables every time you try to construct an object.  The approach detailed in this post is a lot more seamless.

2.) It doesn&#039;t work well when the core code already has class hierarchies in it.  In PHP, you can&#039;t instantiate classes using variable names without using the eval() function (unless I&#039;m missing something).  This means that there&#039;s no easy way to make a subclass extend a variable parent class.  Since VuFind has a lot of base classes that people might want to modify without necessarily changing their subclasses, I don&#039;t think the variable approach is workable.  However, again, the approach detailed in this post works around that problem, as long as your classes extend parent classes from the &quot;Extensible_&quot; namespace rather than the &quot;Core_&quot; namespace.

I can see how that approach might be appropriate in a less complex project, though!]]></description>
		<content:encoded><![CDATA[<p>I had originally thought about the &#8220;class name as variable&#8221; approach you suggest &#8212; in fact, Zend Framework provides plugin management tools that will return the most appropriate class name given certain parameters and which might help with that sort of implementation.</p>
<p>Two things made me eventually reject that idea, though:</p>
<p>1.) It puts its footprints all over the code &#8212; lots of extra variables everywhere, and potentially extra calls to populate those variables every time you try to construct an object.  The approach detailed in this post is a lot more seamless.</p>
<p>2.) It doesn&#8217;t work well when the core code already has class hierarchies in it.  In PHP, you can&#8217;t instantiate classes using variable names without using the eval() function (unless I&#8217;m missing something).  This means that there&#8217;s no easy way to make a subclass extend a variable parent class.  Since VuFind has a lot of base classes that people might want to modify without necessarily changing their subclasses, I don&#8217;t think the variable approach is workable.  However, again, the approach detailed in this post works around that problem, as long as your classes extend parent classes from the &#8220;Extensible_&#8221; namespace rather than the &#8220;Core_&#8221; namespace.</p>
<p>I can see how that approach might be appropriate in a less complex project, though!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Rochkind</title>
		<link>http://blog.library.villanova.edu/libtech/2011/10/05/separating-local-code-customizations-in-php/#comment-30</link>
		<dc:creator>Jonathan Rochkind</dc:creator>
		<pubDate>Thu, 06 Oct 2011 17:57:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.library.villanova.edu/libtech/?p=72#comment-30</guid>
		<description><![CDATA[I guess the other alternative is a more explicit &#039;dependency injection&#039; design, where almost every class name used in code is contained in a variable, and you can change that variable to tell it to use your local version by name.  Where your local version would usually be a sub-class of the core version, I&#039;d figure. 

Man, I wouldn&#039;t want to try and implement that in PHP either.  PHP&#039;s OO facilities are... not my preference to work in. 

You might want to check out Xerxes (the Metalib front-end), Xerxes does a pretty good of keeping local and core code seperate, but Xerxes is much simpler and less flexible software. It basically lets you specify an &#039;action&#039; class for each action (basically each URL path endpoint) in an XML config file, where by default they are the core ones, but you could use your custom ones.  But there&#039;s no way to substitute PHP object classes more granularly than that. 

Xerxes&#039;s &#039;view&#039; layer, for better or worse is all XSLT, and it&#039;s set up so your local XSLT files are loaded in dynamically on top of the core ones, such that you can over-ride the XSLT on a template-by-template basis. (That&#039;s an individual XSLT template; designing the core XSLT to put these templates at the right granularity is the trick).]]></description>
		<content:encoded><![CDATA[<p>I guess the other alternative is a more explicit &#8216;dependency injection&#8217; design, where almost every class name used in code is contained in a variable, and you can change that variable to tell it to use your local version by name.  Where your local version would usually be a sub-class of the core version, I&#8217;d figure. </p>
<p>Man, I wouldn&#8217;t want to try and implement that in PHP either.  PHP&#8217;s OO facilities are&#8230; not my preference to work in. </p>
<p>You might want to check out Xerxes (the Metalib front-end), Xerxes does a pretty good of keeping local and core code seperate, but Xerxes is much simpler and less flexible software. It basically lets you specify an &#8216;action&#8217; class for each action (basically each URL path endpoint) in an XML config file, where by default they are the core ones, but you could use your custom ones.  But there&#8217;s no way to substitute PHP object classes more granularly than that. </p>
<p>Xerxes&#8217;s &#8216;view&#8217; layer, for better or worse is all XSLT, and it&#8217;s set up so your local XSLT files are loaded in dynamically on top of the core ones, such that you can over-ride the XSLT on a template-by-template basis. (That&#8217;s an individual XSLT template; designing the core XSLT to put these templates at the right granularity is the trick).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
