/[drupal]/contributions/modules/handler/handler.environment.inc
ViewVC logotype

Contents of /contributions/modules/handler/handler.environment.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun Aug 10 22:47:47 2008 UTC (15 months, 2 weeks ago) by crell
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.1: +21 -0 lines
File MIME type: text/x-php
- Add more documentation and proper CVS tags.
1 <?php
2 // $Id: $
3
4 /**
5 * @file
6 * The Drupal environment uber variable.
7 *
8 * Handlers by design should be totally insulated from the context in which
9 * they run. All communication eith their environment is through a provided
10 * environment object, which manages communication with the rest of the system.
11 * That makes it very easy to "mock" the environment in order to unit test
12 * a handler object in a vaccuum.
13 */
14
15 /**
16 * The basic Drupal environment object interface.
17 *
18 */
19 interface DrupalEnvironmentInterface {
20
21 public function variableGet($var, $default);
22 public function variableSet($var, $default);
23
24 public function httpGet($key = NULL, $default = NULL);
25 public function httpPost($key = NULL, $default = NULL);
26 public function httpCookie($key = NULL, $default = NULL);
27 public function requestArgument($arg);
28 public function requestPath();
29
30 public function serverInfo($key = NULL, $default = NULL);
31 public function envInfo($key = NULL, $default = NULL);
32
33 public function invokeHooks($hook);
34 public function handler($target, $options = array());
35
36 }
37
38 class EnvironmentDefault implements DrupalEnvironmentInterface {
39
40 protected $requestPath;
41 protected $getArray;
42 protected $postArray;
43 protected $cookieArray;
44 protected $serverArray;
45 protected $envArray;
46
47 public function __construct() {
48 $this->requestPath = drupal_get_normal_path($_GET['q']);
49
50 $this->getArray = $_GET;
51 $this->postArray = $_POST;
52 $this->cookieArray = $_COOKIE;
53 $this->serverArray = $_SERVER;
54 $this->envArray = $_ENV;
55 unset($this->getArray['q']);
56
57 $this->requestArguments = explode('/', $this->requestPath);
58
59 }
60
61 public function variableGet($var, $default) {
62 return variable_get($var, $default);
63 }
64
65 public function variableSet($var, $default) {
66 return variable_set($var, $default);
67 }
68
69 public function requestPath() {
70 return $this->requestPath;
71 }
72
73 protected function arrayIndexLookup($array, $key = NULL, $default = NULL) {
74 if (isset($key)) {
75 return isset($this->$array[$key]) ? $this->$array[$key] : $default;
76 }
77 else {
78 return $this->$array;
79 }
80 }
81
82 public function httpGet($key = NULL, $default = NULL) {
83 return $this->arrayIndexLookup('getArray', $key, $default);
84 }
85
86 public function httpPost($key = NULL, $default = NULL) {
87 return $this->arrayIndexLookup('postArray', $key, $default);
88 }
89
90 public function httpCookie($key = NULL, $default = NULL) {
91 return $this->arrayIndexLookup('cookieArray', $key, $default);
92 }
93
94 public function serverInfo($key = NULL, $default = NULL) {
95 return $this->arrayIndexLookup('serverArray', $key, $default);
96 }
97
98 public function envInfo($key = NULL, $default = NULL) {
99 return $this->arrayIndexLookup('envArray', $key, $default);
100 }
101
102 public function requestArgument($arg) {
103 return isset($this->requestArguments[$arg]) ? $this->requestArguments[$arg] : NULL;
104 }
105
106 public function invokeHooks($hook) {
107 return call_user_func_array('module_invoke_all', func_get_args());
108 }
109
110 public function handler($target, $options = array()) {
111 return handler($target, $options);
112 }
113 }
114

  ViewVC Help
Powered by ViewVC 1.1.2