8000 Merge pull request #31 from wizardstechnologies/feat/rest-view · wizardstechnologies/php-rest-api@a665d63 · GitHub
[go: up one dir, main page]

Skip to content

Commit a665d63

Browse files
authored
Merge pull request #31 from wizardstechnologies/feat/rest-view
feat: add restview
2 parents 521631f + f4adddc commit a665d63

File tree

6 files changed

+69
-15
lines changed

6 files changed

+69
-15
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: php
2+
install:
3+
- composer install
4+
php:
5+
- '7.3'
6+
- '7.4'

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Wizards Technologies' PHP REST API Library
22
A framework agnostic PHP library based on [fractal](https://fractal.thephpleague.com/) to help you craft beautiful REST APIs.
33

4+
[![Build Status](https://travis-ci.org/wizardstechnologies/php-rest-api.svg?branch=master)](https://travis-ci.org/wizardstechnologies/php-rest-api)
5+
46
## Goals
57
The main goal is to provide an easy to use and powerful REST API library that seamlessly integrates with modern frameworks.
68

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
}
1010
],
1111
"require": {
12-
"php": ">=7.1",
12+
"php": ">=7.3",
1313
"psr/http-message": "^1.0",
14-
"league/fractal": "^0.17.0",
14+
"league/fractal": "^0.19.2",
1515
"symfony/options-resolver": "^4.1|^5.0"
1616
},
1717
"require-dev": {

src/WizardsRest/Annotation/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace WizardsRest\Annotation;
44

55
/**
6-
* Define an type for serialization (useful for jsonapi)
6+
* Define a serialization type. In jsonapi, it defines a entity type.
77
*
88
* @Annotation
99
*

src/WizardsRest/Exception/HttpException.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace WizardsRest\Exception;
44

55
/**
6-
* HttpException.
6+
* A simple HttpException.
77
* The whole symfony or laravel http was kinda heavy to include.< 8000 /span>
88
*
99
* @author Romain Richard
@@ -15,23 +15,14 @@ class HttpException extends \RuntimeException
1515
*/
1616
private $statusCode;
1717

18-
/**
19-
* HttpException constructor.
20-
*
21-
* @param int $statusCode
22-
* @param string $message
23-
*/
24-
public function __construct(int $statusCode = 500, string $message = 'Server Error')
18+
public function __construct(int $statusCode = 500, ?string $message = null)
2519
{
2620
$this->statusCode = $statusCode;
2721

2822
parent::__construct($message);
2923
}
3024

31-
/**
32-
* @return int
33-
*/
34-
public function getStatusCode()
25+
public function getStatusCode(): int
3526
{
3627
return $this->statusCode;
3728
}

src/WizardsRest/RestView.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace WizardsRest;
4+
5+
/**
6+
* An entity that represents a REST response. Usefull to pass status code with sucessful responses.
7+
*/
8+
class RestView
9+
{
10+
/**
11+
* @var int
12+
*/
13+
private $code;
14+
15+
/**
16+
* @var string|array
17+
*/
18+
private $content;
19+
20+
public function __construct(int $code, $content)
21+
{
22+
$this->code = $code;
23+
$this->content = $content;
24+
}
25+
26+
public function getCode(): int
27+
{
28+
return $this->code;
29+
}
30+
31+
public function setCode(int $code): self
32+
{
33+
$this->code = $code;
34+
35+
return $this;
36+
}
37+
38+
/**
39+
* @return array|string
40+
*/
41+
public function getContent()
42+
{
43+
return $this->content;
44+
}
45+
46+
/**
47+
* @param array|string $content
48+
*/
49+
public function setContent($content): self
50+
{
51+
$this->content = $content;
52+
53+
return $this;
54+
}
55+
}

0 commit comments

Comments
 (0)
0