-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added registry for community-manager
1 parent
05ad529
commit 18259dd
Showing
7 changed files
with
143 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\CommunityBundle\Manager; | ||
|
||
class CommunityManagerRegistry implements CommunityManagerRegistryInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $managers; | ||
|
||
/** | ||
* @param CommunityManagerInterface[] $managers | ||
*/ | ||
public function __construct(array $managers = []) | ||
{ | ||
$this->managers = $managers; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get($webspaceKey) | ||
{ | ||
if (!$this->has($webspaceKey)) { | ||
throw new \Exception( | ||
sprintf( | ||
'Webspace "%s" is not configured.', | ||
$webspaceKey | ||
) | ||
); | ||
} | ||
|
||
return $this->managers[$webspaceKey]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function has($webspaceKey) | ||
{ | ||
return array_key_exists($webspaceKey, $this->managers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\CommunityBundle\Manager; | ||
|
||
interface CommunityManagerRegistryInterface | ||
{ | ||
/** | ||
* @param string $webspaceKey | ||
* | ||
* @return CommunityManagerInterface | ||
*/ | ||
public function get($webspaceKey); | ||
|
||
/** | ||
* @param string $webspaceKey | ||
* | ||
* @return bool | ||
*/ | ||
public function has($webspaceKey); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\CommunityBundle\Tests\Unit\Manager; | ||
|
||
use Sulu\Bundle\CommunityBundle\Manager\CommunityManager; | ||
use Sulu\Bundle\CommunityBundle\Manager\CommunityManagerRegistry; | ||
|
||
class CommunityManagerRegistryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testGet() | ||
{ | ||
$manager = $this->prophesize(CommunityManager::class); | ||
$registry = new CommunityManagerRegistry(['sulu_io' => $manager->reveal()]); | ||
|
||
$this->assertEquals($manager->reveal(), $registry->get('sulu_io')); | ||
} | ||
|
||
public function testGetNotExists() | ||
{ | ||
$this->expectException(\Exception::class); | ||
|
||
$registry = new CommunityManagerRegistry(); | ||
|
||
$registry->get('sulu_io'); | ||
} | ||
|
||
public function testHas() | ||
{ | ||
$manager = $this->prophesize(CommunityManager::class); | ||
$registry = new CommunityManagerRegistry(['sulu_io' => $manager->reveal()]); | ||
|
||
$this->assertTrue($registry->has('sulu_io')); | ||
$this->assertFalse($registry->has('test_io')); | ||
} | ||
} |