PrimitiveArray.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2004-2008 by Konstantin V. Arkhipov, Anton E. Lebedevich *
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 PrimitiveArray extends FiltrablePrimitive
00016     {
00024         private $fetchMode = null;
00025         
00029         public function setFetchMode($ternary)
00030         {
00031             Assert::isTernaryBase($ternary);
00032             
00033             $this->fetchMode = $ternary;
00034             
00035             return $this;
00036         }
00037         
00038         public function import($scope)
00039         {
00040             if (!BasePrimitive::import($scope))
00041                 return null;
00042             
00043             $this->value = $scope[$this->name];
00044             
00045             $this->selfFilter();
00046             
00047             if (
00048                 is_array($this->value)
00049                 && !($this->min && count($this->value) < $this->min)
00050                 && !($this->max && count($this->value) > $this->max)
00051             ) {
00052                 return true;
00053             } else {
00054                 $this->value = null;
00055             }
00056             
00057             return false;
00058         }
00059         
00060         public function importValue($value)
00061         {
00062             if ($value instanceof UnifiedContainer) {
00063                 if (
00064                     ($this->fetchMode !== null)
00065                     && ($value->getParentObject()->getId())
00066                 ) {
00067                     if ($value->isLazy() === $this->fetchMode) {
00068                         $value = $value->getList();
00069                     } else {
00070                         $className = get_class($value);
00071                         
00072                         $containter = new $className(
00073                             $value->getParentObject(),
00074                             $this->fetchMode
00075                         );
00076                         
00077                         $value = $containter->getList();
00078                     }
00079                 } elseif (!$value->isFetched())
00080                     return null;
00081             }
00082             
00083             if (is_array($value))
00084                 return $this->import(array($this->getName() => $value));
00085             
00086             return false;
00087         }
00088     }
00089 ?>