ProjectionChain.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2006-2008 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 
00015     final class ProjectionChain implements ObjectProjection
00016     {
00017         private $list = array();
00018         
00022         public function add(ObjectProjection $projection, $name = null)
00023         {
00024             if ($name) {
00025                 Assert::isFalse(isset($this->list[$name]));
00026                 
00027                 $this->list[$name] = $projection;
00028             } else {
00029                 $this->list[] = $projection;
00030             }
00031             
00032             return $this;
00033         }
00034         
00038         public function process(Criteria $criteria, JoinCapableQuery $query)
00039         {
00040             foreach ($this->list as $projection)
00041                 $projection->process($criteria, $query);
00042             
00043             return $query;
00044         }
00045         
00046         public function isEmpty()
00047         {
00048             return count($this->list) == 0;
00049         }
00050         
00054         public function dropByType(/* array */ $dropTypes)
00055         {
00056             $newList = array();
00057             
00058             if (!is_array($dropTypes))
00059                 $dropTypes = array($dropTypes);
00060             
00061             foreach ($this->list as $name => &$projection) {
00062                 $class = get_class($projection);
00063                 
00064                 if (!in_array($class, $dropTypes))
00065                     $newList[$name] = $projection;
00066             }
00067             
00068             // swap
00069             $this->list = $newList;
00070             
00071             return $this;
00072         }
00073     }
00074 ?>