# FetchStrategy.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2006-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
    00015     final class FetchStrategy extends Enumeration
    00016     {
    00017         const JOIN      = 1;
    00018         const CASCADE   = 2;
    00019         const LAZY      = 3;
    00020
    00021         protected $names = array(
    00022             self::JOIN      => 'join',
    00023             self::CASCADE   => 'cascade',
    00024             self::LAZY      => 'lazy'
    00025         );
    00026
    00030         public function setId($id)
    00031         {
    00032             Assert::isNull($this->id, 'i am immutable one!');
    00033
    00034             return parent::setId($id);
    00035         }
    00036
    00040         public static function join()
    00041         {
    00042             return self::getInstance(self::JOIN);
    00043         }
    00044
    00048         public static function cascade()
    00049         {
    00050             return self::getInstance(self::CASCADE);
    00051         }
    00052
    00056         public static function lazy()
    00057         {
    00058             return self::getInstance(self::LAZY);
    00059         }
    00060
    00064         private static function getInstance($id)
    00065         {
    00066             static $instances = array();
    00067
    00068             if (!isset($instances[$id]))
    00069                 $instances[$id] = new self($id);
    00070
    00071             return $instances[$id];
    00072         }
    00073     }
    00074 ?>