Skip to content

Commit

Permalink
Orchestra\Support\Manager shouldn't allow name with dotted.
Browse files Browse the repository at this point in the history
* Closes orchestral/acl#13
* Closes orchestral/memory#8
* Part of orchestral/resources#6

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jun 22, 2013
1 parent 7f20e48 commit 3fc39ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Orchestra/Support/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function createDriver($driverName)
{
list($driver, $name) = $this->getDriverName($driverName);

$method = 'create'.ucfirst($driver).'Driver';
$method = 'create'.Str::studly($driver).'Driver';

// We'll check to see if a creator method exists for the given driver.
// If not we will check for a custom driver creator, which allows
Expand Down Expand Up @@ -72,7 +72,14 @@ protected function getDriverName($driverName)
{
if (false === strpos($driverName, '.')) $driverName = $driverName.'.default';

return explode('.', $driverName, 2);
list($driver, $name) = explode('.', $driverName, 2);

if (Str::contains($name, '.'))
{
throw new InvalidArgumentException("Invalid character in driver name [{$name}].");
}

return array($driver, $name);
}

}
13 changes: 13 additions & 0 deletions tests/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ public function testDriverMethodThrowsException()
{
with(new ManagerStub(m::mock('\Illuminate\Foundation\Application')))->driver('invalidDriver');
}

/**
* Test Orchestra\Support\Manager::driver() throws exception when name
* contain dotted.
*
* @expectedException \InvalidArgumentException
*/
public function testDriverMethodGivenNameWithDottedThrowsException()
{
with(new ManagerStub(m::mock('\Illuminate\Foundation\Application')))
->driver('foo.bar.hello');
}
}

class Manager_Foo {
Expand All @@ -62,6 +74,7 @@ public function __construct($app, $name)
$this->name = $name;
}
}

class Manager_Foobar {

public $name = null;
Expand Down

0 comments on commit 3fc39ce

Please sign in to comment.