• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kenjis / ci-phpunit-test / 1025

pending completion
1025

push

travis-ci-com

web-flow
Merge pull request #394 from dezsi-istvan/3.x

pre_controller can modify $class / $method

4 of 4 new or added lines in 1 file covered. (100.0%)

1321 of 1739 relevant lines covered (75.96%)

35.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.05
/application/tests/_ci_phpunit_test/replacing/core/Output.php
1
<?php
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
9
 * Copyright (c) 2019 - 2022, CodeIgniter Foundation
10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
 * copies of the Software, and to permit persons to whom the Software is
16
 * furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in
19
 * all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 *
29
 * @package        CodeIgniter
30
 * @author        EllisLab Dev Team
31
 * @copyright        Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32
 * @copyright        Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
33
 * @copyright        Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
34
 * @license        https://opensource.org/licenses/MIT        MIT License
35
 * @link        https://codeigniter.com
36
 * @since        Version 1.0.0
37
 * @filesource
38
 */
39
defined('BASEPATH') OR exit('No direct script access allowed');
24✔
40

41
/**
42
 * Output Class
43
 *
44
 * Responsible for sending final output to the browser.
45
 *
46
 * @package                CodeIgniter
47
 * @subpackage        Libraries
48
 * @category        Output
49
 * @author                EllisLab Dev Team
50
 * @link                https://codeigniter.com/userguide3/libraries/output.html
51
 */
52
class CI_Output {
53

54
        /**
55
         * Final output string
56
         *
57
         * @var        string
58
         */
59
        public $final_output = '';
60

61
        /**
62
         * Cache expiration time
63
         *
64
         * @var        int
65
         */
66
        public $cache_expiration = 0;
67

68
        /**
69
         * List of server headers
70
         *
71
         * @var        array
72
         */
73
        public $headers = array();
74

75
        /**
76
         * List of mime types
77
         *
78
         * @var        array
79
         */
80
        public $mimes =        array();
81

82
        /**
83
         * Mime-type for the current page
84
         *
85
         * @var        string
86
         */
87
        protected $mime_type = 'text/html';
88

89
        /**
90
         * Enable Profiler flag
91
         *
92
         * @var        bool
93
         */
94
        public $enable_profiler = FALSE;
95

96
        /**
97
         * php.ini zlib.output_compression flag
98
         *
99
         * @var        bool
100
         */
101
        protected $_zlib_oc = FALSE;
102

103
        /**
104
         * CI output compression flag
105
         *
106
         * @var        bool
107
         */
108
        protected $_compress_output = FALSE;
109

110
        /**
111
         * List of profiler sections
112
         *
113
         * @var        array
114
         */
115
        protected $_profiler_sections =        array();
116

117
        /**
118
         * Parse markers flag
119
         *
120
         * Whether or not to parse variables like {elapsed_time} and {memory_usage}.
121
         *
122
         * @var        bool
123
         */
124
        public $parse_exec_vars = TRUE;
125

126
        /**
127
         * mbstring.func_overload flag
128
         *
129
         * @var        bool
130
         */
131
        protected static $func_overload;
132

133
        /**
134
         * Response status (status code, text and is redirection?)
135
         *
136
         * @var array
137
         *
138
         * added by ci-phpunit-test
139
         */
140
        public $_status;
141

142
        /**
143
         * Cookies
144
         *
145
         * @var array
146
         *
147
         * added by ci-phpunit-test
148
         */
149
        public $_cookies;
150

151
        /**
152
         * Class constructor
153
         *
154
         * Determines whether zLib output compression will be used.
155
         *
156
         * @return        void
157
         */
158
        public function __construct()
159
        {
160
                $this->_zlib_oc = (bool) ini_get('zlib.output_compression');
100✔
161
                $this->_compress_output = (
100✔
162
                        $this->_zlib_oc === FALSE
100✔
163
                        && config_item('compress_output') === TRUE
100✔
164
                        && extension_loaded('zlib')
100✔
165
                );
100✔
166

167
                isset(self::$func_overload) OR self::$func_overload = ( ! is_php('8.0') && extension_loaded('mbstring') && @ini_get('mbstring.func_overload'));
168

169
                // Get mime types for later
170
                $this->mimes =& get_mimes();
171

172
                log_message('info', 'Output Class Initialized');
100✔
173
        }
174

175
        // --------------------------------------------------------------------
176

177
        /**
178
         * Get Output
179
         *
180
         * Returns the current output string.
181
         *
182
         * @return        string
183
         */
184
        public function get_output()
185
        {
186
                return $this->final_output;
187
        }
188

189
        // --------------------------------------------------------------------
190

191
        /**
192
         * Set Output
193
         *
194
         * Sets the output string.
195
         *
196
         * @param        string        $output        Output data
197
         * @return        CI_Output
198
         */
199
        public function set_output($output)
200
        {
201
                $this->final_output = $output;
×
202
                return $this;
×
203
        }
204

205
        // --------------------------------------------------------------------
206

207
        /**
208
         * Append Output
209
         *
210
         * Appends data onto the output string.
211
         *
212
         * @param        string        $output        Data to append
213
         * @return        CI_Output
214
         */
215
        public function append_output($output)
216
        {
217
                $this->final_output .= $output;
218
                return $this;
×
219
        }
220

221
        // --------------------------------------------------------------------
222

223
        /**
224
         * Set Header
225
         *
226
         * Lets you set a server header which will be sent with the final output.
227
         *
228
         * Note: If a file is cached, headers will not be sent.
229
         * @todo        We need to figure out how to permit headers to be cached.
230
         *
231
         * @param        string        $header                Header
232
         * @param        bool        $replace        Whether to replace the old header value, if already set
233
         * @return        CI_Output
234
         */
235
        public function set_header($header, $replace = TRUE)
236
        {
237
                // If zlib.output_compression is enabled it will compress the output,
238
                // but it will not modify the content-length header to compensate for
239
                // the reduction, causing the browser to hang waiting for more data.
240
                // We'll just skip content-length in those cases.
241
                if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) === 0)
