PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/src/web/request/request.php

https://github.com/php-tox/tox
PHP | 108 lines | 71 code | 13 blank | 24 comment | 6 complexity | b7756c18074334b500296605e90ba314 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Represents as the input for a web application.
  4. *
  5. * This file is part of Tox.
  6. *
  7. * Tox is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tox is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tox. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @package Tox\Web
  21. * @author Snakevil Zen <zsnakevil@gmail.com>
  22. * @copyright Š 2012-2013 PHP-Tox.org
  23. * @license http://www.gnu.org/licenses/gpl.html
  24. */
  25. namespace Tox\Web\Request;
  26. use Tox\Core;
  27. use Tox\Application;
  28. use Tox\Web;
  29. class Request extends Application\Input\Input implements Web\IRequest
  30. {
  31. protected $data;
  32. public function __construct()
  33. {
  34. $this->data = array();
  35. $this->import('cookie', $_COOKIE)
  36. ->import('env', $_ENV)
  37. ->import('files', $_FILES, 2)
  38. ->import('get', $_GET)
  39. ->import('post', $_POST)
  40. ->import('server', $_SERVER);
  41. $_COOKIE = $_ENV = $_FILES = $_GET = $_POST = $_REQUEST = $_SERVER = array();
  42. }
  43. public function getCommandLine()
  44. {
  45. return rawurldecode($this->data['server.request_uri']);
  46. }
  47. protected function import($prefix, $data, $depth = 1)
  48. {
  49. settype($prefix, 'string');
  50. settype($depth, 'int');
  51. if (0 < $depth) {
  52. $depth--;
  53. settype($data, 'array');
  54. reset($data);
  55. for ($ii = 0, $jj = count($data); $ii < $jj; $ii++) {
  56. list($m_key, $m_data) = each($data);
  57. $this->import($prefix . '.' . strtolower($m_key), $m_data, $depth);
  58. }
  59. } elseif (!$depth) {
  60. $this->data[$prefix] = $data;
  61. }
  62. return $this;
  63. }
  64. public function offsetExists($offset)
  65. {
  66. settype($offset, 'string');
  67. return array_key_exists($offset, $this->data);
  68. }
  69. public function offsetGet($offset)
  70. {
  71. settype($offset, 'string');
  72. if (!$this->offsetExists($offset)) {
  73. if (!isset($this->default[$offset])) {
  74. throw new UnknownMetaException(array('field' => $offset));
  75. } else {
  76. return $this->default[$offset];
  77. }
  78. } else {
  79. return $this->data[$offset];
  80. }
  81. }
  82. public function offsetSet($offset, $value)
  83. {
  84. return;
  85. }
  86. public function offsetUnset($offset)
  87. {
  88. return;
  89. }
  90. public function recruit(Application\IToken $token)
  91. {
  92. return $this->import('route', $token->export());
  93. }
  94. }
  95. // vi:se ft=php fenc=utf-8 ff=unix ts=4 sts=4 et sw=4 fen fdm=indent fdl=1 tw=120: