Beispiel #1
0
 /**
  * Autoload a class by name. <b>This function should not be called directly.</b>
  *
  * @internal
  *
  * @param  string  $name  The name of the class to load
  *
  * @return  bool
  */
 public static function autoload($name)
 {
     $names = array($name);
     if (self::$autoload_harder) {
         if (!class_exists(__NAMESPACE__ . '\\Util\\String')) {
             require_once __DIR__ . '/Util/String.php';
         }
         // Break the class name up, so IterableRenderable will search for
         // Iterable and Renderable and MyFooClass will search for My, MyFoo,
         // FooClass and Class.
         // Additional complexity: 2 * (nComponents - 1)
         $parts = \Jerity\Util\String::splitCamelCase($name);
         $the_parts = $parts;
         array_pop($the_parts);
         $accumulator = '';
         foreach ($the_parts as $part) {
             $accumulator .= $part;
             $names[] = $accumulator;
         }
         $the_parts = array_reverse($parts);
         array_pop($the_parts);
         $accumulator = '';
         $new_names = array();
         foreach ($the_parts as $part) {
             $accumulator = $part . $accumulator;
             $new_names[] = $accumulator;
         }
         $names = array_merge($names, array_reverse($new_names));
     }
     foreach ($names as $name) {
         $path = preg_replace('/^\\\\?' . __NAMESPACE__ . '\\\\/', '', $name);
         $path = str_replace('\\', '/', $path);
         foreach (array_keys(self::$autoload_dirs) as $dir) {
             $target_file = $dir . '/' . $path . '.php';
             if (file_exists($target_file)) {
                 include_once $target_file;
                 if (class_exists($name)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Beispiel #2
0
 /**
  * @dataProvider  splitCamelCaseProvider()
  */
 public function testSplitCamelCase($input, $expected)
 {
     $this->assertSame($expected, String::splitCamelCase($input));
 }