PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / src / http / document.php

document.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/src/http/document.php

108 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Helper class used to handle the interaction with HTTP documents.
16 *
17 * @since 1.5
18 */
19 class VBOHttpDocument
20 {
21 /**
22 * A reference to the application object.
23 *
24 * @var JApplication
25 */
26 protected $app;
27
28 /**
29 * Proxy used to construct the object.
30 *
31 * @param mixed $app The application instance. If not specified the
32 * current one will be used.
33 *
34 * @return self A new instance of this class.
35 */
36 public static function getInstance($app = null)
37 {
38 if (!$app)
39 {
40 $app = JFactory::getApplication();
41 }
42
43 return new static($app);
44 }
45
46 /**
47 * Class constructor.
48 *
49 * @param JApplication $app The application instance.
50 */
51 public function __construct($app)
52 {
53 $this->app = $app;
54 }
55
56 /**
57 * Method to close the application.
58 *
59 * @param integer $code The HTTP status code.
60 * @param mixed $buffer An optional string to display.
61 *
62 * @return void
63 */
64 public function close($code = 200, $buffer = null)
65 {
66 // force HTTP status code
67 $this->app->setHeader('status', $code, $replace = true);
68 $this->app->sendHeaders();
69
70 if (VBOPlatformDetection::isWordPress() && !headers_sent())
71 {
72 // this is necessary for the HTTP2 protocol
73 http_response_code($code);
74 }
75
76 if ($buffer)
77 {
78 // display buffer
79 echo $buffer;
80 }
81
82 // terminate session
83 $this->app->close();
84 }
85
86 /**
87 * Echoes the given JSON by using the right content type.
88 *
89 * @param mixed $json Either a JSON string or a non-scalar value.
90 * @param int $flags Bitmask for json_encode().
91 *
92 * @return void
93 */
94 public function json($json, $flags = 0)
95 {
96 $this->app->setHeader('Content-Type', 'application/json', $replace = true);
97
98 if (!is_string($json))
99 {
100 // stringify array/object
101 $json = json_encode($json, $flags);
102 }
103
104 // terminate session by echoing the given JSON
105 $this->close(200, $json);
106 }
107 }
108