PageRenderTime 33ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/ezcomponents/Workflow/src/nodes/variables/unset.php

http://hppg.googlecode.com/
PHP | 126 lines | 51 code | 12 blank | 63 comment | 2 complexity | aeec259a9b37b1410272882b444275d5 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * File containing the ezcWorkflowNodeVariableUnset class.
  4. *
  5. * @package Workflow
  6. * @version 1.4.1
  7. * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
  8. * @license http://ez.no/licenses/new_bsd New BSD License
  9. */
  10. /**
  11. * An object of the ezcWorkflowNodeVariableUnset class unset the specified workflow variable.
  12. *
  13. * <code>
  14. * <?php
  15. * $unset = new ezcWorkflowNodeVariableUnset( 'variable name' );
  16. * ?>
  17. * </code>
  18. *
  19. * Incoming nodes: 1
  20. * Outgoing nodes: 1
  21. *
  22. * @package Workflow
  23. * @version 1.4.1
  24. */
  25. class ezcWorkflowNodeVariableUnset extends ezcWorkflowNode
  26. {
  27. /**
  28. * Constructs a new unset node.
  29. *
  30. * Configuration format:
  31. * String:
  32. * The name of the workflow variable to unset.
  33. *
  34. * Array:
  35. * An array of names of the workflow variables to unset.
  36. *
  37. * @param mixed $configuration
  38. * @throws ezcBaseValueException
  39. */
  40. public function __construct( $configuration = '' )
  41. {
  42. if ( is_string( $configuration ) )
  43. {
  44. $configuration = array( $configuration );
  45. }
  46. if ( !is_array( $configuration ) )
  47. {
  48. throw new ezcBaseValueException(
  49. 'configuration', $configuration, 'array'
  50. );
  51. }
  52. parent::__construct( $configuration );
  53. }
  54. /**
  55. * Executes this node.
  56. *
  57. * @param ezcWorkflowExecution $execution
  58. * @return boolean true when the node finished execution,
  59. * and false otherwise
  60. * @ignore
  61. */
  62. public function execute( ezcWorkflowExecution $execution )
  63. {
  64. foreach ( $this->configuration as $variable )
  65. {
  66. $execution->unsetVariable( $variable );
  67. }
  68. $this->activateNode( $execution, $this->outNodes[0] );
  69. return parent::execute( $execution );
  70. }
  71. /**
  72. * Generate node configuration from XML representation.
  73. *
  74. * @param DOMElement $element
  75. * @return array
  76. * @ignore
  77. */
  78. public static function configurationFromXML( DOMElement $element )
  79. {
  80. $configuration = array();
  81. foreach ( $element->getElementsByTagName( 'variable' ) as $variable )
  82. {
  83. $configuration[] = $variable->getAttribute( 'name' );
  84. }
  85. return $configuration;
  86. }
  87. /**
  88. * Generate XML representation of this node's configuration.
  89. *
  90. * @param DOMElement $element
  91. * @ignore
  92. */
  93. public function configurationToXML( DOMElement $element )
  94. {
  95. foreach ( $this->configuration as $variable )
  96. {
  97. $variableXml = $element->appendChild(
  98. $element->ownerDocument->createElement( 'variable' )
  99. );
  100. $variableXml->setAttribute( 'name', $variable );
  101. }
  102. }
  103. /**
  104. * Returns a textual representation of this node.
  105. *
  106. * @return string
  107. * @ignore
  108. */
  109. public function __toString()
  110. {
  111. return 'unset(' . implode( ', ', $this->configuration ) . ')';
  112. }
  113. }
  114. ?>