/** * {@inheritdoc} */ public function isAllow(StateInterface $state, Graph $graph, $authorizationMask) { $acceptedMasks = 0; foreach ($this->stateKeys as $stateKey) { $acceptedMasks |= $graph->getState($stateKey)->getMask(); } return parent::isAllow($state, $graph, $authorizationMask) && ($state->getMask() & $acceptedMasks) === $state->getMask(); }
/** * Returns authorized states for an object using the state mapping. * * @return array(<string>) */ public function getAuthorizedStates() { $authorizationMask = $this->graph->getAuthorizationMask($this->object); $objectState = $this->graph->getState($this->readProperty()); $states = array(); foreach ($this->graph->getStates() as $key => $state) { if ($objectState->isAllow($state, $this->graph, $authorizationMask)) { $states[] = $key; } } return $states; }
/** * @dataProvider dataProviderIsAllow */ public function testIsAllow(array $states, $defaultState, $stateCollection, array $authorizedStates) { $graph = new Graph(); foreach ($states as $i => $state) { $spec = "spec" . $i; ${$spec} = new \mock\Rezzza\Workflow\Specification\SpecificationInterface(); ${$spec}->getMockController()->isSatisfiedBy = (bool) $state; $graph->addState(sprintf('state%s', $i + 1), new TestedClass($stateCollection, ${$spec})); } $data = new \stdClass(); $data->state = $defaultState; $workflow = new Workflow($graph, $data, 'state'); $this->array($workflow->getAuthorizedStates())->isIdenticalTo($authorizedStates); }
/** * {@inheritdoc} */ public function isAllow(StateInterface $state, Graph $graph, $authorizationMask) { $untilMask = $graph->getState($this->untilKey)->getMask(); return parent::isAllow($state, $graph, $authorizationMask) && $this->getMask() < $state->getMask() && $state->getMask() <= $untilMask; }