1 <?php
2 /* --------------------------------------------------------------
3 HttpContextReader.inc.php 2015-03-12 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('HttpContextReaderInterface');
13
14 /**
15 * Class HttpContextReader
16 *
17 * @category System
18 * @package Http
19 * @implements HttpContextReaderInterface
20 */
21 class HttpContextReader implements HttpContextReaderInterface
22 {
23 /**
24 * Returns the controller name for current http request context.
25 *
26 * @param HttpContextInterface $httpContext Object which holds information about the current http context.
27 *
28 * @return string Name of controller for the current http context.
29 */
30 public function getControllerName(HttpContextInterface $httpContext)
31 {
32 $doValue = (string)$httpContext->getGetItem('do');
33 $doPartsArray = explode('/', $doValue);
34
35 return $doPartsArray[0];
36 }
37
38
39 /**
40 * Returns the name of the action method for the current http context.
41 *
42 * @param \HttpContextInterface $httpContext Object which holds information about the current http context.
43 *
44 * @return string Name of action method for the current http context.
45 */
46 public function getActionName(HttpContextInterface $httpContext)
47 {
48 $doValue = (string)$httpContext->getGetItem('do');
49 $doPartsArray = explode('/', $doValue);
50 if(count($doPartsArray) < 2)
51 {
52 return '';
53 }
54
55 return $doPartsArray[1];
56 }
57
58
59 /**
60 * Returns an array which represents the global $_GET variable of the current http context.
61 *
62 * @param HttpContextInterface $httpContext Object which holds information about the current http context.
63 *
64 * @return array Which holds information equal to the global $_GET variable in an object oriented layer.
65 */
66 public function getQueryParameters(HttpContextInterface $httpContext)
67 {
68 return $httpContext->getGetArray();
69 }
70
71
72 /**
73 * Returns an array which represents the global $_POST variable of the current http context.
74 *
75 * @param HttpContextInterface $httpContext Object which holds information about the current http context.
76 *
77 * @return array Which holds information equal to the global $_POST variable in an object oriented layer.
78 */
79 public function getPostData(HttpContextInterface $httpContext)
80 {
81 return $httpContext->getPostArray();
82 }
83 }