Skip to content

Commit d11a023

Browse files
author
Marcel Gwerder
committed
Switched to PSR-2
1 parent 76756c2 commit d11a023

13 files changed

+1413
-1562
lines changed

.travis.yml

100755100644
File mode changed.

composer.json

100755100644
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"name": "marcelgwerder/laravel-api-handler",
3-
"description": "Package providing helper functions for a Laravel REST-API ",
4-
"keywords": ["api", "laravel", "rest", "url", "parse", "mysql"],
5-
"homepage": "http://github.com/marcelgwerder/laravel-api-handler",
6-
"license": "MIT",
7-
"authors": [
8-
{
9-
"name": "Marcel Gwerder",
10-
"email": "[email protected]"
11-
}
12-
],
13-
"require": {
14-
"php": ">=5.4.0",
15-
"illuminate/support": "~5.0",
16-
"illuminate/database": "~5.0",
17-
"illuminate/http": "~5.0"
18-
},
19-
"require-dev": {
20-
"phpunit/phpunit": "~4.5",
21-
"mockery/mockery": "~0.9"
22-
},
23-
"autoload": {
24-
"psr-4": {
25-
"Marcelgwerder\\ApiHandler\\": "src"
26-
}
27-
},
28-
"minimum-stability": "stable"
2+
"name": "marcelgwerder/laravel-api-handler",
3+
"description": "Package providing helper functions for a Laravel REST-API ",
4+
"keywords": ["api", "laravel", "rest", "url", "parse", "mysql"],
5+
"homepage": "http://github.com/marcelgwerder/laravel-api-handler",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Marcel Gwerder",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"php": ">=5.4.0",
15+
"illuminate/support": "~5.0",
16+
"illuminate/database": "~5.0",
17+
"illuminate/http": "~5.0"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "~4.5",
21+
"mockery/mockery": "~0.9"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"Marcelgwerder\\ApiHandler\\": "src"
26+
}
27+
},
28+
"minimum-stability": "stable"
2929
}

config/apihandler.php

100755100644
Lines changed: 76 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,90 @@
22

