vue: inheritPoint 샘플 작성
This commit is contained in:
+26
-9
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
use phpDocumentor\Reflection\Types\Boolean;
|
||||
|
||||
class WebUtil
|
||||
{
|
||||
private function __construct()
|
||||
@@ -51,31 +53,31 @@ class WebUtil
|
||||
if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0) {
|
||||
throw new \Exception('Request method must be POST!');
|
||||
}
|
||||
|
||||
|
||||
//Make sure that the content type of the POST request has been set to application/json
|
||||
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
|
||||
if (strcasecmp($contentType, 'application/json') != 0) {
|
||||
throw new \Exception('Content type must be: application/json');
|
||||
}
|
||||
|
||||
|
||||
//Receive the RAW post data.
|
||||
$content = trim(file_get_contents("php://input"));
|
||||
|
||||
|
||||
//Attempt to decode the incoming RAW post data from JSON.
|
||||
$decoded = Json::decode($content);
|
||||
|
||||
|
||||
|
||||
|
||||
$jsonError = json_last_error();
|
||||
|
||||
|
||||
//In some cases, this will happen.
|
||||
if (is_null($decoded) && $jsonError == JSON_ERROR_NONE) {
|
||||
throw new \Exception('Could not decode JSON!');
|
||||
}
|
||||
|
||||
|
||||
//If an error exists.
|
||||
if ($jsonError != JSON_ERROR_NONE) {
|
||||
$error = 'Could not decode JSON! ';
|
||||
|
||||
|
||||
//Use a switch statement to figure out the exact error.
|
||||
switch ($jsonError) {
|
||||
case JSON_ERROR_DEPTH:
|
||||
@@ -99,7 +101,7 @@ class WebUtil
|
||||
}
|
||||
throw new \Exception($error);
|
||||
}
|
||||
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
@@ -176,6 +178,21 @@ class WebUtil
|
||||
return "<link rel='stylesheet' type='text/css' href='{$path}{$tail}' />\n";
|
||||
}
|
||||
|
||||
public static function printStaticValues(array $values, bool $pretty=true){
|
||||
if(!count($values)){
|
||||
return;
|
||||
}
|
||||
$lines = ["<script>"];
|
||||
|
||||
foreach($values as $key => $value){
|
||||
$lines[] = "var {$key} = ".Json::encode($value, Json::EMPTY_ARRAY_IS_DICT | ($pretty?Json::PRETTY:0));
|
||||
}
|
||||
|
||||
$lines[] = "</script>";
|
||||
|
||||
return join("\n", $lines);
|
||||
}
|
||||
|
||||
protected static $jsFilesList = [];
|
||||
public static function pushJSFile(string $path){
|
||||
static::$jsFilesList[] = $path;
|
||||
|
||||
Reference in New Issue
Block a user