×
242
                {
243
                        return $this;
×
244
                }
245

246
                $this->headers[] = array($header, $replace);
×
247
                return $this;
248
        }
249

250
        // --------------------------------------------------------------------
251

252
        /**
253
         * Set Content-Type Header
254
         *
255
         * @param        string        $mime_type        Extension of the file we're outputting
256
         * @param        string        $charset        Character set (default: NULL)
257
         * @return        CI_Output
258
         */
259
        public function set_content_type($mime_type, $charset = NULL)
260
        {
261
                if (strpos($mime_type, '/') === FALSE)
×
262
                {
263
                        $extension = ltrim($mime_type, '.');
264

265
                        // Is this extension supported?
266
                        if (isset($this->mimes[$extension]))
×
267
                        {
268
                                $mime_type =& $this->mimes[$extension];
269

270
                                if (is_array($mime_type))
×
271
                                {
272
                                        $mime_type = current($mime_type);
273
                                }
274
                        }
275
                }
276

277
                $this->mime_type = $mime_type;
×
278

279
                if (empty($charset))
×
280
                {
281
                        $charset = config_item('charset');
282
                }
283

284
                $header = 'Content-Type: '.$mime_type
×
285
                        .(empty($charset) ? '' : '; charset='.$charset);
×
286

287
                $this->headers[] = array($header, TRUE);
×
288
                return $this;
×
289
        }
290

291
        // --------------------------------------------------------------------
292

293
        /**
294
         * Get Current Content-Type Header
295
         *
296
         * @return        string        'text/html', if not already set
297
         */
298
        public function get_content_type()
299
        {
300
                for ($i = 0, $c = count($this->headers); $i < $c; $i++)
301
                {
302
                        if (sscanf($this->headers[$i][0], 'Content-Type: %[^;]', $content_type) === 1)
×
303
                        {
304
                                return $content_type;
305
                        }
306
                }
307

308
                return 'text/html';
309
        }
310

311
        // --------------------------------------------------------------------
312

313
        /**
314
         * Get Header
315
         *
316
         * @param        string        $header
317
         * @return        string
318
         */
319
        public function get_header($header)