33
return [
44

5-
/*
6-
|--------------------------------------------------------------------------
7-
| Query Parameter Prefix
8-
|--------------------------------------------------------------------------
9-
|
10-
| Defines the prefix used for the predefined query parameters such as:
11-
| fields, sort or with
12-
|
13-
*/
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Query Parameter Prefix
8+
|--------------------------------------------------------------------------
9+
|
10+
| Defines the prefix used for the predefined query parameters such as:
11+
| fields, sort or with
12+
|
13+
*/
1414

15-
'prefix' => '_',
15+
'prefix' => '_',
1616

17-
/*
18-
|--------------------------------------------------------------------------
19-
| Envelope
20-
|--------------------------------------------------------------------------
21-
|
22-
| Define whether to use an envelope for meta data or not. By default the
23-
| meta data will be in the response header not in the body.
24-
|
25-
*/
17+
/*
18+
|--------------------------------------------------------------------------
19+
| Envelope
20+
|--------------------------------------------------------------------------
21+
|
22+
| Define whether to use an envelope for meta data or not. By default the
23+
| meta data will be in the response header not in the body.
24+
|
25+
*/
2626

27-
'envelope' => false,
27+
'envelope' => false,
2828

29-
/*
30-
|--------------------------------------------------------------------------
31-
| Fulltext Search
32-
|--------------------------------------------------------------------------
33-
|
34-
| The type of fulltext search, either "default" or "native".
35-
| Native fulltext search for InnoDB tables is only supported by MySQL versions >= 5.6.
36-
|
37-
*/
29+
/*
30+
|--------------------------------------------------------------------------
31+
| Fulltext Search
32+
|--------------------------------------------------------------------------
33+
|
34+
| The type of fulltext search, either "default" or "native".
35+
| Native fulltext search for InnoDB tables is only supported by MySQL versions >= 5.6.
36+
|
37+
*/
3838

39-
'fulltext' => 'default',
39+
'fulltext' => 'default',
4040

41-
/*
42-
|--------------------------------------------------------------------------
43-
| Fulltext Search Score Column
44-
|--------------------------------------------------------------------------
45-
|
46-
| The name of the column containing the fulltext search score in native
47-
| fulltext search mode.
48-
|
49-
*/
41+
/*
42+
|--------------------------------------------------------------------------
43+
| Fulltext Search Score Column
44+
|--------------------------------------------------------------------------
45+
|
46+
| The name of the column containing the fulltext search score in native
47+
| fulltext search mode.
48+
|
49+
*/
5050

51-
'fulltext_score_column' => '_score',
51+
'fulltext_score_column' => '_score',
5252

53-
/*
54-
|--------------------------------------------------------------------------
55-
| Errors
56-
|--------------------------------------------------------------------------
57-
|
58-
| These arrays define the default error messages and the corresponding http
59-
| status codes.
60-
|
61-
*/
53+
/*
54+
|--------------------------------------------------------------------------
55+
| Errors
56+
|--------------------------------------------------------------------------
57+
|
58+
| These arrays define the default error messages and the corresponding http
59+
| status codes.
60+
|
61+
*/
6262

63-
'errors' => [
64-
'ResourceNotFound' => ['http_code' => 404, 'message' => 'The requested resource could not be found but may be available again in the future.'],
65-
'InternalError' => ['http_code' => 500, 'message' => 'Internal server error'],
66-
'Unauthorized' => ['http_code' => 401, 'message' => 'Authentication is required and has failed or has not yet been provided'],
67-
'Forbidden' => ['http_code' => 403, 'message' => 'You don\'t have enough permissions to access this resource'],
68-
'ToManyRequests' => ['http_code' => 429, 'message' => 'You have sent too many requests in a specific timespan'],
69-
'InvalidInput' => ['http_code' => 400, 'message' => 'The submited data is not valid'],
70-
'InvalidQueryParameter' => ['http_code' => 400, 'message' => 'Invalid parameter'],
71-
'UnknownResourceField' => ['http_code' => 400, 'message' => 'Unknown field ":field"'],
72-
'UnknownResourceRelation' => ['http_code' => 400, 'message' => 'Unknown relation ":relation"']
73-
],
63+
'errors' => [
64+
'ResourceNotFound' => ['http_code' => 404, 'message' => 'The requested resource could not be found but may be available again in the future.'],
65+
'InternalError' => ['http_code' => 500, 'message' => 'Internal server error'],
66+
'Unauthorized' => ['http_code' => 401, 'message' => 'Authentication is required and has failed or has not yet been provided'],
67+
'Forbidden' => ['http_code' => 403, 'message' => 'You don\'t have enough permissions to access this resource'],
68+
'ToManyRequests' => ['http_code' => 429, 'message' => 'You have sent too many requests in a specific timespan'],
69+
'InvalidInput' => ['http_code' => 400, 'message' => 'The submited data is not valid'],
70+
'InvalidQueryParameter' => ['http_code' => 400, 'message' => 'Invalid parameter'],
71+
'UnknownResourceField' => ['http_code' => 400, 'message' => 'Unknown field ":field"'],
72+
'UnknownResourceRelation' => ['http_code' => 400, 'message' => 'Unknown relation ":relation"'],
73+
],
7474

75-
/*
76-
|--------------------------------------------------------------------------
77-
| Predefined Errors
78-
|--------------------------------------------------------------------------
79-
|
80-
| Link the errors the api handler uses internaly with the the respective
81-
| error above.
82-
|
83-
*/
75+
/*
76+
|--------------------------------------------------------------------------
77+
| Predefined Errors
78+
|--------------------------------------------------------------------------
79+
|
80+
| Link the errors the api handler uses internaly with the the respective
81+
| error above.
82+
|
83+
*/
8484

85-
'internal_errors' => [
86-
'UnknownResourceField' => 'UnknownResourceField',
87-
'UnknownResourceRelation' => 'UnknownResourceRelation',
88-
'UnsupportedQueryParameter' => 'UnsupportedQueryParameter',
89-
'InvalidQueryParameter' => 'InvalidQueryParameter'
90-
]
91-
92-
];
85+
'internal_errors' => [
86+
'UnknownResourceField' => 'UnknownResourceField',
87+
'UnknownResourceRelation' => 'UnknownResourceRelation',
88+
'UnsupportedQueryParameter' => 'UnsupportedQueryParameter',
89+
'InvalidQueryParameter' => 'InvalidQueryParameter',
90+
],
91+
];

src/ApiHandler.php

100755100644
Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,86 @@
33
use Illuminate\Support\Facades\Input;
44
use Illuminate\Support\Facades\Response;
55

