Example #1
0
 /**
  * Register a file into memory and return an instantiated object.
  *
  * @uses Titon\Utility\Path
  *
  * @param string $key
  * @param array $params
  * @param bool $store
  * @return object
  */
 public static function &factory($key, array $params = [], $store = true)
 {
     if (static::has($key)) {
         return static::get($key);
     }
     $namespace = Path::toNamespace($key);
     $reflection = new ReflectionClass($namespace);
     $object = $reflection->newInstanceArgs($params);
     if ($store) {
         $object = static::set($object, $key);
     }
     return $object;
 }
Example #2
0
 /**
  * Test that converting a path to a namespace package works correctly.
  */
 public function testToNamespace()
 {
     $this->assertEquals('test\\file\\path\\FileName', Path::toNamespace('/test/file/path/FileName.php'));
     $this->assertEquals('test\\file\\path\\File\\Name', Path::toNamespace('/test/file/path/File/Name.php'));
     $this->assertEquals('test\\file\\path\\FileName', Path::toNamespace('vendors/src/test/file/path/FileName.php'));
     $this->assertEquals('Titon\\test\\file\\path\\File\\Name', Path::toNamespace('vendors/src/Titon/test/file/path/File/Name.php'));
 }