summaryrefslogtreecommitdiffstats
path: root/lib/request.php
blob: 013c9b80e959c9f10b6dedc35ec366ca6e0987ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* ownCloud - News app
*
* @author Bernhard Posselt
* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com>
*
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file
*
*/

namespace OCA\News;


/**
 * Encapsulates user id, $_GET and $_POST arrays for better testability
 */
class Request {

	private $get;
	private $post;
	private $userId;
	private $files;

	/**
	 * @param string $userId: the id of the current user
	 * @param array $get: the $_GET array
	 * @param array $post: the $_POST array
	 * @param array $files the $_FILES array
	 */
	public function __construct($userId, $get=array(), $post=array(), $files=array()) {
		$this->get = $get;
		$this->post = $post;
		$this->userId = $userId;
		$this->files = $files;
	}


	/**
	 * Returns the get value or the default if not found
	 * @param string $key: the array key that should be looked up
	 * @param string $default: if the key is not found, return this value
	 * @return the value of the stored array
	 */
	public function getGET($key, $default=null){
		if(isset($this->get[$key])){
			return $this->get[$key];
		} else {
			return $default;
		}
	}


	/**
	 * Returns the get value of the files array
	 * @param string $key: the array key that should be looked up
	 * @return the value of the stored array
	 */
	public function getFILES($key){
		if(isset($this->files[$key])){
			return $this->files[$key];
		} else {
			return null;
		}
	}


	/**
	 * Returns the get value or the default if not found
	 * @param string $key: the array key that should be looked up
	 * @param string $default: if the key is not found, return this value
	 * @return the value of the stored array
	 */
	public function getPOST($key, $default=null){
		if(isset($this->post[$key])){
			return $this->post[$key];
		} else {
			return $default;
		}
	}

}