6-
class ApiHandler
6+
class ApiHandler
77
{
8-
/**
9-
* Return a new Result object for a single dataset
10-
*
11-
* @param mixed $queryBuilder Some kind of query builder instance
12-
* @param array|integer $identification Identification of the dataset to work with
13-
* @param array|boolean $queryParams The parameters used for parsing
14-
* @return Marcelgwerder\ApiHandler\Result Result object that provides getter methods
15-
*/
16-
public function parseSingle($queryBuilder, $identification, $queryParams = false)
17-
{
18-
if($queryParams === false) $queryParams = Input::get();
8+
/**
9+
* Return a new Result object for a single dataset
10+
*
11+
* @param mixed $queryBuilder Some kind of query builder instance
12+
* @param array|integer $identification Identification of the dataset to work with
13+
* @param array|boolean $queryParams The parameters used for parsing
14+
* @return Marcelgwerder\ApiHandler\Result Result object that provides getter methods
15+
*/
16+
public function parseSingle($queryBuilder, $identification, $queryParams = false)
17+
{
18+
if ($queryParams === false) {
19+
$queryParams = Input::get();
20+
}
1921

20-
$parser = new Parser($queryBuilder, $queryParams);
21-
$parser->parse($identification);
22+
$parser = new Parser($queryBuilder, $queryParams);
23+
$parser->parse($identification);
2224

23-
return new Result($parser);
24-
}
25+
return new Result($parser);
26+
}
2527

26-
/**
27-
* Return a new Result object for multiple datasets
28-
*
29-
* @param mixed $queryBuilder Some kind of query builder instance
30-
* @param array $fullTextSearchColumns Columns to search in fulltext search
31-
* @param array|boolean $queryParams A list of query parameter
32-
* @return Result
33-
*/
34-
public function parseMultiple($queryBuilder, $fullTextSearchColumns = array(), $queryParams = false)
35-
{
36-
if($queryParams === false) $queryParams = Input::get();
28+
/**
29+
* Return a new Result object for multiple datasets
30+
*
31+
* @param mixed $queryBuilder Some kind of query builder instance
32+
* @param array $fullTextSearchColumns Columns to search in fulltext search
33+
* @param array|boolean $queryParams A list of query parameter
34+
* @return Result
35+
*/
36+
public function parseMultiple($queryBuilder, $fullTextSearchColumns = array(), $queryParams = false)
37+
{
38+
if ($queryParams === false) {
39+
$queryParams = Input::get();
40+
}
3741

38-
$parser = new Parser($queryBuilder, $queryParams);
39-
$parser->parse($fullTextSearchColumns, true);
42+
$parser = new Parser($queryBuilder, $queryParams);
43+
$parser->parse($fullTextSearchColumns, true);
4044

41-
return new Result($parser);
42-
}
45+
return new Result($parser);
46+
}
4347

44-
/**
45-
* Return a new "created" response object
46-
*
47-
* @param array|object $object
48-
* @return Response
49-
*/
50-
public function created($object)
51-
{
52-
return Response::json($object, 201);
53-
}
48+
/**
49+
* Return a new "created" response object
50+
*
51+
* @param array|object $object
52+
* @return Response
53+
*/
54+
public function created($object)
55+
{
56+
return Response::json($object, 201);
57+
}
5458

55-
/**
56-
* Return a new "updated" response object
57-
*
58-
* @param array|object $object
59-
* @return Response
60-
*/
61-
public function updated($object = null)
62-
{
63-
if($object != null)
64-
{
65-
return Response::json($object, 200);
66-
}
67-
else
68-
{
69-
return Response::make(null, 204);
70-
}
71-
}
59+
/**
60+
* Return a new "updated" response object
61+
*
62+
* @param array|object $object
63+
* @return Response
64+
*/
65+
public function updated($object = null)
66+
{
67+
if ($object != null) {
68+
return Response::json($object, 200);
69+
} else {
70+
return Response::make(null, 204);
71+
}
72+
}
7273

73-
/**
74-
* Return a new "deleted" response object
75-
*
76-
* @param array|object $object
77-
* @return Response
78-
*/
79-
public function deleted($object = null) {
80-
if($object != null)
81-
{
82-
return Response::json($object, 200);
83-
}
84-
else
85-
{
86-
return Response::make(null, 204);
87-
}
88-
}
89-
}
74+
/**
75+
* Return a new "deleted" response object
76+
*
77+
* @param array|object $object
78+
* @return Response
79+
*/
80+
public function deleted($object = null)
81+
{
82+
if ($object != null) {
83+
return Response::json($object, 200);
84+
} else {
85+
return Response::make(null, 204);
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)