Overview

Namespaces

  • DcGeneral
    • Clipboard
    • Contao
      • Callback
      • Compatibility
      • DataDefinition
        • Definition
      • Dca
        • Builder
          • Legacy
        • Definition
        • Palette
        • Populator
      • Event
      • View
        • Contao2BackendView
          • Event
    • Controller
    • Data
    • DataDefinition
      • Builder
      • Definition
        • Properties
        • View
          • Panel
      • ModelRelationship
      • Palette
        • Builder
          • Event
        • Condition
          • Palette
          • Property
    • EnvironmentPopulator
    • Event
    • Exception
    • Factory
      • Event
    • Panel
    • View
      • Event

Classes

  • BooleanCondition
  • NotCondition
  • PropertyConditionChain
  • PropertyFalseCondition
  • PropertyTrueCondition
  • PropertyValueCondition

Interfaces

  • PropertyConditionInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * PHP version 5
  4:  * @package    generalDriver
  5:  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  6:  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
  7:  * @author     Tristan Lins <tristan.lins@bit3.de>
  8:  * @copyright  The MetaModels team.
  9:  * @license    LGPL.
 10:  * @filesource
 11:  */
 12: 
 13: namespace DcGeneral\DataDefinition\Palette\Condition\Property;
 14: 
 15: use DcGeneral\Data\ModelInterface;
 16: use DcGeneral\Data\PropertyValueBag;
 17: 
 18: /**
 19:  * Condition checking that the value of a property is the same as a passed value.
 20:  */
 21: class PropertyValueCondition implements PropertyConditionInterface
 22: {
 23:     /**
 24:      * The property name.
 25:      *
 26:      * @var string
 27:      */
 28:     protected $propertyName;
 29: 
 30:     /**
 31:      * The expected property value.
 32:      *
 33:      * @var mixed
 34:      */
 35:     protected $propertyValue;
 36: 
 37:     /**
 38:      * Use strict compare mode.
 39:      *
 40:      * @var bool
 41:      */
 42:     protected $strict;
 43: 
 44:     /**
 45:      * Create a new instance.
 46:      *
 47:      * @param string $propertyName  The name of the property.
 48:      *
 49:      * @param mixed  $propertyValue The value of the property to match.
 50:      *
 51:      * @param bool   $strict        Flag if the comparison shall be strict (type safe).
 52:      */
 53:     public function __construct($propertyName = '', $propertyValue = null, $strict = false)
 54:     {
 55:         $this->propertyName  = (string)$propertyName;
 56:         $this->propertyValue = $propertyValue;
 57:         $this->strict        = (bool)$strict;
 58:     }
 59: 
 60:     /**
 61:      * Set the property name.
 62:      *
 63:      * @param string $propertyName The property name.
 64:      *
 65:      * @return PropertyValueCondition
 66:      */
 67:     public function setPropertyName($propertyName)
 68:     {
 69:         $this->propertyName = (string)$propertyName;
 70:         return $this;
 71:     }
 72: 
 73:     /**
 74:      * Retrieve the property name.
 75:      *
 76:      * @return string
 77:      */
 78:     public function getPropertyName()
 79:     {
 80:         return $this->propertyName;
 81:     }
 82: 
 83:     /**
 84:      * Set the property value to match.
 85:      *
 86:      * @param mixed $propertyValue The value.
 87:      *
 88:      * @return PropertyValueCondition
 89:      */
 90:     public function setPropertyValue($propertyValue)
 91:     {
 92:         $this->propertyValue = $propertyValue;
 93:         return $this;
 94:     }
 95: 
 96:     /**
 97:      * Retrieve the property value to match.
 98:      *
 99:      * @return mixed
100:      */
101:     public function getPropertyValue()
102:     {
103:         return $this->propertyValue;
104:     }
105: 
106:     /**
107:      * Set the flag if the comparison shall be strict (type safe).
108:      *
109:      * @param boolean $strict The flag.
110:      *
111:      * @return PropertyValueCondition
112:      */
113:     public function setStrict($strict)
114:     {
115:         $this->strict = (bool)$strict;
116:         return $this;
117:     }
118: 
119:     /**
120:      * Retrieve the flag if the comparison shall be strict (type safe).
121:      *
122:      * @return boolean
123:      */
124:     public function getStrict()
125:     {
126:         return $this->strict;
127:     }
128: 
129:     /**
130:      * {@inheritdoc}
131:      */
132:     public function match(ModelInterface $model = null, PropertyValueBag $input = null)
133:     {
134:         if ($input && $input->hasPropertyValue($this->propertyName))
135:         {
136:             $value = $input->getPropertyValue($this->propertyName);
137:         }
138:         elseif ($model)
139:         {
140:             $value = $model->getProperty($this->propertyName);
141:         }
142:         else
143:         {
144:             return false;
145:         }
146: 
147:         return $this->strict ? ($value === $this->propertyValue) : ($value == $this->propertyValue);
148:     }
149: 
150:     /**
151:      * {@inheritdoc}
152:      */
153:     public function __clone()
154:     {
155:     }
156: }
157: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0