Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit 1c43f43

Browse files
committed
✨ add camelCase alias methods
Signed-off-by: otengkwame <[email protected]>
1 parent 6d854bb commit 1c43f43

File tree

1 file changed

+248
-0
lines changed

1 file changed

+248
-0
lines changed

framework/core/Output.php

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ public function get_output()
168168
return $this->final_output;
169169
}
170170

171+
/**
172+
* Get Output
173+
*
174+
* Returns the current output string.
175+
*
176+
* @return string
177+
*/
178+
public function getOutput()
179+
{
180+
return $this->get_output();
181+
}
182+
171183
// --------------------------------------------------------------------
172184

173185
/**
@@ -184,6 +196,20 @@ public function set_output($output)
184196
return $this;
185197
}
186198

199+
/**
200+
* Set Output
201+
*
202+
* Sets the output string.
203+
*
204+
* @param string $output Output data
205+
* @return CI_Output
206+
*/
207+
public function setOutput($output)
208+
{
209+
$this->final_output = $output;
210+
return $this;
211+
}
212+
187213
// --------------------------------------------------------------------
188214

189215
/**
@@ -195,6 +221,20 @@ public function set_output($output)
195221
* @return CI_Output
196222
*/
197223
public function append_output($output)
224+
{
225+
$this->final_output .= $output;
226+
return $this;
227+
}
228+
229+
/**
230+
* Append Output
231+
*
232+
* Appends data onto the output string.
233+
*
234+
* @param string $output Data to append
235+
* @return CI_Output
236+
*/
237+
public function appendOutput($output)
198238
{
199239
$this->final_output .= $output;
200240
return $this;
@@ -228,6 +268,32 @@ public function set_header($header, $replace = true)
228268
return $this;
229269
}
230270

271+
/**
272+
* Set Header
273+
*
274+
* Lets you set a server header which will be sent with the final output.
275+
*
276+
* Note: If a file is cached, headers will not be sent.
277+
* @todo We need to figure out how to permit headers to be cached.
278+
*
279+
* @param string $header Header
280+
* @param bool $replace Whether to replace the old header value, if already set
281+
* @return CI_Output
282+
*/
283+
public function setHeader($header, $replace = true)
284+
{
285+
// If zlib.output_compression is enabled it will compress the output,
286+
// but it will not modify the content-length header to compensate for
287+
// the reduction, causing the browser to hang waiting for more data.
288+
// We'll just skip content-length in those cases.
289+
if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) === 0) {
290+
return $this;
291+
}
292+
293+
$this->headers[] = [$header, $replace];
294+
return $this;
295+
}
296+
231297
// --------------------------------------------------------------------
232298

233299
/**
@@ -265,6 +331,41 @@ public function set_content_type($mime_type, $charset = null)
265331
return $this;
266332
}
267333

334+
/**
335+
* Set Content-Type Header
336+
*
337+
* @param string $mime_type Extension of the file we're outputting
338+
* @param string $charset Character set (default: null)
339+
* @return CI_Output
340+
*/
341+
public function setContentType($mime_type, $charset = null)
342+
{
343+
if (strpos($mime_type, '/') === false) {
344+
$extension = ltrim($mime_type, '.');
345+
346+
// Is this extension supported?
347+
if (isset($this->mimes[$extension])) {
348+
$mime_type = &$this->mimes[$extension];
349+
350+
if (is_array($mime_type)) {
351+
$mime_type = current($mime_type);
352+
}
353+
}
354+
}
355+
356+
$this->mime_type = $mime_type;
357+
358+
if (empty($charset)) {
359+
$charset = config_item('charset');
360+
}
361+
362+
$header = 'Content-Type: ' . $mime_type
363+
. (empty($charset) ? '' : '; charset=' . $charset);
364+
365+
$this->headers[] = [$header, true];
366+
return $this;
367+
}
368+
268369
// --------------------------------------------------------------------
269370

270371
/**
@@ -283,6 +384,22 @@ public function get_content_type()
283384
return 'text/html';
284385
}
285386

387+
/**
388+
* Get Current Content-Type Header
389+
*
390+
* @return string 'text/html', if not already set
391+
*/
392+
public function getContentType()
393+
{
394+
for ($i = 0, $c = count($this->headers); $i < $c; $i++) {
395+
if (sscanf($this->headers[$i][0], 'Content-Type: %[^;]', $content_type) === 1) {
396+
return $content_type;
397+
}
398+
}
399+
400+
return 'text/html';
401+
}
402+
286403
// --------------------------------------------------------------------
287404

