Method.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. namespace ZN\Services;
  3. class __USE_STATIC_ACCESS__Method implements MethodInterface
  4. {
  5. //----------------------------------------------------------------------------------------------------
  6. //
  7. // Yazar : Ozan UYKUN <ozanbote@windowslive.com> | <ozanbote@gmail.com>
  8. // Site : www.zntr.net
  9. // Lisans : The MIT License
  10. // Telif Hakkı: Copyright (c) 2012-2016, zntr.net
  11. //
  12. //----------------------------------------------------------------------------------------------------
  13. //----------------------------------------------------------------------------------------------------
  14. // Call Method
  15. //----------------------------------------------------------------------------------------------------
  16. //
  17. // __call()
  18. //
  19. //----------------------------------------------------------------------------------------------------
  20. use \CallUndefinedMethodTrait;
  21. //----------------------------------------------------------------------------------------------------
  22. // Error Control
  23. //----------------------------------------------------------------------------------------------------
  24. //
  25. // $error
  26. // $success
  27. //
  28. // error()
  29. // success()
  30. //
  31. //----------------------------------------------------------------------------------------------------
  32. use \ErrorControlTrait;
  33. //----------------------------------------------------------------------------------------------------
  34. // Post
  35. //----------------------------------------------------------------------------------------------------
  36. //
  37. // @param string $name
  38. // @param mixed $value
  39. //
  40. //----------------------------------------------------------------------------------------------------
  41. public function post($name = '', $value = '')
  42. {
  43. return $this->_method($name, $value, $_POST ,__FUNCTION__);
  44. }
  45. //----------------------------------------------------------------------------------------------------
  46. // Get
  47. //----------------------------------------------------------------------------------------------------
  48. //
  49. // @param string $name
  50. // @param mixed $value
  51. //
  52. //----------------------------------------------------------------------------------------------------
  53. public function get($name = '', $value = '')
  54. {
  55. return $this->_method($name, $value, $_GET, __FUNCTION__);
  56. }
  57. //----------------------------------------------------------------------------------------------------
  58. // Request
  59. //----------------------------------------------------------------------------------------------------
  60. //
  61. // @param string $name
  62. // @param mixed $value
  63. //
  64. //----------------------------------------------------------------------------------------------------
  65. public function request($name = '', $value = '')
  66. {
  67. return $this->_method($name, $value, $_REQUEST, __FUNCTION__);
  68. }
  69. //----------------------------------------------------------------------------------------------------
  70. // Env
  71. //----------------------------------------------------------------------------------------------------
  72. //
  73. // @param string $name
  74. // @param mixed $value
  75. //
  76. //----------------------------------------------------------------------------------------------------
  77. public function env($name = '', $value = '')
  78. {
  79. return $this->_method($name, $value, $_ENV, __FUNCTION__);
  80. }
  81. //----------------------------------------------------------------------------------------------------
  82. // Server
  83. //----------------------------------------------------------------------------------------------------
  84. //
  85. // @param string $name
  86. // @param mixed $value
  87. //
  88. //----------------------------------------------------------------------------------------------------
  89. public function server($name = '', $value = '')
  90. {
  91. // Parametreler kontrol ediliyor. --------------------------------------------
  92. if( ! is_string($name) )
  93. {
  94. return \Errors::set('Error', 'stringParameter', 'name');
  95. }
  96. // ---------------------------------------------------------------------------
  97. // @value parametresi boş değilse
  98. if( ! empty($value) )
  99. {
  100. $_SERVER[$name] = $value;
  101. }
  102. return server($name);
  103. }
  104. //----------------------------------------------------------------------------------------------------
  105. // Files
  106. //----------------------------------------------------------------------------------------------------
  107. //
  108. // @param string $filename
  109. // @param string $type
  110. //
  111. //----------------------------------------------------------------------------------------------------
  112. public function files($fileName = '', $type = 'name')
  113. {
  114. if( ! is_string($fileName) )
  115. {
  116. return \Errors::set('Error', 'stringParameter', 'fileName');
  117. }
  118. if( ! is_string($type) )
  119. {
  120. $type = 'name';
  121. }
  122. if( empty($fileName) )
  123. {
  124. return \Errors::set('Error', 'emptyVariable', '@fileName');
  125. }
  126. return $_FILES[$fileName][$type];
  127. }
  128. //----------------------------------------------------------------------------------------------------
  129. // Delete
  130. //----------------------------------------------------------------------------------------------------
  131. //
  132. // @param string $input
  133. // @param string $name
  134. //
  135. //----------------------------------------------------------------------------------------------------
  136. public function delete($input = '', $name = '')
  137. {
  138. if( ! is_scalar($input) || ! is_scalar($name) )
  139. {
  140. return \Errors::set('Error', 'scalarParameter', '1.(input) && 2.(name)');
  141. }
  142. switch( $input )
  143. {
  144. case 'post' : unset($_POST[$name]); break;
  145. case 'get' : unset($_GET[$name]); break;
  146. case 'env' : unset($_ENV[$name]); break;
  147. case 'server' : unset($_SERVER[$name]); break;
  148. case 'request' : unset($_REQUEST[$name]); break;
  149. }
  150. }
  151. //----------------------------------------------------------------------------------------------------
  152. // Protected Method
  153. //----------------------------------------------------------------------------------------------------
  154. //
  155. // @param string $name
  156. // @param mixed $value
  157. // @param var $input
  158. // @param string $type
  159. //
  160. //----------------------------------------------------------------------------------------------------
  161. protected function _method($name = '', $value = '', $input = '', $type = '')
  162. {
  163. // Parametreler kontrol ediliyor. --------------------------------------------
  164. if( ! is_string($name) )
  165. {
  166. return \Errors::set('Error', 'stringParameter', 'name');
  167. }
  168. if( empty($name) )
  169. {
  170. return $input;
  171. }
  172. // ---------------------------------------------------------------------------
  173. // @value parametresi boş değilse
  174. if( ! empty($value) )
  175. {
  176. switch( $type )
  177. {
  178. case 'post' : $_POST[$name] = $value; break;
  179. case 'get' : $_GET[$name] = $value; break;
  180. case 'request' : $_REQUEST[$name] = $value; break;
  181. case 'env' : $_ENV[$name] = $value; break;
  182. default : $_POST[$name] = $value; break;
  183. }
  184. }
  185. // Global veri içersinde
  186. // böyle bir veri yoksa
  187. if( empty($input[$name]) )
  188. {
  189. return \Errors::set('Error', 'emptyVariable', '$_'.strtoupper($type)."['name']");
  190. }
  191. if( $value === false )
  192. {
  193. return $input[$name];
  194. }
  195. if( is_scalar($input[$name]) )
  196. {
  197. return htmlspecialchars($input[$name], ENT_QUOTES, "utf-8");
  198. }
  199. elseif( is_array($input[$name]) )
  200. {
  201. return array_map('Security::htmlEncode', $input[$name]);
  202. }
  203. return $input[$name];
  204. }
  205. }