Skip to content

Commit

Permalink
Throw exception if APP_DEBUG=true
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Apr 4, 2016
1 parent 141c47d commit 7aa4043
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 8 deletions.
37 changes: 37 additions & 0 deletions src/NilPortugues/Laravel5/JsonApi/Actions/CreateResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Author: Nil Portugués Calderó <[email protected]>
* Date: 5/04/16
* Time: 0:17.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Laravel5\JsonApi\Actions;

use Exception;
use NilPortugues\Api\JsonApi\Server\Errors\ErrorBag;

/**
* Class CreateResource.
*/
class CreateResource extends \NilPortugues\Api\JsonApi\Server\Actions\CreateResource
{
/**
* @param Exception $e
* @param ErrorBag $errorBag
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws Exception
*/
public function getErrorResponse(Exception $e, ErrorBag $errorBag)
{
if (env('APP_DEBUG')) {
throw $e;
}

return parent::getErrorResponse($e, $errorBag);
}
}
18 changes: 18 additions & 0 deletions src/NilPortugues/Laravel5/JsonApi/Actions/DeleteResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Author: Nil Portugués Calderó <[email protected]>
* Date: 5/04/16
* Time: 0:17.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Laravel5\JsonApi\Actions;

/**
* Class DeleteResource.
*/
class DeleteResource extends \NilPortugues\Api\JsonApi\Server\Actions\DeleteResource
{
}
35 changes: 35 additions & 0 deletions src/NilPortugues/Laravel5/JsonApi/Actions/GetResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Author: Nil Portugués Calderó <[email protected]>
* Date: 5/04/16
* Time: 0:17.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Laravel5\JsonApi\Actions;

use Exception;

/**
* Class GetResource.
*/
class GetResource extends \NilPortugues\Api\JsonApi\Server\Actions\GetResource
{
/**
* @param Exception $e
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws Exception
*/
public function getErrorResponse(Exception $e)
{
if (env('APP_DEBUG')) {
throw $e;
}

return parent::getErrorResponse($e);
}
}
33 changes: 33 additions & 0 deletions src/NilPortugues/Laravel5/JsonApi/Actions/ListResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Author: Nil Portugués Calderó <[email protected]>
* Date: 5/04/16
* Time: 0:15.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Laravel5\JsonApi\Actions;

/**
* Class ListResource.
*/
class ListResource extends \NilPortugues\Api\JsonApi\Server\Actions\ListResource
{
/**
* @param \Exception $e
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Exception
*/
public function getErrorResponse(\Exception $e)
{
if (env('APP_DEBUG')) {
throw $e;
}

return parent::getErrorResponse($e);
}
}
33 changes: 33 additions & 0 deletions src/NilPortugues/Laravel5/JsonApi/Actions/PatchResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Author: Nil Portugués Calderó <[email protected]>
* Date: 5/04/16
* Time: 0:17.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Laravel5\JsonApi\Actions;

/**
* Class PatchResource.
*/
class PatchResource extends \NilPortugues\Api\JsonApi\Server\Actions\PatchResource
{
/**
* @param \Exception $e
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Exception
*/
public function getErrorResponse(\Exception $e)
{
if (env('APP_DEBUG')) {
throw $e;
}

return parent::getErrorResponse($e);
}
}
33 changes: 33 additions & 0 deletions src/NilPortugues/Laravel5/JsonApi/Actions/PutResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Author: Nil Portugués Calderó <[email protected]>
* Date: 5/04/16
* Time: 0:17.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Laravel5\JsonApi\Actions;

/**
* Class PutResource.
*/
class PutResource extends \NilPortugues\Api\JsonApi\Server\Actions\PutResource
{
/**
* @param \Exception $e
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Exception
*/
public function getErrorResponse(\Exception $e)
{
if (env('APP_DEBUG')) {
throw $e;
}

return parent::getErrorResponse($e);
}
}
13 changes: 7 additions & 6 deletions src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
use Illuminate\Http\Request;
use NilPortugues\Api\JsonApi\Http\Factory\RequestFactory;
use NilPortugues\Api\JsonApi\Http\Response\ResourceNotFound;
use NilPortugues\Api\JsonApi\Server\Actions\CreateResource;
use NilPortugues\Api\JsonApi\Server\Actions\DeleteResource;
use NilPortugues\Api\JsonApi\Server\Actions\GetResource;
use NilPortugues\Api\JsonApi\Server\Actions\ListResource;
use NilPortugues\Api\JsonApi\Server\Actions\PatchResource;
use NilPortugues\Api\JsonApi\Server\Actions\PutResource;
use NilPortugues\Laravel5\JsonApi\Actions\CreateResource;
use NilPortugues\Laravel5\JsonApi\Actions\DeleteResource;
use NilPortugues\Laravel5\JsonApi\Actions\GetResource;
use NilPortugues\Laravel5\JsonApi\Actions\ListResource;
use NilPortugues\Laravel5\JsonApi\Actions\PatchResource;
use NilPortugues\Laravel5\JsonApi\Actions\PutResource;
use NilPortugues\Api\JsonApi\Server\Errors\Error;
use NilPortugues\Api\JsonApi\Server\Errors\ErrorBag;
use NilPortugues\Laravel5\JsonApi\Eloquent\EloquentHelper;
Expand Down Expand Up @@ -79,6 +79,7 @@ public function index()

/**
* @param $controllerAction
*
* @return mixed
*/
protected function uriGenerator($controllerAction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ abstract class LumenJsonApiController extends Controller

/**
* @param string $controllerAction
*
* @return mixed
*
*
Expand All @@ -30,12 +31,12 @@ abstract class LumenJsonApiController extends Controller
*/
protected function uriGenerator($controllerAction)
{
/** @var array $routes */
/** @var array $routes */
$routes = Application::getInstance()->getRoutes();
foreach ($routes as $route) {
if ($route['action'] === $controllerAction) {
return $route;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Author: Nil Portugués Calderó <[email protected]>
* Date: 11/02/16
* Time: 23:03.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace NilPortugues\Laravel5\JsonApi\Repository;

use Illuminate\Database\Eloquent\Model;
use NilPortugues\Foundation\Infrastructure\Model\Repository\Eloquent\EloquentRepository as Repository;

/**
* Class Repository.
*/
class EloquentRepository extends Repository
{
/**
* @var string
*/
protected $modelClass;

/**
* EloquentRepository constructor.
*
* @param Model $model
*/
public function __construct(Model $model)
{
$this->modelClass = get_class($model);
}

/**
* {@inheritdoc}
*/
protected function modelClassName()
{
return $this->modelClass;
}
}

0 comments on commit 7aa4043

Please sign in to comment.