forked from piece/piece-flow
-
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.
[PageFlow] introduced the ViewStateInterface and ActionStateInterface…
… interfaces (Issue piece#4)
- Loading branch information
Showing
6 changed files
with
314 additions
and
25 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 |
---|---|---|
|
@@ -37,12 +37,18 @@ | |
|
||
namespace Piece\Flow\PageFlow; | ||
|
||
use Stagehand\FSM\Event\DoEvent; | ||
use Stagehand\FSM\Event\EntryEvent; | ||
use Stagehand\FSM\Event\EventInterface; | ||
use Stagehand\FSM\Event\ExitEvent; | ||
use Stagehand\FSM\StateMachine\StateMachineBuilder; | ||
use Stagehand\FSM\State\StateInterface; | ||
use Symfony\Component\Config\Definition\Processor; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
use Piece\Flow\PageFlow\State\ActionState; | ||
use Piece\Flow\PageFlow\State\ViewState; | ||
|
||
/** | ||
* @package Piece_Flow | ||
* @copyright 2007-2008, 2012-2013 KUBO Atsuhiro <[email protected]> | ||
|
@@ -92,17 +98,26 @@ public function generate() | |
throw new ProtectedStateException("The state [ {$definition['firstState']} ] cannot be used in flow definitions."); | ||
} | ||
|
||
$states = array_merge( | ||
$definition['viewState'], | ||
$definition['actionState'], | ||
empty($definition['lastState']) ? array() : array($definition['lastState']) | ||
); | ||
foreach ($states as $state) { | ||
foreach ($definition['viewState'] as $state) { | ||
if (in_array($state['name'], array(StateInterface::STATE_INITIAL, StateInterface::STATE_FINAL))) { | ||
throw new ProtectedStateException("The state [ {$state['name']} ] cannot be used in flow definitions."); | ||
} | ||
|
||
$this->fsmBuilder->addState($state['name']); | ||
$this->addState(new ViewState($state['name'])); | ||
} | ||
foreach ($definition['actionState'] as $state) { | ||
if (in_array($state['name'], array(StateInterface::STATE_INITIAL, StateInterface::STATE_FINAL))) { | ||
throw new ProtectedStateException("The state [ {$state['name']} ] cannot be used in flow definitions."); | ||
} | ||
|
||
$this->addState(new ActionState($state['name'])); | ||
} | ||
if (!empty($definition['lastState'])) { | ||
if (in_array($definition['lastState']['name'], array(StateInterface::STATE_INITIAL, StateInterface::STATE_FINAL))) { | ||
throw new ProtectedStateException("The state [ {$definition['lastState']['name']} ] cannot be used in flow definitions."); | ||
} | ||
|
||
$this->addState(new ViewState($definition['lastState']['name'])); | ||
} | ||
|
||
if (empty($definition['initial'])) { | ||
|
@@ -118,7 +133,7 @@ public function generate() | |
$this->fsmBuilder->setEndState($definition['lastState']['name'], PageFlowInterface::EVENT_END, $this->wrapAction($definition['final'])); | ||
} | ||
$this->configureViewState($definition['lastState']); | ||
$this->pageFlow->addView($definition['lastState']['name'], $definition['lastState']['view']); | ||
$this->fsmBuilder->getStateMachine()->getState($definition['lastState']['name'])->setView($definition['lastState']['view']); | ||
} | ||
|
||
$this->configureViewStates($definition['viewState']); | ||
|
@@ -139,7 +154,6 @@ protected function configureViewStates(array $states) | |
{ | ||
foreach ($states as $state) { | ||
$this->configureViewState($state); | ||
$this->pageFlow->addView($state['name'], $state['view']); | ||
} | ||
} | ||
|
||
|
@@ -229,6 +243,7 @@ protected function wrapAction(array $action = null) | |
*/ | ||
protected function configureViewState(array $state) | ||
{ | ||
$this->fsmBuilder->getStateMachine()->getState($state['name'])->setView($state['view']); | ||
$this->configureState($state); | ||
} | ||
|
||
|
@@ -268,6 +283,18 @@ protected function readDefinition() | |
array('definition17' => Yaml::parse($this->pageFlowRegistry->getFileName($this->pageFlow->getID()))) | ||
); | ||
} | ||
|
||
/** | ||
* @param \Stagehand\FSM\State\StateInterface $state | ||
* @since Method available since Release 2.0.0 | ||
*/ | ||
protected function addState(StateInterface $state) | ||
{ | ||
$state->setEntryEvent(new EntryEvent()); | ||
$state->setExitEvent(new ExitEvent()); | ||
$state->setDoEvent(new DoEvent()); | ||
$this->fsmBuilder->getStateMachine()->addState($state); | ||
} | ||
} | ||
|
||
/* | ||
|
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,62 @@ | ||
<?php | ||
/* vim: set expandtab tabstop=4 shiftwidth=4: */ | ||
|
||
/** | ||
* PHP version 5.3 | ||
* | ||
* Copyright (c) 2013 KUBO Atsuhiro <[email protected]>, | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @package Piece_Flow | ||
* @copyright 2013 KUBO Atsuhiro <[email protected]> | ||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | ||
* @version Release: @package_version@ | ||
* @since File available since Release 2.0.0 | ||
*/ | ||
|
||
namespace Piece\Flow\PageFlow\State; | ||
|
||
use Stagehand\FSM\State\State; | ||
|
||
/** | ||
* @package Piece_Flow | ||
* @copyright 2013 KUBO Atsuhiro <[email protected]> | ||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | ||
* @version Release: @package_version@ | ||
* @since Class available since Release 2.0.0 | ||
*/ | ||
class ActionState extends State implements ActionStateInterface | ||
{ | ||
} | ||
|
||
/* | ||
* Local Variables: | ||
* mode: php | ||
* coding: iso-8859-1 | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* c-hanging-comment-ender-p: nil | ||
* indent-tabs-mode: nil | ||
* End: | ||
*/ |
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,62 @@ | ||
<?php | ||
/* vim: set expandtab tabstop=4 shiftwidth=4: */ | ||
|
||
/** | ||
* PHP version 5.3 | ||
* | ||
* Copyright (c) 2013 KUBO Atsuhiro <[email protected]>, | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @package Piece_Flow | ||
* @copyright 2013 KUBO Atsuhiro <[email protected]> | ||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | ||
* @version Release: @package_version@ | ||
* @since File available since Release 2.0.0 | ||
*/ | ||
|
||
namespace Piece\Flow\PageFlow\State; | ||
|
||
use Stagehand\FSM\State\StateInterface; | ||
|
||
/** | ||
* @package Piece_Flow | ||
* @copyright 2013 KUBO Atsuhiro <[email protected]> | ||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | ||
* @version Release: @package_version@ | ||
* @since Class available since Release 2.0.0 | ||
*/ | ||
interface ActionStateInterface extends StateInterface | ||
{ | ||
} | ||
|
||
/* | ||
* Local Variables: | ||
* mode: php | ||
* coding: iso-8859-1 | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* c-hanging-comment-ender-p: nil | ||
* indent-tabs-mode: nil | ||
* End: | ||
*/ |
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,82 @@ | ||
<?php | ||
/* vim: set expandtab tabstop=4 shiftwidth=4: */ | ||
|
||
/** | ||
* PHP version 5.3 | ||
* | ||
* Copyright (c) 2013 KUBO Atsuhiro <[email protected]>, | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @package Piece_Flow | ||
* @copyright 2013 KUBO Atsuhiro <[email protected]> | ||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | ||
* @version Release: @package_version@ | ||
* @since File available since Release 2.0.0 | ||
*/ | ||
|
||
namespace Piece\Flow\PageFlow\State; | ||
|
||
use Stagehand\FSM\State\State; | ||
|
||
/** | ||
* @package Piece_Flow | ||
* @copyright 2013 KUBO Atsuhiro <[email protected]> | ||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | ||
* @version Release: @package_version@ | ||
* @since Class available since Release 2.0.0 | ||
*/ | ||
class ViewState extends State implements ViewStateInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $view; | ||
|
||
/** | ||
* @param string $view | ||
*/ | ||
public function setView($view) | ||
{ | ||
$this->view = $view; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getView() | ||
{ | ||
return $this->view; | ||
} | ||
} | ||
|
||
/* | ||
* Local Variables: | ||
* mode: php | ||
* coding: iso-8859-1 | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* c-hanging-comment-ender-p: nil | ||
* indent-tabs-mode: nil | ||
* End: | ||
*/ |
Oops, something went wrong.