RequestType.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 RequestType extends Enumeration
00016     {
00017         const GET       = 1;
00018         const POST      = 2;
00019         const FILES     = 3;
00020         const COOKIE    = 4;
00021         const SESSION   = 5;
00022         const ATTACHED  = 6;
00023         const SERVER    = 7;
00024         
00025         protected $names = array(
00026             self::GET       => 'get',
00027             self::POST      => 'post',
00028             self::FILES     => 'files',
00029             self::COOKIE    => 'cookie',
00030             self::SESSION   => 'session',
00031             self::ATTACHED  => 'attached',
00032             self::SERVER    => 'server'
00033         );
00034         
00038         public function setId($id)
00039         {
00040             Assert::isNull($this->id, 'i am immutable one!');
00041             
00042             return parent::setId($id);
00043         }
00044         
00048         public static function get()
00049         {
00050             return self::getInstance(self::GET);
00051         }
00052         
00056         public static function post()
00057         {
00058             return self::getInstance(self::POST);
00059         }
00060         
00064         public static function files()
00065         {
00066             return self::getInstance(self::FILES);
00067         }
00068         
00072         public static function cookie()
00073         {
00074             return self::getInstance(self::COOKIE);
00075         }
00076         
00080         public static function session()
00081         {
00082             return self::getInstance(self::SESSION);
00083         }
00084 
00088         public static function attached()
00089         {
00090             return self::getInstance(self::ATTACHED);
00091         }
00092         
00096         public static function server()
00097         {
00098             return self::getInstance(self::SERVER);
00099         }
00100         
00104         private static function getInstance($id)
00105         {
00106             static $instances = array();
00107             
00108             if (!isset($instances[$id]))
00109                 $instances[$id] = new self($id);
00110             
00111             return $instances[$id];
00112         }
00113     }
00114 ?>