PHP Classes

File: src/Json.php

Recommend this page to a friend!
  Classes of Joseluis Laso   Asynchronous Long Server Tasks   src/Json.php   Download  
File: src/Json.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Asynchronous Long Server Tasks
Start background tasks and query progress status
Author: By
Last change:
Date: 8 years ago
Size: 617 bytes
 

Contents

Class file image Download
<?php

namespace JLaso\ToolsLib;

class
Json
{

    public static function
dump($data)
    {
       
header('Content-Type: application/json');
        print
json_encode($data);
    }

    public static function
error($reason)
    {
       
self::dump(array(
           
'result' => false,
           
'reason' => $reason,
        ));
    }

    public static function
ok($data = array())
    {
       
$data['result'] = true;
       
self::dump($data);
    }

    public static function
getBodyParams()
    {
       
$postBody = file_get_contents("php://input");

        return
json_decode($postBody, true);
    }

}