ColorArray.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-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 ColorArray
00016     {
00017         private $colors = array();
00018         
00022         public function add(Color $color)
00023         {
00024             $this->colors[] = $color;
00025             
00026             return $this;
00027         }
00028         
00032         public function clear()
00033         {
00034             unset($this->colors);
00035             
00036             return $this;
00037         }
00038         
00043         public function getRandomTextColor()
00044         {
00045             if ($this->isEmpty())
00046                 throw new MissingElementException();
00047                 
00048             return $this->colors[array_rand($this->colors)];
00049         }
00050     
00051         public function getColors()
00052         {
00053             return $this->colors;
00054         }
00055         
00056         public function isEmpty()
00057         {
00058             if (count($this->colors) == 0)
00059                 return true;
00060             else
00061                 return false;
00062         }
00063     }
00064 ?>