From 434e70b50c587de025dbe61146f6abc8090595bf Mon Sep 17 00:00:00 2001 From: Matej Schwartz Date: Wed, 28 Feb 2018 12:24:43 +0100 Subject: [PATCH 1/4] Maintain WEB route files name order (#78) Sort WEB route files by the name --- Loaders/RoutesLoaderTrait.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Loaders/RoutesLoaderTrait.php b/Loaders/RoutesLoaderTrait.php index f01fdc783..c4f1dfa6f 100644 --- a/Loaders/RoutesLoaderTrait.php +++ b/Loaders/RoutesLoaderTrait.php @@ -69,6 +69,9 @@ private function loadWebContainerRoutes($containerPath, $containersNamespace) if (File::isDirectory($webRoutesPath)) { $files = File::allFiles($webRoutesPath); + $files = array_sort($files, function ($file) { + return $file->getFilename(); + }); foreach ($files as $file) { $this->loadWebRoute($file, $controllerNamespace); } From 182d94342845fa3f497062d1c2a8e57b92a79f0a Mon Sep 17 00:00:00 2001 From: Johannes Schobel Date: Sat, 3 Mar 2018 14:26:22 +0100 Subject: [PATCH 2/4] small changes (style, typos, optimize imports, ...) (#65) --- Abstracts/Events/Dispatcher/Dispatcher.php | 4 ++-- Abstracts/Events/Jobs/EventJob.php | 2 +- Abstracts/Tests/PhpUnit/TestCase.php | 4 ++-- Abstracts/Transporters/Transporter.php | 10 +++++++--- Exceptions/Handlers/ExceptionsHandler.php | 2 +- Foundation/Apiato.php | 7 ++++++- Generator/Traits/FileSystemTrait.php | 7 ++++++- Generator/Traits/ParserTrait.php | 15 ++++++++++++--- Generator/Traits/PrinterTrait.php | 4 +++- Loaders/MiddlewaresLoaderTrait.php | 2 +- Loaders/ProvidersLoaderTrait.php | 2 +- Loaders/SeederLoaderTrait.php | 2 ++ Providers/ApiatoProvider.php | 2 +- Traits/HashIdTrait.php | 3 ++- Traits/SanitizerTrait.php | 3 ++- .../PhpUnit/TestsRequestHelperTrait.php | 4 +++- 16 files changed, 52 insertions(+), 21 deletions(-) diff --git a/Abstracts/Events/Dispatcher/Dispatcher.php b/Abstracts/Events/Dispatcher/Dispatcher.php index a46ed4a35..35c6cb8e0 100644 --- a/Abstracts/Events/Dispatcher/Dispatcher.php +++ b/Abstracts/Events/Dispatcher/Dispatcher.php @@ -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. diff --git a/Abstracts/Events/Jobs/EventJob.php b/Abstracts/Events/Jobs/EventJob.php index 458dcb25b..b55962370 100644 --- a/Abstracts/Events/Jobs/EventJob.php +++ b/Abstracts/Events/Jobs/EventJob.php @@ -28,7 +28,7 @@ public function __construct(ShouldHandle $handler) /** * Handle the job. * - * @return @void + * @return void */ public function handle() { diff --git a/Abstracts/Tests/PhpUnit/TestCase.php b/Abstracts/Tests/PhpUnit/TestCase.php index 50f91729d..2f229e3e5 100644 --- a/Abstracts/Tests/PhpUnit/TestCase.php +++ b/Abstracts/Tests/PhpUnit/TestCase.php @@ -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 diff --git a/Abstracts/Transporters/Transporter.php b/Abstracts/Transporters/Transporter.php index 93329c19d..f9bbe59c4 100644 --- a/Abstracts/Transporters/Transporter.php +++ b/Abstracts/Transporters/Transporter.php @@ -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); @@ -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) { @@ -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)]); diff --git a/Exceptions/Handlers/ExceptionsHandler.php b/Exceptions/Handlers/ExceptionsHandler.php index f77c842f8..9d9cee96f 100644 --- a/Exceptions/Handlers/ExceptionsHandler.php +++ b/Exceptions/Handlers/ExceptionsHandler.php @@ -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 diff --git a/Foundation/Apiato.php b/Foundation/Apiato.php index e39b78284..89356b1a7 100644 --- a/Foundation/Apiato.php +++ b/Foundation/Apiato.php @@ -206,7 +206,8 @@ public function uncamelize($word, $splitter = " ", $uppercase = true) } /** - * @return mixed + * @return mixed + * @throws WrongConfigurationsException */ public function getLoginWebPageName() { @@ -250,6 +251,8 @@ public function getClassType($className) /** * @param $containerName + * + * @throws MissingContainerException */ public function verifyContainerExist($containerName) { @@ -260,6 +263,8 @@ public function verifyContainerExist($containerName) /** * @param $className + * + * @throws ClassDoesNotExistException */ public function verifyClassExist($className) { diff --git a/Generator/Traits/FileSystemTrait.php b/Generator/Traits/FileSystemTrait.php index d93f6b1ff..c0e98b7dc 100755 --- a/Generator/Traits/FileSystemTrait.php +++ b/Generator/Traits/FileSystemTrait.php @@ -10,6 +10,8 @@ trait FileSystemTrait /** * Determine if the file already exists. * + * @param $path + * * @return bool */ protected function alreadyExists($path) @@ -18,7 +20,10 @@ protected function alreadyExists($path) } /** - * @return mixed + * @param $filePath + * @param $stubContent + * + * @return mixed */ public function generateFile($filePath, $stubContent) { diff --git a/Generator/Traits/ParserTrait.php b/Generator/Traits/ParserTrait.php index 0f857b855..c0961c0fb 100755 --- a/Generator/Traits/ParserTrait.php +++ b/Generator/Traits/ParserTrait.php @@ -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) { @@ -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) { @@ -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) { diff --git a/Generator/Traits/PrinterTrait.php b/Generator/Traits/PrinterTrait.php index fd5abc2e1..83f42a309 100755 --- a/Generator/Traits/PrinterTrait.php +++ b/Generator/Traits/PrinterTrait.php @@ -11,7 +11,9 @@ public function printStartedMessage($containerName, $fileName) } /** - * @void + * @param $type + * + * @return void */ public function printFinishedMessage($type) { diff --git a/Loaders/MiddlewaresLoaderTrait.php b/Loaders/MiddlewaresLoaderTrait.php index 37730193b..5e0383a1e 100644 --- a/Loaders/MiddlewaresLoaderTrait.php +++ b/Loaders/MiddlewaresLoaderTrait.php @@ -26,7 +26,7 @@ public function loadMiddlewares() /** * Registering Route Group's * - * @param array $middlewareGroups + * @param array $middlewares */ private function registerMiddleware(array $middlewares = []) { diff --git a/Loaders/ProvidersLoaderTrait.php b/Loaders/ProvidersLoaderTrait.php index e9a8399a4..c26f4cb3c 100644 --- a/Loaders/ProvidersLoaderTrait.php +++ b/Loaders/ProvidersLoaderTrait.php @@ -2,8 +2,8 @@ namespace Apiato\Core\Loaders; -use App; use Apiato\Core\Foundation\Facades\Apiato; +use App; use File; /** diff --git a/Loaders/SeederLoaderTrait.php b/Loaders/SeederLoaderTrait.php index 786229c0c..5a8c6ef33 100644 --- a/Loaders/SeederLoaderTrait.php +++ b/Loaders/SeederLoaderTrait.php @@ -40,6 +40,8 @@ private function loadSeedersFromContainers() { $seedersClasses = new Collection(); + $containersDirectories = []; + foreach (Apiato::getContainersNames() as $containerName) { $containersDirectories[] = base_path('app/Containers/' . $containerName . $this->seedersPath); diff --git a/Providers/ApiatoProvider.php b/Providers/ApiatoProvider.php index 2f2969a31..6d6ba5d50 100644 --- a/Providers/ApiatoProvider.php +++ b/Providers/ApiatoProvider.php @@ -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; diff --git a/Traits/HashIdTrait.php b/Traits/HashIdTrait.php index d553f8b38..73f6f5da8 100644 --- a/Traits/HashIdTrait.php +++ b/Traits/HashIdTrait.php @@ -180,7 +180,8 @@ public function decodeArray(array $ids) * @param $id * @param null $parameter * - * @return array + * @return array + * @throws IncorrectIdException */ public function decode($id, $parameter = null) { diff --git a/Traits/SanitizerTrait.php b/Traits/SanitizerTrait.php index 58dc22259..bafe1db94 100644 --- a/Traits/SanitizerTrait.php +++ b/Traits/SanitizerTrait.php @@ -41,7 +41,8 @@ public function sanitizeInput(array $fields) } /** - * @return array + * @return array + * @throws InternalErrorException */ private function getData() { diff --git a/Traits/TestsTraits/PhpUnit/TestsRequestHelperTrait.php b/Traits/TestsTraits/PhpUnit/TestsRequestHelperTrait.php index 47adafff9..aeb45c14b 100644 --- a/Traits/TestsTraits/PhpUnit/TestsRequestHelperTrait.php +++ b/Traits/TestsTraits/PhpUnit/TestsRequestHelperTrait.php @@ -242,7 +242,7 @@ private function buildUrlForUri($uri) /** * Attach Authorization Bearer Token to the request headers - * if it doesn't exist already and the authentication is required + * if it does not exist already and the authentication is required * for the endpoint `$this->auth = true`. * * @param $headers @@ -345,6 +345,8 @@ private function validateEndpointExist() /** * @param $separator + * + * @throws WrongEndpointFormatException */ private function validateEndpointFormat($separator) { From b4d951070460d74c15a37730ef6ed0cfaec56d14 Mon Sep 17 00:00:00 2001 From: Johannes Schobel Date: Sat, 3 Mar 2018 18:12:11 +0100 Subject: [PATCH 3/4] Fix Repository (#80) propose changes to core --- Abstracts/Actions/Action.php | 2 + Abstracts/Repositories/Repository.php | 7 ++- Abstracts/Tasks/Task.php | 3 ++ Generator/Stubs/actions/getall.stub | 2 +- Generator/Stubs/tasks/create.stub | 2 +- Generator/Stubs/tasks/delete.stub | 2 +- Generator/Stubs/tasks/find.stub | 2 +- Generator/Stubs/tasks/getall.stub | 2 +- Generator/Stubs/tasks/update.stub | 2 +- Traits/HasRequestCriteriaTrait.php | 74 +++++++++++++++++++++++++++ 10 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 Traits/HasRequestCriteriaTrait.php diff --git a/Abstracts/Actions/Action.php b/Abstracts/Actions/Action.php index 69647638d..0202e9a2c 100644 --- a/Abstracts/Actions/Action.php +++ b/Abstracts/Actions/Action.php @@ -3,6 +3,7 @@ namespace Apiato\Core\Abstracts\Actions; use Apiato\Core\Traits\CallableTrait; +use Apiato\Core\Traits\HasRequestCriteriaTrait; /** * Class Action. @@ -13,6 +14,7 @@ abstract class Action { use CallableTrait; + use HasRequestCriteriaTrait; /** * Set automatically by the controller after calling an Action. diff --git a/Abstracts/Repositories/Repository.php b/Abstracts/Repositories/Repository.php index ce2d490e0..766d5f49f 100644 --- a/Abstracts/Repositories/Repository.php +++ b/Abstracts/Repositories/Repository.php @@ -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)); + } } /** @@ -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); } diff --git a/Abstracts/Tasks/Task.php b/Abstracts/Tasks/Task.php index ef68db119..47a13cf38 100644 --- a/Abstracts/Tasks/Task.php +++ b/Abstracts/Tasks/Task.php @@ -2,6 +2,8 @@ namespace Apiato\Core\Abstracts\Tasks; +use Apiato\Core\Traits\HasRequestCriteriaTrait; + /** * Class Task. * @@ -9,5 +11,6 @@ */ abstract class Task { + use HasRequestCriteriaTrait; } diff --git a/Generator/Stubs/actions/getall.stub b/Generator/Stubs/actions/getall.stub index bd4bfabc4..8eb196f3f 100644 --- a/Generator/Stubs/actions/getall.stub +++ b/Generator/Stubs/actions/getall.stub @@ -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}}; } diff --git a/Generator/Stubs/tasks/create.stub b/Generator/Stubs/tasks/create.stub index 1cc84911a..3e08604fa 100644 --- a/Generator/Stubs/tasks/create.stub +++ b/Generator/Stubs/tasks/create.stub @@ -10,7 +10,7 @@ use Exception; class Create{{model}}Task extends Task { - private $repository; + protected $repository; public function __construct({{model}}Repository $repository) { diff --git a/Generator/Stubs/tasks/delete.stub b/Generator/Stubs/tasks/delete.stub index 550f91f65..af608b5fb 100644 --- a/Generator/Stubs/tasks/delete.stub +++ b/Generator/Stubs/tasks/delete.stub @@ -10,7 +10,7 @@ use Exception; class Delete{{model}}Task extends Task { - private $repository; + protected $repository; public function __construct({{model}}Repository $repository) { diff --git a/Generator/Stubs/tasks/find.stub b/Generator/Stubs/tasks/find.stub index bc20d343b..a161f8a5c 100644 --- a/Generator/Stubs/tasks/find.stub +++ b/Generator/Stubs/tasks/find.stub @@ -10,7 +10,7 @@ use Exception; class Find{{model}}ByIdTask extends Task { - private $repository; + protected $repository; public function __construct({{model}}Repository $repository) { diff --git a/Generator/Stubs/tasks/getall.stub b/Generator/Stubs/tasks/getall.stub index 779399b5f..c98b18b51 100644 --- a/Generator/Stubs/tasks/getall.stub +++ b/Generator/Stubs/tasks/getall.stub @@ -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) { diff --git a/Generator/Stubs/tasks/update.stub b/Generator/Stubs/tasks/update.stub index 9e6aa0dc3..e04af64c0 100644 --- a/Generator/Stubs/tasks/update.stub +++ b/Generator/Stubs/tasks/update.stub @@ -10,7 +10,7 @@ use Exception; class Update{{model}}Task extends Task { - private $repository; + protected $repository; public function __construct({{model}}Repository $repository) { diff --git a/Traits/HasRequestCriteriaTrait.php b/Traits/HasRequestCriteriaTrait.php new file mode 100644 index 000000000..7114d1e47 --- /dev/null +++ b/Traits/HasRequestCriteriaTrait.php @@ -0,0 +1,74 @@ + + */ +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; + } + +} From 0f02f4c938e69d095c2234391db5bc1bd7518474 Mon Sep 17 00:00:00 2001 From: Adam Currie Date: Tue, 6 Mar 2018 16:34:42 +0000 Subject: [PATCH 4/4] Fix incorrect namespace on Job stub (#82) Incorrect naming on the namespace, change "Job" to "Jobs". --- Generator/Stubs/job.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Generator/Stubs/job.stub b/Generator/Stubs/job.stub index e46b19799..24054115f 100644 --- a/Generator/Stubs/job.stub +++ b/Generator/Stubs/job.stub @@ -1,6 +1,6 @@