JSON response provider
This commit is contained in:
parent
14a8e9e9d5
commit
6d94263ede
@ -146,6 +146,7 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/vlucas/phpdotenv" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/voku/portable-ascii" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/sanctum" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
@ -153,6 +153,7 @@
|
||||
<path value="$PROJECT_DIR$/vendor/awssat/discord-notification-channel" />
|
||||
<path value="$PROJECT_DIR$/vendor/berkayk/onesignal-laravel" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/psr-http-message-bridge" />
|
||||
<path value="$PROJECT_DIR$/vendor/laravel/sanctum" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.3" />
|
||||
|
17
app/Facades/JSON.php
Normal file
17
app/Facades/JSON.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Facades;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class JSON extends Facade
|
||||
{
|
||||
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'json';
|
||||
}
|
||||
|
||||
}
|
116
app/Helpers/JSON.php
Normal file
116
app/Helpers/JSON.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
/**
|
||||
* Class JSON - Used for JSON responses.
|
||||
* @package App\Helpers
|
||||
*/
|
||||
class JSON
|
||||
{
|
||||
|
||||
protected $type, $status, $message, $code, $data;
|
||||
|
||||
/**
|
||||
* @param mixed $type
|
||||
*/
|
||||
public function setResponseType($type): JSON
|
||||
{
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $status
|
||||
* @return JSON
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @return JSON
|
||||
*/
|
||||
public function setMessage($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $code
|
||||
* @return JSON
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @return JSON
|
||||
*/
|
||||
public function setData($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function build($headers = [])
|
||||
{
|
||||
$response = [
|
||||
'status' => $this->getStatus(),
|
||||
'message' => $this->getMessage(),
|
||||
'type' => $this->getType(),
|
||||
'response' => $this->getData()
|
||||
];
|
||||
|
||||
return response($response, $this->getCode(), $headers);
|
||||
}
|
||||
|
||||
}
|
31
app/Providers/JSONProvider.php
Normal file
31
app/Providers/JSONProvider.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Helpers\JSON;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class JSONProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
App::bind('json', function () {
|
||||
return new JSON();
|
||||
});
|
||||
}
|
||||
}
|
@ -244,6 +244,7 @@ return [
|
||||
\App\Providers\MojangStatusProvider::class,
|
||||
\App\Providers\OptionsProvider::class,
|
||||
App\Providers\DigitalStorageProvider::class,
|
||||
App\Providers\JSONProvider::class,
|
||||
|
||||
],
|
||||
|
||||
@ -301,6 +302,7 @@ return [
|
||||
'Markdown' => GrahamCampbell\Markdown\Facades\Markdown::class,
|
||||
'ContextAwareValidator' => App\Facades\ContextAwareValidation::class,
|
||||
'Settings' => App\Facades\Options::class,
|
||||
'JSON' => App\Facades\JSON::class
|
||||
|
||||
],
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user