Beispiel #1
0
 /**
  * Check the proxy's method listEnabledStates behavior when there are no enable state.
  */
 public function testListEnabledStatesOfEmpty()
 {
     $this->proxy->registerState('state1', $this->state1);
     $this->proxy->registerState('state3', $this->state3);
     $this->assertEquals(array(), $this->proxy->listEnabledStates());
 }
Beispiel #2
0
 /**
  * To initialize a proxy object with its states. States are fetched by the finder of this stated class.
  *
  * @param ProxyInterface $proxyObject
  * @param string         $stateName
  *
  * @return FactoryInterface
  *
  * @throws Exception\StateNotFound if the $stateName was not found for this stated class
  */
 public function startup(ProxyInterface $proxyObject, string $stateName = null) : FactoryInterface
 {
     //Get all states available
     $statesList = $this->listStatesByClasses();
     //Check if the require state is available
     if (null !== $stateName && !isset($statesList[$stateName])) {
         throw new Exception\StateNotFound(\sprintf('Error, the state "%s" was not found in this stated class', $stateName));
     }
     //Get the main finder of this stated class, to compare it with finders of parents classes
     $mainFinder = $this->getFinder();
     //Load each state into proxy
     foreach ($statesList as $loadingStateName => $finderLoader) {
         //Create new state object by the finder
         $stateObject = $this->buildState($loadingStateName, $finderLoader, $finderLoader !== $mainFinder);
         //Add the state in the proxy
         $proxyObject->registerState($loadingStateName, $stateObject);
     }
     //Switch to required state
     if (null !== $stateName) {
         $proxyObject->switchState($stateName);
     } elseif (isset($statesList[ProxyInterface::DEFAULT_STATE_NAME])) {
         //No required stated name, check if the default state is available and load it
         $proxyObject->switchState(ProxyInterface::DEFAULT_STATE_NAME);
     }
     return $this;
 }