[wp-trac] [WordPress Trac] #36335: Next generation: core autoloader proposal

WordPress Trac noreply at wordpress.org
Sat Mar 26 10:38:24 UTC 2016


#36335: Next generation: core autoloader proposal
-----------------------------+------------------------------
 Reporter:  dnaber-de        |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  General          |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by tfrommen):

 For testing's sake, the autoloader methods (i.e., the interface as well as
 the implementing classes) should return a status. This would lead to the
 following:

 {{{#!php
 <?php
 interface WP_Autoload_Autoload {

     /**
      * @param WP_Autoload_Rule $autoload_rule
      *
      * @return bool
      */
     public function add_rule( WP_Autoload_Rule $autoload_rule );
 }
 }}}

 and

 {{{#!php
 <?php
 class WP_Autoload_SplAutoload implements WP_Autoload_Autoload {

     /**
      * @var WP_Autoload_Rule[]
      */
     private $rules = array();

     /**
      * @param WP_Autoload_Rule $autoload_rule
      *
      * @return bool
      */
     public function add_rule( WP_Autoload_Rule $autoload_rule ) {

         if ( in_array( $autoload_rule, $this->rules, true ) ) {
             return false;
         }

         $this->rules[] = $autoload_rule;

         return true;
     }

     /**
      * @param string $fqcn (fully qualified class name)
      *
      * @return bool
      */
     public function load_class( $fqcn ) {

         foreach ( $this->rules as $rule ) {
             if ( $rule->load_class( $fqcn ) )
                 return true;
         }

         return false;
     }
 }
 }}}

 I also added a type-hint for the autoloader rule parameter.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36335#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list