288405
/**
@@ -317,6 +434,38 @@ public function get_header($header)
317434
return null;
318435
}
319436

437+
/**
438+
* Get Header
439+
*
440+
* @param string $header
441+
* @return string
442+
*/
443+
public function getHeader($header)
444+
{
445+
// We only need [x][0] from our multi-dimensional array
446+
$header_lines = array_map(function ($headers) {
447+
return array_shift($headers);
448+
}, $this->headers);
449+
450+
$headers = array_merge(
451+
$header_lines,
452+
headers_list()
453+
);
454+
455+
if (empty($headers) or empty($header)) {
456+
return null;
457+
}
458+
459+
// Count backwards, in order to get the last matching header
460+
for ($c = count($headers) - 1; $c > -1; $c--) {
461+
if (strncasecmp($header, $headers[$c], $l = self::strlen($header)) === 0) {
462+
return trim(self::substr($headers[$c], $l + 1));
463+
}
464+
}
465+
466+
return null;
467+
}
468+
320469
// --------------------------------------------------------------------
321470

322471
/**
@@ -335,6 +484,44 @@ public function set_status_header($code = 200, $text = '')
335484
return $this;
336485
}
337486

487+
/**
488+
* Set HTTP Status Header
489+
*
490+
* As of version 1.7.2, this is an alias for common function
491+
* set_status_header().
492+
*
493+
* @param int $code Status code (default: 200)
494+
* @param string $text Optional message
495+
* @return CI_Output
496+
*/
497+
public function setStatusHeader($code = 200, $text = '')
498+
{
499+
set_status_header($code, $text);
500+
return $this;
501+
}
502+
503+
// --------------------------------------------------------------------
504+
505+
/**
506+
* Return an instance with the specified header appended with the given value.
507+
*
508+
* Existing values for the specified header will be maintained. The new
509+
* value(s) will be appended to the existing list. If the header did not
510+
* exist previously, it will be added.
511+
*
512+
* PSR-7 standard
513+
*
514+
* @param string $name Case-insensitive header field name to add.
515+
* @param string|string[] $value Header value(s).
516+
* @return self
517+
*/
518+
public function withAddedHeader($name, $value)
519+
{
520+
$this->set_header("{$name}: {$value}");
521+
522+
return $this;
523+
}
524+
338525
// --------------------------------------------------------------------
339526

340527
/**
@@ -349,6 +536,18 @@ public function enable_profiler($val = true)
349536
return $this;
350537
}
351538

539+
/**
540+
* Enable/disable Profiler
541+
*
542+
* @param bool $val true to enable or false to disable
543+
* @return CI_Output
544+
*/
545+
public function enableProfiler($val = true)
546+
{
547+
$this->enable_profiler = is_bool($val) ? $val : true;
548+
return $this;
549+
}
550+
352551
// --------------------------------------------------------------------
353552

354553
/**
@@ -374,6 +573,29 @@ public function set_profiler_sections($sections)
374573
return $this;
375574
}
376575

576+
/**
577+
* Set Profiler Sections
578+
*
579+
* Allows override of default/config settings for
580+
* Profiler section display.
581+
*
582+
* @param array $sections Profiler sections
583+
* @return CI_Output
584+
*/
585+
public function setProfilerSections($sections)
586+
{
587+
if (isset($sections['query_toggle_count'])) {
588+
$this->_profiler_sections['query_toggle_count'] = (int) $sections['query_toggle_count'];
589+
unset($sections['query_toggle_count']);
590+
}
591+
592+
foreach ($sections as $section => $enable) {
593+
$this->_profiler_sections[$section] = ($enable !== false);
594+
}
595+
596+
return $this;
597+
}
598+
377599
// --------------------------------------------------------------------
378600

379601
/**
@@ -736,6 +958,17 @@ public function delete_cache($uri = '')
736958
return true;
737959
}
738960

961+
/**
962+
* Delete cache
963+
*
964+
* @param string $uri URI string
965+
* @return bool
966+
*/
967+
public function deleteCache($uri = '')
968+
{
969+
return $this->delete_cache($uri);
970+
}
971+
739972
// --------------------------------------------------------------------
740973

741974
/**
@@ -763,6 +996,21 @@ public function set_cache_header($last_modified, $expiration)
763996
header('Last-modified: ' . gmdate('D, d M Y H:i:s', $last_modified) . ' GMT');
764997
}
765998

999+
/**
1000+
* Set Cache Header
1001+
*
1002+
* Set the HTTP headers to match the server-side file cache settings
1003+
* in order to reduce bandwidth.
1004+
*
1005+
* @param int $last_modified Timestamp of when the page was last modified
1006+
* @param int $expiration Timestamp of when should the requested page expire from cache
1007+
* @return void
1008+
*/
1009+
public function setCacheHeader($last_modified, $expiration)
1010+
{
1011+
return $this->set_cache_header($last_modified, $expiration);
1012+
}
1013+
7661014
// --------------------------------------------------------------------
7671015

7681016
/**

0 commit comments

Comments
 (0)