320
        {
321
                // We only need [x][0] from our multi-dimensional array
322
                $header_lines = array_map(function ($headers)
×
323
                {
×
324
                        return array_shift($headers);
×
325
                }, $this->headers);
×
326

327
                // Combine headers already sent with our batched headers
328
                $headers = array_merge(
×
329
                        $header_lines,
×
330
                        headers_list()
×
331
                );
×
332

333
                if (empty($headers) OR empty($header))
×
334
                {
335
                        return NULL;
×
336
                }
337

338
                // Count backwards, in order to get the last matching header
339
                for ($c = count($headers) - 1; $c > -1; $c--)
340
                {
341
                        if (strncasecmp($header, $headers[$c], $l = self::strlen($header)) === 0)
342
                        {
343
                                return trim(self::substr($headers[$c], $l+1));
×
344
                        }
345
                }
346

347
                return NULL;
×
348
        }
349

350
        // --------------------------------------------------------------------
351

352
        /**
353
         * Set HTTP Status Header
354
         *
355
         * As of version 1.7.2, this is an alias for common function
356
         * set_status_header().
357
         *
358
         * @param        int        $code        Status code (default: 200)
359
         * @param        string        $text        Optional message
360
         * @return        CI_Output
361
         */
362
        public function set_status_header($code = 200, $text = '')
363
        {
364
                set_status_header($code, $text);
×
365
                return $this;
×
366
        }
367

368
        // --------------------------------------------------------------------
369

370
        /**
371
         * Enable/disable Profiler
372
         *
373
         * @param        bool        $val        TRUE to enable or FALSE to disable
374
         * @return        CI_Output
375
         */
376
        public function enable_profiler($val = TRUE)
377
        {
378
                $this->enable_profiler = is_bool($val) ? $val : TRUE;
379
                return $this;
380
        }
381

382
        // --------------------------------------------------------------------
383

384
        /**
385
         * Set Profiler Sections
386
         *
387
         * Allows override of default/config settings for
388
         * Profiler section display.
389
         *
390
         * @param        array        $sections        Profiler sections
391
         * @return        CI_Output
392
         */
393
        public function set_profiler_sections($sections)
394
        {
395
                if (isset($sections['query_toggle_count']))
396
                {
397
                        $this->_profiler_sections['query_toggle_count'] = (int) $sections['query_toggle_count'];
398
                        unset($sections['query_toggle_count']);
399
                }
400

401
                foreach ($sections as $section => $enable)
402
                {
403
                        $this->_profiler_sections[$section] = ($enable !== FALSE);
404
                }
405

406
                return $this;
407
        }
408

409
        // --------------------------------------------------------------------
410

411
        /**
412
         * Set Cache
413
         *
414
         * @param        int        $time        Cache expiration time in minutes
415
         * @return        CI_Output
416
         */
417
        public function cache($time)
418
        {
419
                $this->cache_expiration = is_numeric($time) ? $time : 0;
420
                return $this;
421
        }
422

423
        // --------------------------------------------------------------------
424

425
        /**
426
         * Display Output
427
         *
428
         * Processes and sends finalized output data to the browser along
429
         * with any server headers and profile data. It also stops benchmark
430
         * timers so the page rendering speed and memory usage can be shown.
431
         *
432
         * Note: All "view" data is automatically put into $this->final_output
433
         *         by controller class.
434
         *
435
         * @uses        CI_Output::$final_output
436
         * @param        string        $output        Output data override
437
         * @return        void
438
         *
439
         * modified by ci-phpunit-test
440
         */
441
        public function _display($output = '')
