Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit fb2572b

Browse files
author
Andrey Helldar
committed
Removed FormRequest
1 parent eb4afa4 commit fb2572b

File tree

7 files changed

+60
-108
lines changed

7 files changed

+60
-108
lines changed

.styleci.yml

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
preset: psr2
22

33
enabled:
4-
- align_double_arrow
5-
- align_equals
6-
- align_phpdoc
7-
- blank_line_after_opening_tag
8-
- blank_line_before_continue
9-
- blank_line_before_declare
10-
- blank_line_before_throw
11-
- blank_line_before_try
12-
- concat_with_spaces
13-
- const_separation
14-
- ereg_to_preg
15-
- extra_empty_lines
16-
- lowercase_cast
17-
- method_separation
18-
- multiline_array_trailing_comma
19-
- no_empty_lines_after_phpdocs
20-
- no_empty_phpdoc
21-
- no_unused_imports
22-
- operators_spaces
23-
- ordered_use
24-
- phpdoc_indent
25-
- phpdoc_inline_tag
26-
- phpdoc_no_access
27-
- phpdoc_no_package
28-
- phpdoc_order
29-
- phpdoc_scalar
30-
- phpdoc_separation
31-
- phpdoc_to_comment
32-
- phpdoc_trim
33-
- phpdoc_type_to_var
34-
- phpdoc_types
35-
- phpdoc_var_without_name
36-
- property_separation
37-
- return
38-
- return_type_declaration
39-
- self_accessor
40-
- short_array_syntax
41-
- short_bool_cast
42-
- single_quote
43-
- spaces_after_semicolon
44-
- spaces_cast
45-
- standardize_not_equal
46-
- ternary_spaces
47-
- trim_array_spaces
48-
- unary_operators_spaces
49-
- unneeded_control_parentheses
50-
- whitespacy_lines
4+
- align_double_arrow
5+
- align_equals
6+
- align_phpdoc
7+
- blank_line_after_opening_tag
8+
- blank_line_before_continue
9+
- blank_line_before_declare
10+
- blank_line_before_throw
11+
- blank_line_before_try
12+
- concat_with_spaces
13+
- const_separation
14+
- ereg_to_preg
15+
- extra_empty_lines
16+
- lowercase_cast
17+
- method_separation
18+
- multiline_array_trailing_comma
19+
- no_empty_lines_after_phpdocs
20+
- no_empty_phpdoc
21+
- no_unused_imports
22+
- operators_spaces
23+
- ordered_use
24+
- phpdoc_indent
25+
- phpdoc_inline_tag
26+
- phpdoc_no_access
27+
- phpdoc_no_package
28+
- phpdoc_order
29+
- phpdoc_scalar
30+
- phpdoc_separation
31+
- phpdoc_to_comment
32+
- phpdoc_trim
33+
- phpdoc_type_to_var
34+
- phpdoc_types
35+
- phpdoc_var_without_name
36+
- property_separation
37+
- return
38+
- return_type_declaration
39+
- self_accessor
40+
- short_array_syntax
41+
- short_bool_cast
42+
- single_quote
43+
- spaces_after_semicolon
44+
- spaces_cast
45+
- standardize_not_equal
46+
- ternary_spaces
47+
- trim_array_spaces
48+
- unary_operators_spaces
49+
- unneeded_control_parentheses
50+
- whitespacy_lines

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,9 @@ returned with code 200:
158158

159159
If the first parameter is a number, then the decryption of the error by code will be returned. In other cases, the value of the passed variable will be returned.
160160

161-
### FormRequest for API in Laravel 5+ framework
161+
### Using in Laravel 5+ framework
162162

163-
You then must change your `Illuminate\Foundation\Http\FormRequest` to extend `Helldar\ApiResponse\Requests\FormRequest` in `app/Http/Requests/*` files:
164-
165-
```php
166-
use Helldar\ApiResponse\Requests\FormRequest;
167-
168-
class MyRequest extends FormRequest {
169-
//
170-
}
171-
```
172-
173-
Next, in `app/Exceptions/Handler.php` file change a `render` method to:
163+
To use you need to add three methods to the file `app/Exceptions/Handler.php`:
174164

175165
```php
176166
protected function unauthenticated($request, AuthenticationException $exception)

src/Requests/FormRequest.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/ServiceProvider.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,7 @@
22

33
namespace Helldar\ApiResponse;
44

5-
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
6-
7-
class ServiceProvider extends IlluminateServiceProvider
5+
class ServiceProvider extends Illuminate\Support\ServiceProvider
86
{
9-
/**
10-
* Perform post-registration booting of services.
11-
*
12-
* @return void
13-
*/
14-
public function boot()
15-
{
16-
//
17-
}
18-
19-
/**
20-
* Register bindings in the container.
21-
*
22-
* @return void
23-
*/
24-
public function register()
25-
{
26-
//
27-
}
7+
// 😀
288
}

src/Services/ApiResponseService.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class ApiResponseService
88
{
99
/**
10-
* @var string|int|array|object
10+
* @var null|string|int|array|object
1111
*/
1212
protected $content = null;
1313

@@ -42,7 +42,7 @@ public function status($status = 200)
4242
}
4343

4444
/**
45-
* @param string|int|array|object $content
45+
* @param null|string|int|array|object $content
4646
*
4747
* @return $this
4848
*/
@@ -67,8 +67,6 @@ public function headers($headers = [])
6767

6868
/**
6969
* @return \Symfony\Component\HttpFoundation\JsonResponse
70-
*
71-
* @deprecated
7270
*/
7371
public function send()
7472
{
@@ -103,7 +101,7 @@ protected function setErrorContent()
103101
}
104102

105103
/**
106-
* @return JsonResponse
104+
* @return \Symfony\Component\HttpFoundation\JsonResponse
107105
*/
108106
protected function jsonResponse()
109107
{

src/helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/**
66
* Return a new response from the application.
77
*
8-
* @param null $content
9-
* @param int $status_code
8+
* @param null|string|int|array|object $content
9+
* @param int $status_code
1010
* @param array $headers
1111
*
1212
* @return \Symfony\Component\HttpFoundation\JsonResponse

tests/ApiResponseServiceTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ public function testInit()
1111
$this->assertJson(api_response('ok')->getContent());
1212
$this->assertJson(api_response('fail', 400)->getContent());
1313

14-
$this->assertJsonStringEqualsJsonString(api_response('ok')->getContent(), json_encode('ok'));
1514
$this->assertEquals(api_response('ok')->getContent(), json_encode('ok'));
1615

1716
$this->assertEquals(api_response('ok', 401)->getStatusCode(), 401);
1817
$this->assertEquals(api_response('ok')->getStatusCode(), 200);
18+
}
1919

20+
public function testStructure()
21+
{
22+
$this->assertJsonStringEqualsJsonString(api_response('ok')->getContent(), json_encode('ok'));
2023
$this->assertJsonStringEqualsJsonString(api_response('fail', 400)->getContent(), json_encode(['error' => ['code' => 400, 'msg' => 'fail']]));
21-
2224
$this->assertJsonStringNotEqualsJsonString(api_response('fail', 400)->getContent(), json_encode('ok'));
2325
}
2426
}

0 commit comments

Comments
 (0)