public function getFlyweight($state) { if (is_array($state)) { //复合模式 $uFlyweight = new UnsharedConcreteFlyweight(); foreach ($state as $row) { $uFlyweight->add($row, $this->getFlyweight($row)); } return $uFlyweight; } else { if (is_string($state)) { if (isset($this->_flyweights[$state])) { return $this->_flyweights[$state]; } else { return $this->_flyweights[$state] = new ConcreteFlyweight($state); } } else { return null; } } }