442
        {
443
                // Note:  We use load_class() because we can't use $CI =& get_instance()
444
                // since this function is sometimes called by the caching mechanism,
445
                // which happens before the CI super object is available.
446
                $BM =& load_class('Benchmark', 'core');
447
                $CFG =& load_class('Config', 'core');
448

449
                // Grab the super object if we can.
450
                if (class_exists('CI_Controller', FALSE))
451
                {
452
                        $CI =& get_instance();
453
                }
454

455
                // --------------------------------------------------------------------
456

457
                // Set the output data
458
                if ($output === '')
459
                {
460
                        $output =& $this->final_output;
461
                }
462

463
                // --------------------------------------------------------------------
464

465
                // Do we need to write a cache file? Only if the controller does not have its
466
                // own _output() method and we are not dealing with a cache file, which we
467
                // can determine by the existence of the $CI object above
468
                if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output'))
469
                {
470
                        $this->_write_cache($output);
471
                }
472

473
                // --------------------------------------------------------------------
474

475
                // Parse out the elapsed time and memory usage,
476
                // then swap the pseudo-variables with the data
477

478
                $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');
479

480
                if ($this->parse_exec_vars === TRUE)
481
                {
482
                        $memory        = round(memory_get_usage() / 1024 / 1024, 2).'MB';
483
                        $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output);
484
                }
485

486
                // --------------------------------------------------------------------
487

488
                // Is compression requested?
489
                if (isset($CI) // This means that we're not serving a cache file, if we were, it would already be compressed
490
                        && $this->_compress_output === TRUE
491
                        && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
492
                {
493
                        ob_start('ob_gzhandler');
494
                }
495

496
                // --------------------------------------------------------------------
497

498
                // Are there any server headers to send?
499
                if (count($this->headers) > 0)
500
                {
501
                        foreach ($this->headers as $header)
502
                        {
503
//                                @header($header[0], $header[1]);
504
                        }
505
                }
506

507
                // --------------------------------------------------------------------
508

509
                // Does the $CI object exist?
510
                // If not we know we are dealing with a cache file so we'll
511
                // simply echo out the data and exit.
512
                if ( ! isset($CI))
513
                {
514
                        if ($this->_compress_output === TRUE)
515
                        {
516
                                if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
517
                                {
518
//                                        header('Content-Encoding: gzip');
519
//                                        header('Content-Length: '.self::strlen($output));
520
                                }
521
                                else
522
                                {
523
                                        // User agent doesn't support gzip compression,
524
                                        // so we'll have to decompress our cache
525
                                        $output = gzinflate(self::substr($output, 10, -8));
526
                                }
527
                        }
528

529
                        echo $output;
530
                        log_message('info', 'Final output sent to browser');
531
                        log_message('debug', 'Total execution time: '.$elapsed);
532
                        return;
533
                }
534

535
                // --------------------------------------------------------------------
536

537
                // Do we need to generate profile data?
538
                // If so, load the Profile class and run it.
539
                if ($this->enable_profiler === TRUE)
540
                {
541
                        $CI->load->library('profiler');
542
                        if ( ! empty($this->_profiler_sections))
543
                        {
544
                                $CI->profiler->set_sections($this->_profiler_sections);
545
                        }
546

547
                        // If the output data contains closing </body> and </html> tags
548
                        // we will remove them and add them back after we insert the profile data
549
                        $output = preg_replace('|</body>.*?</html>|is', '', $output, -1, $count).$CI->profiler->run();
550
                        if ($count > 0)
551
                        {
552
                                $output .= '</body></html>';
553
                        }
554
                }
555

556
                // Does the controller contain a function named _output()?
557
                // If so send the output there.  Otherwise, echo it.
558
                if (method_exists($CI, '_output'))
559
                {
560
                        $CI->_output($output);
561
                }
562
                else
563
                {
564
                        echo $output; // Send it to the browser!
565
                }
566

567
                log_message('info', 'Final output sent to browser');
568
                log_message('debug', 'Total execution time: '.$elapsed);
569
        }
570

571
        // --------------------------------------------------------------------
572

573
        /**
574
         * Write Cache
575
         *
576
         * @param        string        $output        Output data to cache
577
         * @return        void
578
         */
579
        public function _write_cache($output)
580
        {
581
                $CI =& get_instance();
582
                $path = $CI->config->item('cache_path');
583
                $cache_path = ($path === '') ? APPPATH.'cache/' : $path;
584

585
                if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
586
                {
587
                        log_message('error', 'Unable to write cache file: '.$cache_path);
588
                        return;
589
                }
590

591
                $uri = $CI->config->item('base_url')
592
                        .$CI->config->item('index_page')
593
                        .$CI->uri->uri_string();
594

595
                if (($cache_query_string = $CI->config->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING']))
596
                {
597
                        if (is_array($cache_query_string))
598
                        {
599
                                $uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string)));
600
                        }
601
                        else
602
                        {
603
                                $uri .= '?'.$_SERVER['QUERY_STRING'];
604
                        }
605
                }
