PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/Workflow/src/conditions/in_array.php

https://github.com/Yannix/zetacomponents
PHP | 85 lines | 20 code | 5 blank | 60 comment | 1 complexity | 39df34e68c5f6b9af9c2de4723badb50 MD5 | raw file
  1. <?php
  2. /**
  3. * File containing the ezcWorkflowConditionInArray 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. * Condition that checks if a value is in an array.
  28. *
  29. * Typically used together with ezcWorkflowConditionVariable to use the
  30. * condition on a workflow variable.
  31. *
  32. * <code>
  33. * <?php
  34. * $condition = new ezcWorkflowConditionVariable(
  35. * 'variable name',
  36. * new ezcWorkflowConditionInArray( array( ... ) )
  37. * );
  38. * ?>
  39. * </code>
  40. *
  41. * @package Workflow
  42. * @version //autogen//
  43. */
  44. class ezcWorkflowConditionInArray extends ezcWorkflowConditionComparison
  45. {
  46. /**
  47. * Textual representation of the comparison operator.
  48. *
  49. * @var mixed
  50. */
  51. protected $operator = 'in array';
  52. /**
  53. * Evaluates this condition with $value and returns true if it is false or false if it is not.
  54. *
  55. * @param mixed $value
  56. * @return boolean true when the condition holds, false otherwise.
  57. * @ignore
  58. */
  59. public function evaluate( $value )
  60. {
  61. return in_array( $value, $this->value );
  62. }
  63. /**
  64. * Returns a textual representation of this condition.
  65. *
  66. * @return string
  67. * @ignore
  68. */
  69. public function __toString()
  70. {
  71. $array = $this->value;
  72. $count = count( $array );
  73. for ( $i = 0; $i < $count; $i++ )
  74. {
  75. $array[$i] = var_export( $array[$i], true );
  76. }
  77. return $this->operator . '(' . join( ', ', $array ) . ')';
  78. }
  79. }
  80. ?>