Skip to content

Commit

Permalink
Switched to PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Gwerder committed Jun 18, 2015
1 parent 76756c2 commit d11a023
Show file tree
Hide file tree
Showing 13 changed files with 1,413 additions and 1,562 deletions.
Empty file modified .travis.yml
100755 → 100644
Empty file.
54 changes: 27 additions & 27 deletions composer.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
{
"name": "marcelgwerder/laravel-api-handler",
"description": "Package providing helper functions for a Laravel REST-API ",
"keywords": ["api", "laravel", "rest", "url", "parse", "mysql"],
"homepage": "http://github.com/marcelgwerder/laravel-api-handler",
"license": "MIT",
"authors": [
{
"name": "Marcel Gwerder",
"email": "info@marcelgwerder.ch"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "~5.0",
"illuminate/database": "~5.0",
"illuminate/http": "~5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.5",
"mockery/mockery": "~0.9"
},
"autoload": {
"psr-4": {
"Marcelgwerder\\ApiHandler\\": "src"
}
},
"minimum-stability": "stable"
"name": "marcelgwerder/laravel-api-handler",
"description": "Package providing helper functions for a Laravel REST-API ",
"keywords": ["api", "laravel", "rest", "url", "parse", "mysql"],
"homepage": "http://github.com/marcelgwerder/laravel-api-handler",
"license": "MIT",
"authors": [
{
"name": "Marcel Gwerder",
"email": "info@marcelgwerder.ch"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "~5.0",
"illuminate/database": "~5.0",
"illuminate/http": "~5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.5",
"mockery/mockery": "~0.9"
},
"autoload": {
"psr-4": {
"Marcelgwerder\\ApiHandler\\": "src"
}
},
"minimum-stability": "stable"
}
153 changes: 76 additions & 77 deletions config/apihandler.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,90 @@

return [

/*
|--------------------------------------------------------------------------
| Query Parameter Prefix
|--------------------------------------------------------------------------
|
| Defines the prefix used for the predefined query parameters such as:
| fields, sort or with
|
*/
/*
|--------------------------------------------------------------------------
| Query Parameter Prefix
|--------------------------------------------------------------------------
|
| Defines the prefix used for the predefined query parameters such as:
| fields, sort or with
|
*/

'prefix' => '_',
'prefix' => '_',

/*
|--------------------------------------------------------------------------
| Envelope
|--------------------------------------------------------------------------
|
| Define whether to use an envelope for meta data or not. By default the
| meta data will be in the response header not in the body.
|
*/
/*
|--------------------------------------------------------------------------
| Envelope
|--------------------------------------------------------------------------
|
| Define whether to use an envelope for meta data or not. By default the
| meta data will be in the response header not in the body.
|
*/

'envelope' => false,
'envelope' => false,

/*
|--------------------------------------------------------------------------
| Fulltext Search
|--------------------------------------------------------------------------
|
| The type of fulltext search, either "default" or "native".
| Native fulltext search for InnoDB tables is only supported by MySQL versions >= 5.6.
|
*/
/*
|--------------------------------------------------------------------------
| Fulltext Search
|--------------------------------------------------------------------------
|
| The type of fulltext search, either "default" or "native".
| Native fulltext search for InnoDB tables is only supported by MySQL versions >= 5.6.
|
*/

'fulltext' => 'default',
'fulltext' => 'default',

/*
|--------------------------------------------------------------------------
| Fulltext Search Score Column
|--------------------------------------------------------------------------
|
| The name of the column containing the fulltext search score in native
| fulltext search mode.
|
*/
/*
|--------------------------------------------------------------------------
| Fulltext Search Score Column
|--------------------------------------------------------------------------
|
| The name of the column containing the fulltext search score in native
| fulltext search mode.
|
*/

'fulltext_score_column' => '_score',
'fulltext_score_column' => '_score',

/*
|--------------------------------------------------------------------------
| Errors
|--------------------------------------------------------------------------
|
| These arrays define the default error messages and the corresponding http
| status codes.
|
*/
/*
|--------------------------------------------------------------------------
| Errors
|--------------------------------------------------------------------------
|
| These arrays define the default error messages and the corresponding http
| status codes.
|
*/

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

/*
|--------------------------------------------------------------------------
| Predefined Errors
|--------------------------------------------------------------------------
|
| Link the errors the api handler uses internaly with the the respective
| error above.
|
*/
/*
|--------------------------------------------------------------------------
| Predefined Errors
|--------------------------------------------------------------------------
|
| Link the errors the api handler uses internaly with the the respective
| error above.
|
*/

'internal_errors' => [
'UnknownResourceField' => 'UnknownResourceField',
'UnknownResourceRelation' => 'UnknownResourceRelation',
'UnsupportedQueryParameter' => 'UnsupportedQueryParameter',
'InvalidQueryParameter' => 'InvalidQueryParameter'
]

];
'internal_errors' => [
'UnknownResourceField' => 'UnknownResourceField',
'UnknownResourceRelation' => 'UnknownResourceRelation',
'UnsupportedQueryParameter' => 'UnsupportedQueryParameter',
'InvalidQueryParameter' => 'InvalidQueryParameter',
],
];
149 changes: 74 additions & 75 deletions src/ApiHandler.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,86 @@
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Response;

class ApiHandler
class ApiHandler
{
/**
* Return a new Result object for a single dataset
*
* @param mixed $queryBuilder Some kind of query builder instance
* @param array|integer $identification Identification of the dataset to work with
* @param array|boolean $queryParams The parameters used for parsing
* @return Marcelgwerder\ApiHandler\Result Result object that provides getter methods
*/
public function parseSingle($queryBuilder, $identification, $queryParams = false)
{
if($queryParams === false) $queryParams = Input::get();
/**
* Return a new Result object for a single dataset
*
* @param mixed $queryBuilder Some kind of query builder instance
* @param array|integer $identification Identification of the dataset to work with
* @param array|boolean $queryParams The parameters used for parsing
* @return Marcelgwerder\ApiHandler\Result Result object that provides getter methods
*/
public function parseSingle($queryBuilder, $identification, $queryParams = false)
{
if ($queryParams === false) {
$queryParams = Input::get();
}

$parser = new Parser($queryBuilder, $queryParams);
$parser->parse($identification);
$parser = new Parser($queryBuilder, $queryParams);
$parser->parse($identification);

return new Result($parser);
}
return new Result($parser);
}

/**
* Return a new Result object for multiple datasets
*
* @param mixed $queryBuilder Some kind of query builder instance
* @param array $fullTextSearchColumns Columns to search in fulltext search
* @param array|boolean $queryParams A list of query parameter
* @return Result
*/
public function parseMultiple($queryBuilder, $fullTextSearchColumns = array(), $queryParams = false)
{
if($queryParams === false) $queryParams = Input::get();
/**
* Return a new Result object for multiple datasets
*
* @param mixed $queryBuilder Some kind of query builder instance
* @param array $fullTextSearchColumns Columns to search in fulltext search
* @param array|boolean $queryParams A list of query parameter
* @return Result
*/
public function parseMultiple($queryBuilder, $fullTextSearchColumns = array(), $queryParams = false)
{
if ($queryParams === false) {
$queryParams = Input::get();
}

$parser = new Parser($queryBuilder, $queryParams);
$parser->parse($fullTextSearchColumns, true);
$parser = new Parser($queryBuilder, $queryParams);
$parser->parse($fullTextSearchColumns, true);

return new Result($parser);
}
return new Result($parser);
}

/**
* Return a new "created" response object
*
* @param array|object $object
* @return Response
*/
public function created($object)
{
return Response::json($object, 201);
}
/**
* Return a new "created" response object
*
* @param array|object $object
* @return Response
*/
public function created($object)
{
return Response::json($object, 201);
}

/**
* Return a new "updated" response object
*
* @param array|object $object
* @return Response
*/
public function updated($object = null)
{
if($object != null)
{
return Response::json($object, 200);
}
else
{
return Response::make(null, 204);
}
}
/**
* Return a new "updated" response object
*
* @param array|object $object
* @return Response
*/
public function updated($object = null)
{
if ($object != null) {
return Response::json($object, 200);
} else {
return Response::make(null, 204);
}
}

/**
* Return a new "deleted" response object
*
* @param array|object $object
* @return Response
*/
public function deleted($object = null) {
if($object != null)
{
return Response::json($object, 200);
}
else
{
return Response::make(null, 204);
}
}
}
/**
* Return a new "deleted" response object
*
* @param array|object $object
* @return Response
*/
public function deleted($object = null)
{
if ($object != null) {
return Response::json($object, 200);
} else {
return Response::make(null, 204);
}
}
}
Loading

0 comments on commit d11a023

Please sign in to comment.