606

607
                $cache_path .= md5($uri);
608

609
                if ( ! $fp = @fopen($cache_path, 'w+b'))
610
                {
611
                        log_message('error', 'Unable to write cache file: '.$cache_path);
612
                        return;
613
                }
614

615
                if ( ! flock($fp, LOCK_EX))
616
                {
617
                        log_message('error', 'Unable to secure a file lock for file at: '.$cache_path);
618
                        fclose($fp);
619
                        return;
620
                }
621

622
                // If output compression is enabled, compress the cache
623
                // itself, so that we don't have to do that each time
624
                // we're serving it
625
                if ($this->_compress_output === TRUE)
626
                {
627
                        $output = gzencode($output);
628

629
                        if ($this->get_header('content-type') === NULL)
630
                        {
631
                                $this->set_content_type($this->mime_type);
632
                        }
633
                }
634

635
                $expire = time() + ($this->cache_expiration * 60);
636

637
                // Put together our serialized info.
638
                $cache_info = serialize(array(
639
                        'expire'        => $expire,
640
                        'headers'        => $this->headers
641
                ));
642

643
                $output = $cache_info.'ENDCI--->'.$output;
644

645
                for ($written = 0, $length = self::strlen($output); $written < $length; $written += $result)
646
                {
647
                        if (($result = fwrite($fp, self::substr($output, $written))) === FALSE)
648
                        {
649
                                break;
650
                        }
651
                }
652

653
                flock($fp, LOCK_UN);
654
                fclose($fp);
655

656
                if ( ! is_int($result))
657
                {
658
                        @unlink($cache_path);
659
                        log_message('error', 'Unable to write the complete cache content at: '.$cache_path);
660
                        return;
661
                }
662

663
                chmod($cache_path, 0640);
664
                log_message('debug', 'Cache file written: '.$cache_path);
665

666
                // Send HTTP cache-control headers to browser to match file cache settings.
667
                $this->set_cache_header($_SERVER['REQUEST_TIME'], $expire);
668
        }
669

670
        // --------------------------------------------------------------------
671

672
        /**
673
         * Update/serve cached output
674
         *
675
         * @uses        CI_Config
676
         * @uses        CI_URI
677
         *
678
         * @param        object        &$CFG        CI_Config class instance
679
         * @param        object        &$URI        CI_URI class instance
680
         * @return        bool        TRUE on success or FALSE on failure
681
         */
682
        public function _display_cache(&$CFG, &$URI)
683
        {
684
                $cache_path = ($CFG->item('cache_path') === '') ? APPPATH.'cache/' : $CFG->item('cache_path');
685

686
                // Build the file path. The file name is an MD5 hash of the full URI
687
                $uri = $CFG->item('base_url').$CFG->item('index_page').$URI->uri_string;
688

689
                if (($cache_query_string = $CFG->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING']))
690
                {
691
                        if (is_array($cache_query_string))
692
                        {
693
                                $uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string)));
694
                        }
695
                        else
696
                        {
697
                                $uri .= '?'.$_SERVER['QUERY_STRING'];
698
                        }
699
                }
700

701
                $filepath = $cache_path.md5($uri);
702

703
                if ( ! file_exists($filepath) OR ! $fp = @fopen($filepath, 'rb'))
704
                {
705
                        return FALSE;
706
                }
707

708
                flock($fp, LOCK_SH);
709

710
                $cache = (filesize($filepath) > 0) ? fread($fp, filesize($filepath)) : '';
711

712
                flock($fp, LOCK_UN);
713
                fclose($fp);
714

715
                // Look for embedded serialized file info.
716
                if ( ! preg_match('/^(.*)ENDCI--->/', $cache, $match))
717
                {
718
                        return FALSE;
719
                }
720

721
                $cache_info = unserialize($match[1]);
722
                $expire = $cache_info['expire'];
723

724
                $last_modified = filemtime($filepath);
725

