00001 <?php 00002 /*************************************************************************** 00003 * Copyright (C) 2004-2007 by Konstantin V. Arkhipov * 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 00018 abstract class ComplexPrimitive extends RangedPrimitive 00019 { 00020 private $single = null; // single, not single or fsck it 00021 00022 public function __construct($name) 00023 { 00024 $this->single = new Ternary(null); 00025 parent::__construct($name); 00026 } 00027 00031 public function getState() 00032 { 00033 return $this->single; 00034 } 00035 00039 public function setState(Ternary $ternary) 00040 { 00041 $this->single->setValue($ternary->getValue()); 00042 00043 return $this; 00044 } 00045 00049 public function setSingle() 00050 { 00051 $this->single->setTrue(); 00052 00053 return $this; 00054 } 00055 00059 public function setComplex() 00060 { 00061 $this->single->setFalse(); 00062 00063 return $this; 00064 } 00065 00069 public function setAnyState() 00070 { 00071 $this->single->setNull(); 00072 00073 return $this; 00074 } 00075 00076 // implement me, child :-) 00077 abstract protected function importSingle($scope); 00078 abstract protected function importMarried($scope); 00079 00080 public function import($scope) 00081 { 00082 if (!BasePrimitive::import($scope)) 00083 return null; 00084 00085 if ($this->single->isTrue()) 00086 return $this->importSingle($scope); 00087 elseif ($this->single->isFalse()) 00088 return $this->importMarried($scope); 00089 else { 00090 if (!$this->importMarried($scope)) 00091 return $this->importSingle($scope); 00092 00093 return true; 00094 } 00095 00096 Assert::isUnreachable(); 00097 } 00098 00099 public function exportValue() 00100 { 00101 throw new UnimplementedFeatureException(); 00102 } 00103 } 00104 ?>