Skip to content

Commit

Permalink
update 2.4 (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesschobel authored Mar 3, 2018
1 parent 44af4a7 commit e00bb44
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 29 deletions.
2 changes: 2 additions & 0 deletions Abstracts/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Apiato\Core\Abstracts\Actions;

use Apiato\Core\Traits\CallableTrait;
use Apiato\Core\Traits\HasRequestCriteriaTrait;

/**
* Class Action.
Expand All @@ -13,6 +14,7 @@ abstract class Action
{

use CallableTrait;
use HasRequestCriteriaTrait;

/**
* Set automatically by the controller after calling an Action.
Expand Down
4 changes: 2 additions & 2 deletions Abstracts/Events/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Apiato\Core\Abstracts\Events\Interfaces\ShouldHandle;
use Apiato\Core\Abstracts\Events\Interfaces\ShouldHandleNow;
use Apiato\Core\Abstracts\Events\Jobs\EventJob;
use \Illuminate\Foundation\Bus\PendingDispatch as JobDispatcher;
use \Illuminate\Events\Dispatcher as EventDispatcher;
use Illuminate\Events\Dispatcher as EventDispatcher;
use Illuminate\Foundation\Bus\PendingDispatch as JobDispatcher;

/**
* Created by PhpStorm.
Expand Down
2 changes: 1 addition & 1 deletion Abstracts/Events/Jobs/EventJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(ShouldHandle $handler)
/**
* Handle the job.
*
* @return @void
* @return void
*/
public function handle()
{
Expand Down
7 changes: 5 additions & 2 deletions Abstracts/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public function model()
*/
public function boot()
{
$this->pushCriteria(app(PrettusRequestCriteria::class));
// only apply the RequestCriteria if config flag is set!
if (Config::get('apiato.requests.automatically-apply-request-criteria', true)) {
$this->pushCriteria(app(PrettusRequestCriteria::class));
}
}

/**
Expand All @@ -74,7 +77,7 @@ public function paginate($limit = null, $columns = ['*'], $method = "paginate")
$limit = $limit ? : Request::get('limit');

// check, if skipping pagination is allowed and the requested by the user
if(Config::get('repository.pagination.skip') && $limit == "0") {
if (Config::get('repository.pagination.skip') && $limit == "0") {
return parent::all($columns);
}

Expand Down
3 changes: 3 additions & 0 deletions Abstracts/Tasks/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Apiato\Core\Abstracts\Tasks;

use Apiato\Core\Traits\HasRequestCriteriaTrait;

/**
* Class Task.
*
* @author Mahmoud Zalt <[email protected]>
*/
abstract class Task
{
use HasRequestCriteriaTrait;

}
4 changes: 2 additions & 2 deletions Abstracts/Tests/PhpUnit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use Apiato\Core\Traits\TestsTraits\PhpUnit\TestsRequestHelperTrait;
use Apiato\Core\Traits\TestsTraits\PhpUnit\TestsResponseHelperTrait;
use Apiato\Core\Traits\TestsTraits\PhpUnit\TestsUploadHelperTrait;
use Illuminate\Foundation\Testing\TestCase as LaravelTestCase;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\TestCase as LaravelTestCase;

/**
* Class TestCase
Expand Down
10 changes: 7 additions & 3 deletions Abstracts/Transporters/Transporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function __construct($input = null, $schema = null, RegulatorInterface $r
// and pass them as array input to the Dto constructor..
if ($input instanceof Request) {
$content = $input->toArray();
$heders = ['_headers' => $input->headers->all()];
$headers = ['_headers' => $input->headers->all()];

$input = array_merge($heders, $content);
$input = array_merge($headers, $content);
}

parent::__construct($input, $schema, $regulator);
Expand All @@ -63,8 +63,11 @@ public function getInputByKey($key = null, $default = null)
}

/**
* Since passing Objects doesn't work, because they cannot be hydrated by the DTO.
* Since passing Objects does not work, because they cannot be hydrated by the DTO.
* This gives us the ability to pass instances, via the DTO.
*
* @param string $key
* @param mixed $value
*/
public function setInstance($key, $value)
{
Expand Down Expand Up @@ -94,6 +97,7 @@ public function __get($name)

$field = parent::__get($name);

// this will call the toScalar / toArray / toObject / ... functions
$type = $field->getStorageType();
$value = call_user_func([$field, 'to' . Str::ucfirst($type)]);

Expand Down
2 changes: 1 addition & 1 deletion Exceptions/Handlers/ExceptionsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Apiato\Core\Exceptions\Handlers;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as LaravelExceptionHandler;
use Illuminate\Support\Facades\Config;
use Optimus\Heimdal\ExceptionHandler as HeimdalExceptionHandler;
use Illuminate\Foundation\Exceptions\Handler as LaravelExceptionHandler;

/**
* Class ExceptionsHandler
Expand Down
7 changes: 6 additions & 1 deletion Foundation/Apiato.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ public function uncamelize($word, $splitter = " ", $uppercase = true)
}

/**
* @return mixed
* @return mixed
* @throws WrongConfigurationsException
*/
public function getLoginWebPageName()
{
Expand Down Expand Up @@ -250,6 +251,8 @@ public function getClassType($className)

/**
* @param $containerName
*
* @throws MissingContainerException
*/
public function verifyContainerExist($containerName)
{
Expand All @@ -260,6 +263,8 @@ public function verifyContainerExist($containerName)

/**
* @param $className
*
* @throws ClassDoesNotExistException
*/
public function verifyClassExist($className)
{
Expand Down
2 changes: 1 addition & 1 deletion Generator/Stubs/actions/getall.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GetAll{{models}}Action extends Action
{
public function run(Request $request)
{
${{entities}} = Apiato::call('{{container-name}}@GetAll{{models}}Task');
${{entities}} = Apiato::call('{{container-name}}@GetAll{{models}}Task', [], ['addRequestCriteria']);

return ${{entities}};
}
Expand Down
2 changes: 1 addition & 1 deletion Generator/Stubs/tasks/create.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Exception;
class Create{{model}}Task extends Task
{

private $repository;
protected $repository;

public function __construct({{model}}Repository $repository)
{
Expand Down
2 changes: 1 addition & 1 deletion Generator/Stubs/tasks/delete.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Exception;
class Delete{{model}}Task extends Task
{

private $repository;
protected $repository;

public function __construct({{model}}Repository $repository)
{
Expand Down
2 changes: 1 addition & 1 deletion Generator/Stubs/tasks/find.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Exception;
class Find{{model}}ByIdTask extends Task
{

private $repository;
protected $repository;

public function __construct({{model}}Repository $repository)
{
Expand Down
2 changes: 1 addition & 1 deletion Generator/Stubs/tasks/getall.stub
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use App\Ship\Parents\Tasks\Task;
class GetAll{{models}}Task extends Task
{

private $repository;
protected $repository;

public function __construct({{model}}Repository $repository)
{
Expand Down
2 changes: 1 addition & 1 deletion Generator/Stubs/tasks/update.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Exception;
class Update{{model}}Task extends Task
{

private $repository;
protected $repository;

public function __construct({{model}}Repository $repository)
{
Expand Down
7 changes: 6 additions & 1 deletion Generator/Traits/FileSystemTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ trait FileSystemTrait
/**
* Determine if the file already exists.
*
* @param $path
*
* @return bool
*/
protected function alreadyExists($path)
Expand All @@ -18,7 +20,10 @@ protected function alreadyExists($path)
}

/**
* @return mixed
* @param $filePath
* @param $stubContent
*
* @return mixed
*/
public function generateFile($filePath, $stubContent)
{
Expand Down
15 changes: 12 additions & 3 deletions Generator/Traits/ParserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ trait ParserTrait
/**
* replaces the variables in the path structure with defined values
*
* @return mixed
* @param $path
* @param $data
*
* @return mixed
*/
public function parsePathStructure($path, $data)
{
Expand All @@ -25,7 +28,10 @@ public function parsePathStructure($path, $data)
/**
* replaces the variables in the file structure with defined values
*
* @return mixed
* @param $filename
* @param $data
*
* @return mixed
*/
public function parseFileStructure($filename, $data)
{
Expand All @@ -36,7 +42,10 @@ public function parseFileStructure($filename, $data)
/**
* replaces the variables in the stub file with defined values
*
* @return mixed
* @param $stub
* @param $data
*
* @return mixed
*/
public function parseStubContent($stub, $data)
{
Expand Down
4 changes: 3 additions & 1 deletion Generator/Traits/PrinterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public function printStartedMessage($containerName, $fileName)
}

/**
* @void
* @param $type
*
* @return void
*/
public function printFinishedMessage($type)
{
Expand Down
2 changes: 1 addition & 1 deletion Loaders/MiddlewaresLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function loadMiddlewares()
/**
* Registering Route Group's
*
* @param array $middlewareGroups
* @param array $middlewares
*/
private function registerMiddleware(array $middlewares = [])
{
Expand Down
2 changes: 1 addition & 1 deletion Loaders/ProvidersLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Apiato\Core\Loaders;

use App;
use Apiato\Core\Foundation\Facades\Apiato;
use App;
use File;

/**
Expand Down
2 changes: 2 additions & 0 deletions Loaders/SeederLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ private function loadSeedersFromContainers()
{
$seedersClasses = new Collection();

$containersDirectories = [];

foreach (Apiato::getContainersNames() as $containerName) {

$containersDirectories[] = base_path('app/Containers/' . $containerName . $this->seedersPath);
Expand Down
2 changes: 1 addition & 1 deletion Providers/ApiatoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Apiato\Core\Providers;

use Apiato\Core\Abstracts\Events\Providers\EventServiceProvider;
use Apiato\Core\Abstracts\Providers\MainProvider as AbstractMainProvider;
use Apiato\Core\Foundation\Apiato;
use Apiato\Core\Generator\GeneratorsServiceProvider;
use Apiato\Core\Loaders\AutoLoaderTrait;
use Apiato\Core\Loaders\FactoriesLoaderTrait;
use Apiato\Core\Traits\ValidationTrait;
use Apiato\Core\Abstracts\Events\Providers\EventServiceProvider;
use App\Ship\Parents\Providers\RoutesProvider;
use App\Ship\Providers\ShipProvider;
use Barryvdh\Cors\ServiceProvider as CorsServiceProvider;
Expand Down
74 changes: 74 additions & 0 deletions Traits/HasRequestCriteriaTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Apiato\Core\Traits;

use Apiato\Core\Abstracts\Repositories\Repository;
use Apiato\Core\Exceptions\CoreInternalErrorException;
use Prettus\Repository\Criteria\RequestCriteria;

/**
* Trait HasRequestCriteriaTrait
*
* @author Johannes Schobel <[email protected]>
*/
trait HasRequestCriteriaTrait
{

/**
* Adds the RequestCriteria to a Repository
*
* @param null $repository
*/
public function addRequestCriteria($repository = null)
{
$validatedRepository = $this->validateRepository($repository);

$validatedRepository->pushCriteria(app(RequestCriteria::class));
}

/**
* Removes the RequestCriteria from a Repository
*
* @param null $repository
*/
public function removeRequestCriteria($repository = null)
{
$validatedRepository = $this->validateRepository($repository);

$validatedRepository->popCriteria(RequestCriteria::class);
}

/**
* Validates, if the given Repository exists or uses $this->repository on the Task/Action to apply functions
*
* @param $repository
*
* @return mixed
* @throws CoreInternalErrorException
*/
private function validateRepository($repository)
{
$validatedRepository = $repository;

// check if we have a "custom" repository
if (null === $repository) {
if (! isset($this->repository)) {
throw new CoreInternalErrorException('No protected or public accessible repository available');
}
$validatedRepository = $this->repository;
}

// check, if the validated repository is null
if (null === $validatedRepository) {
throw new CoreInternalErrorException();
}

// check if it is a Repository class
if (! ($validatedRepository instanceof Repository)) {
throw new CoreInternalErrorException();
}

return $validatedRepository;
}

}
Loading

0 comments on commit e00bb44

Please sign in to comment.