forked from zfcampus/zf-apigility-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `/apigility/api/dashboard`: - authentication - DB adapters - modules (with REST and RPC service names) - `/apigility/api/settings-dashboard`: - authentication - content negotiation - DB adapters
- Loading branch information
1 parent
91eb039
commit f8ba42c
Showing
4 changed files
with
251 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
<?php | ||
/** | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com) | ||
*/ | ||
|
||
namespace ZF\Apigility\Admin\Controller; | ||
|
||
use Zend\Mvc\Controller\AbstractActionController; | ||
use ZF\Apigility\Admin\Model\AuthenticationEntity; | ||
use ZF\Apigility\Admin\Model\AuthenticationModel; | ||
use ZF\Apigility\Admin\Model\ContentNegotiationModel; | ||
use ZF\Apigility\Admin\Model\DbAdapterModel; | ||
use ZF\Apigility\Admin\Model\ModuleModel; | ||
use ZF\Apigility\Admin\Model\RestServiceModelFactory; | ||
use ZF\Apigility\Admin\Model\RpcServiceModelFactory; | ||
use ZF\ContentNegotiation\ViewModel; | ||
use ZF\Hal\Entity; | ||
use ZF\Hal\Collection; | ||
use ZF\Hal\Link\Link; | ||
|
||
class DashboardController extends AbstractActionController | ||
{ | ||
protected $authentication; | ||
|
||
protected $contentNegotiation; | ||
|
||
protected $dbAdapters; | ||
|
||
protected $modules; | ||
|
||
protected $restServicesFactory; | ||
|
||
protected $rpcServicesFactory; | ||
|
||
public function __construct( | ||
AuthenticationModel $authentication, | ||
ContentNegotiationModel $contentNegotiation, | ||
DbAdapterModel $dbAdapters, | ||
ModuleModel $modules, | ||
RestServiceModelFactory $restServicesFactory, | ||
RpcServiceModelFactory $rpcServicesFactory | ||
) { | ||
$this->authentication = $authentication; | ||
$this->contentNegotiation = $contentNegotiation; | ||
$this->dbAdapters = $dbAdapters; | ||
$this->modules = $modules; | ||
$this->restServicesFactory = $restServicesFactory; | ||
$this->rpcServicesFactory = $rpcServicesFactory; | ||
} | ||
|
||
public function dashboardAction() | ||
{ | ||
$authentication = $this->authentication->fetch(); | ||
if ($authentication) { | ||
$authenticationEntity = $authentication; | ||
$authentication = new Entity($authentication, null); | ||
$authentication->getLinks()->add(Link::factory(array( | ||
'rel' => 'self', | ||
'route' => $this->getRouteForEntity($authenticationEntity), | ||
))); | ||
} | ||
|
||
$dbAdapters = new Collection($this->dbAdapters->fetchAll()); | ||
$dbAdapters->setCollectionRoute('zf-apigility/api/db-adapter'); | ||
|
||
$modules = $this->modules->getModules(); | ||
$map = function ($value) { | ||
return $value->serviceName; | ||
}; | ||
foreach ($modules as $module) { | ||
$name = $module->getName(); | ||
$version = $module->getLatestVersion(); | ||
|
||
$rest = $this->restServicesFactory->factory($name)->fetchAll($version); | ||
$rest = array_map($map, $rest); | ||
|
||
$rpc = $this->rpcServicesFactory->factory($name)->fetchAll($version); | ||
$rpc = array_map($map, $rpc); | ||
|
||
$module->exchangeArray(array( | ||
'rest' => $rest, | ||
'rpc' => $rpc, | ||
)); | ||
} | ||
|
||
$modulesCollection = new Collection($modules); | ||
$modulesCollection->setCollectionRoute('zf-apigility/api/module'); | ||
|
||
$dashboard = array( | ||
'authentication' => $authentication, | ||
'db_adapter' => $dbAdapters, | ||
'module' => $modulesCollection, | ||
); | ||
|
||
$entity = new Entity($dashboard, 'dashboard'); | ||
$links = $entity->getLinks(); | ||
$links->add(Link::factory(array( | ||
'rel' => 'self', | ||
'route' => array( | ||
'name' => 'zf-apigility/api/dashboard', | ||
), | ||
))); | ||
|
||
return new ViewModel(array('payload' => $entity)); | ||
} | ||
|
||
public function settingsDashboardAction() | ||
{ | ||
$authentication = $this->authentication->fetch(); | ||
if ($authentication) { | ||
$authenticationEntity = $authentication; | ||
$authentication = new Entity($authentication, null); | ||
$authentication->getLinks()->add(Link::factory(array( | ||
'rel' => 'self', | ||
'route' => $this->getRouteForEntity($authenticationEntity), | ||
))); | ||
} | ||
|
||
$dbAdapters = new Collection($this->dbAdapters->fetchAll()); | ||
$dbAdapters->setCollectionRoute('zf-apigility/api/db-adapter'); | ||
|
||
$contentNegotiation = new Collection($this->contentNegotiation->fetchAll()); | ||
$contentNegotiation->setCollectionRoute('zf-apigility/api/content-negotiation'); | ||
|
||
$dashboard = array( | ||
'authentication' => $authentication, | ||
'content_negotiation' => $contentNegotiation, | ||
'db_adapter' => $dbAdapters, | ||
); | ||
|
||
$entity = new Entity($dashboard, 'settings-dashboard'); | ||
$links = $entity->getLinks(); | ||
$links->add(Link::factory(array( | ||
'rel' => 'self', | ||
'route' => array( | ||
'name' => 'zf-apigility/api/settings-dashboard', | ||
), | ||
))); | ||
|
||
return new ViewModel(array('payload' => $entity)); | ||
} | ||
|
||
/** | ||
* Determine the route to use for a given entity | ||
* | ||
* Copied from AuthenticationController | ||
* | ||
* @param AuthenticationEntity $entity | ||
* @return string | ||
*/ | ||
protected function getRouteForEntity(AuthenticationEntity $entity) | ||
{ | ||
$baseRoute = 'zf-apigility/api/authentication'; | ||
|
||
if ($entity->isBasic()) { | ||
return $baseRoute . '/http-basic'; | ||
} | ||
|
||
if ($entity->isDigest()) { | ||
return $baseRoute . '/http-digest'; | ||
} | ||
|
||
if ($entity->isOAuth2()) { | ||
return $baseRoute . '/oauth2'; | ||
} | ||
|
||
return $baseRoute; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
/** | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com) | ||
*/ | ||
|
||
namespace ZF\Apigility\Admin\Controller; | ||
|
||
class DashboardControllerFactory | ||
{ | ||
public function __invoke($controllers) | ||
{ | ||
$services = $controllers->getServiceLocator(); | ||
return new DashboardController( | ||
$services->get('ZF\Apigility\Admin\Model\AuthenticationModel'), | ||
$services->get('ZF\Apigility\Admin\Model\ContentNegotiationModel'), | ||
$services->get('ZF\Apigility\Admin\Model\DbAdapterModel'), | ||
$services->get('ZF\Apigility\Admin\Model\ModuleModel'), | ||
$services->get('ZF\Apigility\Admin\Model\RestServiceModelFactory'), | ||
$services->get('ZF\Apigility\Admin\Model\RpcServiceModelFactory') | ||
); | ||
} | ||
} |
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