These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Part of ci-phpunit-test |
||
4 | * |
||
5 | * @author Kenji Suzuki <https://github.com/kenjis> |
||
6 | * @license MIT License |
||
7 | * @copyright 2015 Kenji Suzuki |
||
8 | * @link https://github.com/kenjis/ci-phpunit-test |
||
9 | */ |
||
10 | |||
11 | /** |
||
12 | * CodeIgniter URL Helpers with little modification for testing |
||
13 | * |
||
14 | * @package CodeIgniter |
||
15 | * @subpackage Helpers |
||
16 | * @category Helpers |
||
17 | * @author Kenji Suzuki <http://github.com/kenjis/ci-phpunit-test> |
||
18 | * @author EllisLab Dev Team |
||
19 | * @link https://codeigniter.com/user_guide/helpers/url_helper.html |
||
20 | */ |
||
21 | |||
22 | // ------------------------------------------------------------------------ |
||
23 | |||
24 | View Code Duplication | if ( ! function_exists('redirect')) |
|
25 | { |
||
26 | function redirect($uri = '', $method = 'auto', $code = NULL) |
||
0 ignored issues
–
show
|
|||
27 | { |
||
28 | if ( ! preg_match('#^(\w+:)?//#i', $uri)) |
||
29 | { |
||
30 | $uri = site_url($uri); |
||
31 | } |
||
32 | |||
33 | // IIS environment likely? Use 'refresh' for better compatibility |
||
34 | if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE) |
||
35 | { |
||
36 | $method = 'refresh'; |
||
37 | } |
||
38 | elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code))) |
||
39 | { |
||
40 | if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') |
||
41 | { |
||
42 | $code = ($_SERVER['REQUEST_METHOD'] !== 'GET') |
||
43 | ? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get |
||
44 | : 307; |
||
45 | } |
||
46 | else |
||
47 | { |
||
48 | $code = 302; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | switch ($method) |
||
53 | { |
||
54 | case 'refresh': |
||
55 | if (ENVIRONMENT !== 'testing') |
||
56 | { |
||
57 | header('Refresh:0;url='.$uri); |
||
58 | } |
||
59 | break; |
||
60 | default: |
||
61 | if (ENVIRONMENT !== 'testing') |
||
62 | { |
||
63 | header('Location: '.$uri, TRUE, $code); |
||
64 | } |
||
65 | break; |
||
66 | } |
||
67 | |||
68 | if (ENVIRONMENT !== 'testing') |
||
69 | { |
||
70 | exit; |
||
71 | } |
||
72 | else |
||
73 | { |
||
74 | while (ob_get_level() > 1) |
||
75 | { |
||
76 | ob_end_clean(); |
||
77 | } |
||
78 | |||
79 | throw new CIPHPUnitTestRedirectException('Redirect to ' . $uri, $code); |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: