# PrimitiveTernary.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /****************************************************************************
    00003  *   Copyright (C) 2006-2007 by Dmitry E. Demidov                           *
    00004  *                                                                          *
    00005  *   This program is free software; you can redistribute it and/or modify   *
    00006  *   it under the terms of the GNU Lesser General Public License as         *
    00007  *   published by the Free Software Foundation; either version 3 of the     *
    00008  *   License, or (at your option) any later version.                        *
    00009  *                                                                          *
    00010  ****************************************************************************/
    00011
    00015     final class PrimitiveTernary extends BasePrimitive
    00016     {
    00017         private $falseValue     = 0;
    00018         private $trueValue      = 1;
    00019
    00023         public function setTrueValue($trueValue)
    00024         {
    00025             $this->trueValue = $trueValue;
    00026
    00027             return $this;
    00028         }
    00029
    00033         public function setFalseValue($falseValue)
    00034         {
    00035             $this->falseValue = $falseValue;
    00036
    00037             return $this;
    00038         }
    00039
    00040         public function import($scope)
    00041         {
    00042             if (isset($scope[$this->name])) {
    00043                 if ($this->trueValue == $scope[$this->name])
    00044                     $this->value = true;
    00045                 elseif ($this->falseValue == $scope[$this->name])
    00046                     $this->value = false;
    00047                 else
    00048                     return false;
    00049             } else {
    00050                 $this->clean();
    00051
    00052                 return null;
    00053             }
    00054
    00055             $this->raw = $scope[$this->name];
    00056
    00057             return $this->imported = true;
    00058         }
    00059
    00060         public function importValue($value)
    00061         {
    00062             Assert::isTernaryBase($value, 'only ternary based accepted');
    00063
    00064             $this->value = $value;
    00065
    00066             return $this->imported = true;
    00067         }
    00068     }
    00069 ?>