Development

Changeset 1204

You must first sign up to be able to contribute.

Changeset 1204

Show
Ignore:
Timestamp:
04/14/06 08:11:54 (4 years ago)
Author:
fabien
Message:

added a more configurable autoloading feature

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/data/config/settings.yml

    r1155 r1204  
    7373    validation_error_class:     form_error 
    7474    validation_error_id_prefix: error_for_ 
     75 
     76    autoloading_functions: ~ 
  • trunk/lib/symfony.php

    r1038 r1204  
    5555} 
    5656 
    57 /** 
    58  * Handles autoloading of classes that have been specified in autoload.yml. 
    59  * 
    60  * @param string A class name. 
    61  * 
    62  * @return void 
    63  */ 
    64 if (!function_exists('__autoload')) 
    65 
    66   function __autoload($class) 
     57class Symfony 
     58
     59  public static function autoload($class) 
    6760  { 
    6861    static $loaded; 
     
    9184            require_once($module_lib); 
    9285 
    93             return
     86            return true
    9487          } 
    9588        } 
    9689      } 
    9790 
    98       // unspecified class 
    99       $error = sprintf('Autoloading of class "%s" failed. Try to clear the symfony cache and refresh. [err0003]', $class); 
    100       $e = new sfAutoloadException($error); 
    101  
    102       $e->printStackTrace(); 
     91      return false; 
    10392    } 
    10493    else 
     
    10695      // class exists, let's include it 
    10796      require_once($classes[$class]); 
    108     } 
     97 
     98      return true; 
     99    } 
     100  } 
     101
     102 
     103/** 
     104 * Handles autoloading of classes that have been specified in autoload.yml. 
     105 * 
     106 * @param string A class name. 
     107 * 
     108 * @return void 
     109 */ 
     110if (!function_exists('__autoload')) 
     111
     112  function __autoload($class) 
     113  { 
     114    static $functions; 
     115 
     116    if (!$functions) 
     117    { 
     118      // load functions and methods that can autoload classes 
     119      $functions = is_array(sfConfig::get('sf_autoloading_functions')) ? sfConfig::get('sf_autoloading_functions') : array(); 
     120      array_unshift($functions, array('Symfony', 'autoload')); 
     121    } 
     122 
     123    foreach ($functions as $function) 
     124    { 
     125      if (call_user_func($function, $class)) 
     126      { 
     127        return true; 
     128      } 
     129    } 
     130 
     131    // unspecified class 
     132    $error = sprintf('Autoloading of class "%s" failed. Try to clear the symfony cache and refresh. [err0003]', $class); 
     133    $e = new sfAutoloadException($error); 
     134 
     135    $e->printStackTrace(); 
    109136  } 
    110137} 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.