[wp-trac] [WordPress Trac] #14814: Allow WP XML-RPC Library to be Extended

WordPress Trac wp-trac at lists.automattic.com
Wed Sep 8 15:33:37 UTC 2010


#14814: Allow WP XML-RPC Library to be Extended
--------------------------+-------------------------------------------------
 Reporter:  filosofo      |       Owner:  filosofo 
     Type:  defect (bug)  |      Status:  assigned 
 Priority:  normal        |   Milestone:  3.1      
Component:  XML-RPC       |     Version:  3.1      
 Severity:  normal        |    Keywords:  has-patch
--------------------------+-------------------------------------------------

Comment(by Denis-de-Bernardy):

 Replying to [comment:6 filosofo]:
 > Replying to [comment:5 Denis-de-Bernardy]:
 > > Maybe be we could add a lazy-loaded dependency injection...
 > I'm not sure exactly what you have in mind, but it's probably worth
 having a separate ticket for it.

 Googling helps :-)

 http://www.google.com/search?q=dependency+injection+php

 > I'm trying to do something really simple with this ticket, basically
 just cut-n-paste except for the filter on the server class name.

 I had something similar to what's done in the patch, but more like:

 {{{
 # in plugin file:
 function my_xmlrpc_server($class) {
     require_once 'my_xmlrpc_server.php';
     return $my_xmlrpc_server;
 }
 add_filter('xmlrpc_server_class', 'my_xmlrpc_server');

 # at the end of the default xmlrpc server file:
 $xmlrpc_server_class = apply_filters('xmlrpc_server_class',
 'xmlrpc_server');
 $xmlrpc_server = new $xmlrpc_server_class;
 }}}

 The file is lazy loaded already, so it's not much of a big deal.

 In other apps, the lazy loaded part generally looks like this:

 {{{
 class Foo {
   static $adapters = array('storage' => 'default');

   ...

   function doStuff() {
     $storage = Storage::get(self::$adapters['storage]);
   }
 }

 Foo::config(array('storage' => 'memcache')); // override the default

 class Storage { // typically inherits from a base class that does this
   static $adapters =array(
     'default' => 'MemoryStorage',
     'memcache' => 'MemcacheStorage'
     );
   static function get($adapter) {
     $class = self::$adapters[$adapter];
     // only autoload and instantiate the class if it gets used
     return is_object($class) ? $class : new $class;
   }
 }
 }}}

 the same could be done for quite a few other classes. e.g. wpdb, locale-
 related stuff, etc.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14814#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list