for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace rtens\domin;
class ActionRegistry {
/** @var null|AccessControl */
private $access;
/** @var array|Action[] indexed by ID */
private $actions = [];
/**
* @return Action[] indexed by ID
*/
public function getAllActions() {
$actions = $this->actions;
if ($this->access) {
$actions = array_filter($actions, function ($id) {
return $this->access->isVisible($id);
}, ARRAY_FILTER_USE_KEY);
}
return $actions;
* @param string $id
* @return Action
* @throws \Exception
public function getAction($id) {
if (!array_key_exists($id, $this->actions) || $this->access && !$this->access->isVisible($id)) {
throw new \Exception("Action [$id] is not registered.");
return $this->actions[$id];
* @param Action $action
public function add($id, Action $action) {
if (array_key_exists($id, $this->actions)) {
throw new \Exception("Action [$id] is already registered.");
$this->actions[$id] = $action;
return $action;
* @param AccessControl $access
public function restrictAccess(AccessControl $access) {
$this->access = $access;