|
43 | 43 | * @since File available since Release 1.0.0
|
44 | 44 | */
|
45 | 45 |
|
46 |
| -function phpunit_story_autoload($class = NULL) { |
47 |
| - static $classes = NULL; |
48 |
| - static $path = NULL; |
| 46 | +spl_autoload_register( |
| 47 | + function ($class) { |
| 48 | + static $classes = NULL; |
| 49 | + static $path = NULL; |
49 | 50 |
|
50 |
| - if ($classes === NULL) { |
51 |
| - $classes = array( |
52 |
| - 'phpunit_extensions_story_given' => '/Extensions/Story/Given.php', |
53 |
| - 'phpunit_extensions_story_resultprinter' => '/Extensions/Story/ResultPrinter.php', |
54 |
| - 'phpunit_extensions_story_resultprinter_html' => '/Extensions/Story/ResultPrinter/HTML.php', |
55 |
| - 'phpunit_extensions_story_resultprinter_text' => '/Extensions/Story/ResultPrinter/Text.php', |
56 |
| - 'phpunit_extensions_story_scenario' => '/Extensions/Story/Scenario.php', |
57 |
| - 'phpunit_extensions_story_step' => '/Extensions/Story/Step.php', |
58 |
| - 'phpunit_extensions_story_testcase' => '/Extensions/Story/TestCase.php', |
59 |
| - 'phpunit_extensions_story_then' => '/Extensions/Story/Then.php', |
60 |
| - 'phpunit_extensions_story_when' => '/Extensions/Story/When.php' |
61 |
| - ); |
| 51 | + if ($classes === NULL) { |
| 52 | + $classes = array( |
| 53 | + 'phpunit_extensions_story_given' => '/Extensions/Story/Given.php', |
| 54 | + 'phpunit_extensions_story_resultprinter' => '/Extensions/Story/ResultPrinter.php', |
| 55 | + 'phpunit_extensions_story_resultprinter_html' => '/Extensions/Story/ResultPrinter/HTML.php', |
| 56 | + 'phpunit_extensions_story_resultprinter_text' => '/Extensions/Story/ResultPrinter/Text.php', |
| 57 | + 'phpunit_extensions_story_scenario' => '/Extensions/Story/Scenario.php', |
| 58 | + 'phpunit_extensions_story_step' => '/Extensions/Story/Step.php', |
| 59 | + 'phpunit_extensions_story_testcase' => '/Extensions/Story/TestCase.php', |
| 60 | + 'phpunit_extensions_story_then' => '/Extensions/Story/Then.php', |
| 61 | + 'phpunit_extensions_story_when' => '/Extensions/Story/When.php' |
| 62 | + ); |
62 | 63 |
|
63 |
| - $path = dirname(dirname(dirname(__FILE__))); |
64 |
| - } |
| 64 | + $path = dirname(dirname(dirname(__FILE__))); |
| 65 | + } |
65 | 66 |
|
66 |
| - if ($class === NULL) { |
67 |
| - $result = array(__FILE__); |
| 67 | + $cn = strtolower($class); |
68 | 68 |
|
69 |
| - foreach ($classes as $file) { |
70 |
| - $result[] = $path . $file; |
71 |
| - } |
72 |
| - |
73 |
| - return $result; |
74 |
| - } |
75 |
| - |
76 |
| - $cn = strtolower($class); |
77 |
| - |
78 |
| - if (isset($classes[$cn])) { |
79 |
| - $file = $path . $classes[$cn]; |
80 |
| - |
81 |
| - require $file; |
82 |
| - } |
83 |
| -} |
84 |
| - |
85 |
| -spl_autoload_register('phpunit_story_autoload'); |
| 69 | + if (isset($classes[$cn])) { |
| 70 | + require $path . $classes[$cn]; |
| 71 | + } |
| 72 | + } |
| 73 | +); |
0 commit comments