1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8/** 9 * Creates a request object populated with data 10 * from either http request or cli arguments. 11 */ 12class Tiki_Request 13{ 14 protected $properties = []; 15 16 /** 17 * Populates $this->properties with params passed to PHP 18 * via http request or cli arguments. 19 * 20 * @return null 21 */ 22 public function __construct() 23 { 24 if (isset($_SERVER['REQUEST_METHOD'])) { 25 // http 26 $this->properties = $_REQUEST; 27 } elseif (isset($_SERVER['argc'], $_SERVER['argv']) && $_SERVER['argc'] >= 2) { 28 // cli 29 foreach ($_SERVER['argv'] as $arg) { 30 if (strpos($arg, '=')) { 31 list($key, $value) = explode('=', $arg); 32 $this->setProperty($key, $value); 33 } 34 } 35 } 36 } 37 38 /** 39 * Set property a new property 40 * 41 * @param string $key property key 42 * @param string $value property value 43 * @return null 44 */ 45 public function setProperty($key, $value) 46 { 47 $this->properties[$key] = $value; 48 } 49 50 /** 51 * Return property value 52 * 53 * @param string $key property key 54 * @return string|null property value or null 55 */ 56 public function getProperty($key) 57 { 58 if (isset($this->properties[$key])) { 59 return $this->properties[$key]; 60 } 61 } 62 63 /** 64 * Return true or false depending whether the 65 * property exist or not. 66 * 67 * @param string $key 68 * @return bool 69 */ 70 public function hasProperty($key) 71 { 72 if (isset($this->properties[$key])) { 73 return true; 74 } 75 76 return false; 77 } 78} 79