-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
888c493
commit e685017
Showing
7 changed files
with
159 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
|
||
namespace Blueprint\Models\Statements; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
class RespondStatement | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $status = 200; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $content; | ||
|
||
public function __construct(string $data) | ||
{ | ||
if (ctype_digit($data)) { | ||
$this->status = (int)$data; | ||
} else { | ||
$this->content = $data; | ||
} | ||
} | ||
|
||
public function status(): int | ||
{ | ||
return $this->status; | ||
} | ||
|
||
public function content(): ?string | ||
{ | ||
return $this->content; | ||
} | ||
|
||
public function output() | ||
{ | ||
if ($this->content()) { | ||
return 'return $' . $this->content . ';'; | ||
} | ||
|
||
return sprintf('return response()->noContent(%s);', $this->status() === 204 ? '' : $this->status()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Api\Post; | ||
use Illuminate\Http\Request; | ||
|
||
class PostController extends Controller | ||
{ | ||
/** | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
$posts = Post::all(); | ||
|
||
return $posts; | ||
} | ||
|
||
/** | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
return response()->noContent(); | ||
} | ||
|
||
/** | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function error(Request $request) | ||
{ | ||
return response()->noContent(400); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
controllers: | ||
Api/Post: | ||
index: | ||
query: all:posts | ||
respond: posts | ||
store: | ||
respond: 204 | ||
error: | ||
respond: 400 |