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 true.
 20:  */
 21: class PropertyTrueCondition implements PropertyConditionInterface
 22: {
 23:     /**
 24:      * The property name.
 25:      *
 26:      * @var string
 27:      */
 28:     protected $propertyName;
 29: 
 30:     /**
 31:      * Use strict compare mode.
 32:      *
 33:      * @var bool
 34:      */
 35:     protected $strict;
 36: 
 37:     /**
 38:      * Create a new instance.
 39:      *
 40:      * @param string $propertyName The name of the property.
 41:      *
 42:      * @param bool   $strict       Flag if the comparison shall be strict (type safe).
 43:      */
 44:     public function __construct($propertyName = '', $strict = false)
 45:     {
 46:         $this->propertyName = (string)$propertyName;
 47:         $this->strict       = (bool)$strict;
 48:     }
 49: 
 50:     /**
 51:      * Set the property name.
 52:      *
 53:      * @param string $propertyName The property name.
 54:      *
 55:      * @return PropertyTrueCondition
 56:      */
 57:     public function setPropertyName($propertyName)
 58:     {
 59:         $this->propertyName = $propertyName;
 60:         return $this;
 61:     }
 62: 
 63:     /**
 64:      * Retrieve the property name.
 65:      *
 66:      * @return string
 67:      */
 68:     public function getPropertyName()
 69:     {
 70:         return $this->propertyName;
 71:     }
 72: 
 73:     /**
 74:      * Set the flag if the comparison shall be strict (type safe).
 75:      *
 76:      * @param boolean $strict The flag.
 77:      *
 78:      * @return PropertyTrueCondition
 79:      */
 80:     public function setStrict($strict)
 81:     {
 82:         $this->strict = $strict;
 83:         return $this;
 84:     }
 85: 
 86:     /**
 87:      * Retrieve the flag if the comparison shall be strict (type safe).
 88:      *
 89:      * @return boolean
 90:      */
 91:     public function getStrict()
 92:     {
 93:         return $this->strict;
 94:     }
 95: 
 96:     /**
 97:      * {@inheritdoc}
 98:      */
 99:     public function match(ModelInterface $model = null, PropertyValueBag $input = null)
100:     {
101:         if ($input && $input->hasPropertyValue($this->propertyName))
102:         {
103:             $value = $input->getPropertyValue($this->propertyName);
104:         }
105:         elseif ($model)
106:         {
107:             $value = $model->getProperty($this->propertyName);
108:         }
109:         else
110:         {
111:             return false;
112:         }
113: 
114:         return $this->strict ? ($value === true) : (bool)$value;
115:     }
116: 
117:     /**
118:      * {@inheritdoc}
119:      */
120:     public function __clone()
121:     {
122:     }
123: }
124: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0