PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/Yannix/zetacomponents
PHP | 142 lines | 51 code | 12 blank | 79 comment | 2 complexity | 014e3c6e7f94648efc70853924cafb29 MD5 | raw file
  1. <?php
  2. /**
  3. * File containing the ezcWorkflowNodeVariableUnset class.
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Workflow
  23. * @version //autogen//
  24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25. */
  26. /**
  27. * An object of the ezcWorkflowNodeVariableUnset class unset the specified workflow variable.
  28. *
  29. * <code>
  30. * <?php
  31. * $unset = new ezcWorkflowNodeVariableUnset( 'variable name' );
  32. * ?>
  33. * </code>
  34. *
  35. * Incoming nodes: 1
  36. * Outgoing nodes: 1
  37. *
  38. * @package Workflow
  39. * @version //autogen//
  40. */
  41. class ezcWorkflowNodeVariableUnset extends ezcWorkflowNode
  42. {
  43. /**
  44. * Constructs a new unset node.
  45. *
  46. * Configuration format:
  47. * String:
  48. * The name of the workflow variable to unset.
  49. *
  50. * Array:
  51. * An array of names of the workflow variables to unset.
  52. *
  53. * @param mixed $configuration
  54. * @throws ezcBaseValueException
  55. */
  56. public function __construct( $configuration = '' )
  57. {
  58. if ( is_string( $configuration ) )
  59. {
  60. $configuration = array( $configuration );
  61. }
  62. if ( !is_array( $configuration ) )
  63. {
  64. throw new ezcBaseValueException(
  65. 'configuration', $configuration, 'array'
  66. );
  67. }
  68. parent::__construct( $configuration );
  69. }
  70. /**
  71. * Executes this node.
  72. *
  73. * @param ezcWorkflowExecution $execution
  74. * @return boolean true when the node finished execution,
  75. * and false otherwise
  76. * @ignore
  77. */
  78. public function execute( ezcWorkflowExecution $execution )
  79. {
  80. foreach ( $this->configuration as $variable )
  81. {
  82. $execution->unsetVariable( $variable );
  83. }
  84. $this->activateNode( $execution, $this->outNodes[0] );
  85. return parent::execute( $execution );
  86. }
  87. /**
  88. * Generate node configuration from XML representation.
  89. *
  90. * @param DOMElement $element
  91. * @return array
  92. * @ignore
  93. */
  94. public static function configurationFromXML( DOMElement $element )
  95. {
  96. $configuration = array();
  97. foreach ( $element->getElementsByTagName( 'variable' ) as $variable )
  98. {
  99. $configuration[] = $variable->getAttribute( 'name' );
  100. }
  101. return $configuration;
  102. }
  103. /**
  104. * Generate XML representation of this node's configuration.
  105. *
  106. * @param DOMElement $element
  107. * @ignore
  108. */
  109. public function configurationToXML( DOMElement $element )
  110. {
  111. foreach ( $this->configuration as $variable )
  112. {
  113. $variableXml = $element->appendChild(
  114. $element->ownerDocument->createElement( 'variable' )
  115. );
  116. $variableXml->setAttribute( 'name', $variable );
  117. }
  118. }
  119. /**
  120. * Returns a textual representation of this node.
  121. *
  122. * @return string
  123. * @ignore
  124. */
  125. public function __toString()
  126. {
  127. return 'unset(' . implode( ', ', $this->configuration ) . ')';
  128. }
  129. }
  130. ?>