Skip to content

Commit

Permalink
fix DI::create() unable to handle Yii-style class alias
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Aug 30, 2023
1 parent efa8418 commit ed5663d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,12 @@
Yii1 Dependency Injection extension
===================================

1.0.3 Under Development
-----------------------

- Bug: Fixed `DI::create()` unable to handle Yii-style class alias (klimov-paul)


1.0.2, August 16, 2023
----------------------

Expand Down
4 changes: 4 additions & 0 deletions src/DI.php
Expand Up @@ -175,6 +175,10 @@ public static function create($config, array $arguments = [])
throw new CException(Yii::t('yii', 'Object configuration must be an array containing a "class" element.'));
}

if (!class_exists($class, false)) {
$class = Yii::import($class, true);
}

$object = static::make($class, $arguments);

foreach ($config as $name => $value) {
Expand Down
12 changes: 12 additions & 0 deletions tests/DITest.php
Expand Up @@ -97,6 +97,18 @@ public function testCreate(): void
$this->assertSame('bar', $object->constructorArgs[0]);
}

/**
* @depends testCreate
*/
public function testCreateWithYiiImport(): void
{
$object = DI::create([
'class' => 'zii.behaviors.CTimestampBehavior',
]);

$this->assertFalse(empty($object));
}

/**
* @depends testSetupContainer
*/
Expand Down

0 comments on commit ed5663d

Please sign in to comment.