Project

General

Profile

opTestLoader.class.php

Hidenori Goto, 2010-09-24 19:48

Download (1.09 KB)

 
1
<?php
2
class opTestLoader
3
{
4
  /**
5
   * Autoload classes.
6
   * This method replaces Zend_Loader::registerAutoload() because it's been deprecated from zf 1.8.0
7
   * and will be removed from 2.0.0.
8
   *
9
   * @param string $class
10
   * @param mixed $enabled
11
   * @return
12
   */
13
  public static function registerAutoload($class = 'Zend_Loader', $enabled = true)
14
  {
15
    require_once 'Zend/Loader/Autoloader.php';
16
    $autoloader = Zend_Loader_Autoloader::getInstance();
17
    $autoloader->setFallbackAutoloader(true);
18

    
19
    if ('Zend_Loader' != $class)
20
    {
21
      Zend_Loader::loadClass($class);
22
      $methods = get_class_methods($class);
23
      if (!in_array('autoload', (array) $methods))
24
      {
25
        require_once 'Zend/Exception.php';
26
        throw new Zend_Exception("The class \"$class\" does not have an autoload() method");
27
      }
28

    
29
      $callback = array($class, 'autoload');
30

    
31
      if ($enabled)
32
      {
33
        $autoloader->pushAutoloader($callback);
34
      } else
35
      {
36
        $autoloader->removeAutoloader($callback);
37
      }
38
    }
39
    else
40
    {
41
      Zend_Loader_Autoloader::resetInstance();
42
    }
43
  }
44
}