Skip to content

Commit

Permalink
Fix regression in handling of suppressed constructors, fixes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jul 31, 2013
1 parent 777e427 commit 2251ec9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Nelmio/Alice/Loader/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,18 @@ public function load($data)
list($to, $from) = array($from, $to);
}
for ($i = $from; $i <= $to; $i++) {
$curSpec = $spec;
$curName = str_replace($match[0], $i, $name);
list($curName, $instanceFlags) = $this->parseFlags($curName);
$instances[] = array($this->createInstance($class, $curName, $spec), $class, $curName, $spec, $classFlags, $instanceFlags, $i);
$instances[] = array($this->createInstance($class, $curName, $curSpec), $class, $curName, $curSpec, $classFlags, $instanceFlags, $i);
}
} elseif (preg_match('#\{([^,]+(\s*,\s*[^,]+)*)\}#', $name, $match)) {
$enumItems = array_map('trim', explode(',', $match[1]));
foreach ($enumItems as $item) {
$curSpec = $spec;
$curName = str_replace($match[0], $item, $name);
list($curName, $instanceFlags) = $this->parseFlags($curName);
$instances[] = array($this->createInstance($class, $curName, $spec), $class, $curName, $spec, $classFlags, $instanceFlags, $item);
$instances[] = array($this->createInstance($class, $curName, $curSpec), $class, $curName, $curSpec, $classFlags, $instanceFlags, $item);
}
} else {
list($name, $instanceFlags) = $this->parseFlags($name);
Expand Down
6 changes: 3 additions & 3 deletions tests/Nelmio/Alice/Loader/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,18 +658,18 @@ public function testLoadCanBypassConstructorsWithRequiredArgs()
),
),
self::CONTACT => array(
'contact' => array(
'contact{1..2}' => array(
'__construct' => false,
'user' => '@user',
),
),
));

$this->assertInstanceOf(self::USER, $this->loader->getReference('user'));
$this->assertInstanceOf(self::CONTACT, $this->loader->getReference('contact'));
$this->assertInstanceOf(self::CONTACT, $this->loader->getReference('contact1'));
$this->assertSame(
$this->loader->getReference('user'),
$this->loader->getReference('contact')->getUser()
$this->loader->getReference('contact1')->getUser()
);
}

Expand Down

0 comments on commit 2251ec9

Please sign in to comment.