726
                // Has the file expired?
727
                if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path))
728
                {
729
                        // If so we'll delete it.
730
                        @unlink($filepath);
731
                        log_message('debug', 'Cache file has expired. File deleted.');
732
                        return FALSE;
733
                }
734

735
                // Send the HTTP cache control headers
736
                $this->set_cache_header($last_modified, $expire);
737

738
                // Add headers from cache file.
739
                foreach ($cache_info['headers'] as $header)
740
                {
741
                        $this->set_header($header[0], $header[1]);
742
                }
743

744
                // Display the cache
745
                $this->_display(self::substr($cache, self::strlen($match[0])));
746
                log_message('debug', 'Cache file is current. Sending it to browser.');
747
                return TRUE;
748
        }
749

750
        // --------------------------------------------------------------------
751

752
        /**
753
         * Delete cache
754
         *
755
         * @param        string        $uri        URI string
756
         * @return        bool
757
         */
758
        public function delete_cache($uri = '')
759
        {
760
                $CI =& get_instance();
761
                $cache_path = $CI->config->item('cache_path');
762
                if ($cache_path === '')
763
                {
764
                        $cache_path = APPPATH.'cache/';
765
                }
766

767
                if ( ! is_dir($cache_path))
768
                {
769
                        log_message('error', 'Unable to find cache path: '.$cache_path);
770
                        return FALSE;
771
                }
772

773
                if (empty($uri))
774
                {
775
                        $uri = $CI->uri->uri_string();
776

777
                        if (($cache_query_string = $CI->config->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING']))
778
                        {
779
                                if (is_array($cache_query_string))
780
                                {
781
                                        $uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string)));
782
                                }
783
                                else
784
                                {
785
                                        $uri .= '?'.$_SERVER['QUERY_STRING'];
786
                                }
787
                        }
788
                }
789

790
                $cache_path .= md5($CI->config->item('base_url').$CI->config->item('index_page').ltrim($uri, '/'));
791

792
                if ( ! @unlink($cache_path))
793
                {
794
                        log_message('error', 'Unable to delete cache file for '.$uri);
795
                        return FALSE;
796
                }
797

798
                return TRUE;
799
        }
800

801
        // --------------------------------------------------------------------
802

803
        /**
804
         * Set Cache Header
805
         *
806
         * Set the HTTP headers to match the server-side file cache settings
807
         * in order to reduce bandwidth.
808
         *
809
         * @param        int        $last_modified        Timestamp of when the page was last modified
810
         * @param        int        $expiration        Timestamp of when should the requested page expire from cache
811
         * @return        void
812
         *
813
         * modified by ci-phpunit-test
814
         */
815
        public function set_cache_header($last_modified, $expiration)
816
        {
817
                $max_age = $expiration - $_SERVER['REQUEST_TIME'];
818

819
                if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']))
820
                {
821
                        $this->set_status_header(304);
822
                        exit;
823
                }
824

825
//                header('Pragma: public');
826
//                header('Cache-Control: max-age='.$max_age.', public');
827
//                header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT');
828
//                header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT');
829
        }
830

831
        // --------------------------------------------------------------------
832

833
        /**
834
         * Byte-safe strlen()
835
         *
836
         * @param        string        $str
837
         * @return        int
838
         */
839
        protected static function strlen($str)
840
        {
841
                return (self::$func_overload)
842
                        ? mb_strlen($str, '8bit')
843
                        : strlen($str);
844
        }
845

846
        // --------------------------------------------------------------------
847

848
        /**
849
         * Byte-safe substr()
850
         *
851
         * @param        string        $str
852
         * @param        int        $start
853
         * @param        int        $length
854
         * @return        string
855
         */
856
        protected static function substr($str, $start, $length = NULL)
857
        {
858
                if (self::$func_overload)
859
                {
860
                        // mb_substr($str, $start, null, '8bit') returns an empty
861
                        // string on PHP 5.3
862
                        isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start);
863
                        return mb_substr($str, $start, $length, '8bit');
864
                }
865

866
                return isset($length)
867
                        ? substr($str, $start, $length)
868
                        : substr($str, $start);
869
        }
870
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc