Skip to content

Commit

Permalink
Merge branch 'master' into fix/model-factory-mixed-concerns
Browse files Browse the repository at this point in the history
# Conflicts:
#	api/app/Services/Datasets/Countries.php
#	api/app/Services/ModelFactoryInstance.php
#	api/tests/ModelFactoryTest.php
  • Loading branch information
Redjik committed Sep 4, 2015
2 parents 0c40722 + 99f6cf6 commit 0d9f32b
Show file tree
Hide file tree
Showing 210 changed files with 2,138 additions and 666 deletions.
5 changes: 1 addition & 4 deletions .styleci.yml
@@ -1,4 +1 @@
preset: psr2

enabled:
- short_array_syntax
preset: laravel
11 changes: 8 additions & 3 deletions api/app/Console/Commands/ApiaryValidateCommand.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Console\Commands;

use App\Http\Controllers\ApiaryController;
Expand Down Expand Up @@ -39,13 +47,10 @@ public function handle()
{
$apiaryController = new ApiaryController();


$apib = $apiaryController->getDocumentationApib('/');


$fs = new Filesystem();


$fileLocation = storage_path().'/app/apiary.apib';

$fs->put($fileLocation, $apib);
Expand Down
10 changes: 9 additions & 1 deletion api/app/Console/Commands/GenerateKeysCommand.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Console\Commands;

use Crypt_RSA;
Expand Down Expand Up @@ -53,7 +61,7 @@ public function handle()
$rsa = new Crypt_RSA();
$keys = $rsa->createKey();

if (!$this->file->exists(storage_path('app/keys'))) {
if (! $this->file->exists(storage_path('app/keys'))) {
$this->file->makeDirectory(storage_path('app/keys'));
}

Expand Down
8 changes: 8 additions & 0 deletions api/app/Console/Kernel.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
Expand Down
8 changes: 8 additions & 0 deletions api/app/Exceptions/BadRequestException.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Exceptions;

use Exception;
Expand Down
8 changes: 8 additions & 0 deletions api/app/Exceptions/FatalErrorException.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Exceptions;

use RuntimeException;
Expand Down
12 changes: 11 additions & 1 deletion api/app/Exceptions/ForbiddenException.php
@@ -1,4 +1,14 @@
<?php namespace App\Exceptions;
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Exceptions;

use Exception;
use Symfony\Component\HttpFoundation\Response;
Expand Down
12 changes: 9 additions & 3 deletions api/app/Exceptions/Handler.php
@@ -1,12 +1,19 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Exceptions;

use App\Http\Transformers\EloquentModelTransformer;
use Exception;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Spira\Responder\Contract\TransformableInterface;
use Spira\Responder\Contract\TransformerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

Expand All @@ -27,7 +34,6 @@ class Handler extends ExceptionHandler
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
*
*/
public function report(Exception $e)
{
Expand All @@ -47,7 +53,7 @@ public function render($request, Exception $e)
$debug = env('APP_DEBUG', false);

$message = $e->getMessage();
if (!$message) {
if (! $message) {
$message = 'An error occurred';
}

Expand Down
8 changes: 8 additions & 0 deletions api/app/Exceptions/NotImplementedException.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Exceptions;

use Exception;
Expand Down
8 changes: 8 additions & 0 deletions api/app/Exceptions/ServiceUnavailableException.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Exceptions;

use Exception;
Expand Down
8 changes: 8 additions & 0 deletions api/app/Exceptions/TokenInvalidException.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Exceptions;

use Exception;
Expand Down
8 changes: 8 additions & 0 deletions api/app/Exceptions/UnauthorizedException.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Exceptions;

use Exception;
Expand Down
8 changes: 8 additions & 0 deletions api/app/Exceptions/UnprocessableEntityException.php
@@ -1,5 +1,13 @@
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Exceptions;

use Exception;
Expand Down
36 changes: 17 additions & 19 deletions api/app/Extensions/Controller/RequestValidationTrait.php
@@ -1,9 +1,11 @@
<?php
/**
* Created by PhpStorm.
* User: redjik
* Date: 04.08.15
* Time: 21:09

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Extensions\Controller;
Expand Down Expand Up @@ -38,26 +40,25 @@ public function getIds($entityCollection, $keyName)
return $ids;
}


/**
* Build notFoundException
* Build notFoundException.
* @param string $keyName
* @return ValidationException
*/
protected function notFoundException($keyName = '')
{
$validation = $this->getValidationFactory()->make([$keyName=>$keyName], [$keyName=>'notFound']);
if (!$validation->fails()) {
$validation = $this->getValidationFactory()->make([$keyName => $keyName], [$keyName => 'notFound']);
if (! $validation->fails()) {
// @codeCoverageIgnoreStart
throw new \LogicException("Validator should have failed");
throw new \LogicException('Validator should have failed');
// @codeCoverageIgnoreEnd
}

throw new ValidationException($validation->getMessageBag());
}

/**
* Get notFoundManyException
* Get notFoundManyException.
* @param $ids
* @param Collection $models
* @param string $keyName
Expand All @@ -81,7 +82,6 @@ protected function notFoundManyException($ids, $models, $keyName = '')
throw new ValidationExceptionCollection($errors);
}


/**
* @param $requestEntity
* @param array $validationRules
Expand All @@ -105,7 +105,7 @@ public function validateRequest($requestEntity, $validationRules, $limitToKeysPr
}

/**
* Validate a request collection
* Validate a request collection.
* @param $requestCollection
* @param $validationRules
* @param bool|false $limitToKeysPresent
Expand Down Expand Up @@ -133,8 +133,6 @@ public function validateRequestCollection($requestCollection, $validationRules,
return true;
}



/**
* @param Request $request
* @param $id
Expand All @@ -145,16 +143,16 @@ public function validateRequestCollection($requestCollection, $validationRules,
protected function checkEntityIdMatchesRoute(Request $request, $id, BaseModel $model, $requireEntityKey = true)
{
$keyName = $model->getKeyName();
if (!$request->has($keyName)) {
if (!$requireEntityKey) {
if (! $request->has($keyName)) {
if (! $requireEntityKey) {
return true; //it is ok if the key is not set (for patch requests etc)
} else {
throw new BadRequestException("Request entity must include entity id ($keyName) for ".get_class($model));
}
}

if ((string)$request->input($keyName) !== (string)$id) {
throw new BadRequestException("Provided entity body does not match route parameter. The entity key cannot be updated");
if ((string) $request->input($keyName) !== (string) $id) {
throw new BadRequestException('Provided entity body does not match route parameter. The entity key cannot be updated');
}

return true;
Expand Down
20 changes: 15 additions & 5 deletions api/app/Extensions/JWTAuth/ClaimFactory.php
@@ -1,4 +1,14 @@
<?php namespace App\Extensions\JWTAuth;
<?php

/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/

namespace App\Extensions\JWTAuth;

use Tymon\JWTAuth\Claims\Custom;
use Tymon\JWTAuth\Claims\Factory;
Expand All @@ -16,11 +26,11 @@ class ClaimFactory extends Factory
'jti' => 'Tymon\JWTAuth\Claims\JwtId',
'nbf' => 'Tymon\JWTAuth\Claims\NotBefore',
'sub' => 'Tymon\JWTAuth\Claims\Subject',
'_user' => 'App\Extensions\JWTAuth\UserClaim'
'_user' => 'App\Extensions\JWTAuth\UserClaim',
];

/**
* Get the instance of the claim when passing the name and value
* Get the instance of the claim when passing the name and value.
*
* @param string $name
* @param mixed $value
Expand All @@ -36,10 +46,10 @@ public function get($name, $value)
}

/**
* Check whether the claim exists
* Check whether the claim exists.
*
* @param string $name
* @return boolean
* @return bool
*/
public function has($name)
{
Expand Down

0 comments on commit 0d9f32b

Please sign in to comment.