Skip to content

Commit

Permalink
Migrate to laravel 9 (apiato#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi authored Apr 27, 2022
1 parent 704869d commit 21fc123
Show file tree
Hide file tree
Showing 220 changed files with 2,005 additions and 2,846 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ HASH_ID=true
HASH_ID_KEY=apiato
HASH_ID_LENGTH=16

API_RATE_LIMIT_ENABLED=true
API_RATE_LIMIT_ATTEMPTS=30
API_RATE_LIMIT_EXPIRES=1
GLOBAL_API_RATE_LIMIT_ENABLED=true
GLOBAL_API_RATE_LIMIT_ATTEMPTS_PER_MIN=30
GLOBAL_API_RATE_LIMIT_EXPIRES_IN_MIN=1

PAGINATION_LIMIT_DEFAULT=10
PAGINATION_SKIP=false
Expand Down
15 changes: 8 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
.github export-ignore
CHANGELOG.md export-ignore
.travis.yml export-ignore
.env.travis export-ignore

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
/storage/*.key
/vendor
.env
.env.testing
.env.backup
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
/.idea
/.vscode
.env.testing
storage/logs/laravel.log
/public/uploads/
/laradock*/
_ide_helper*.php
.phpstorm.meta.php
/.vagrant
/.idea
/.vscode
html_coverage
Vagrantfile
after.sh
Expand Down
62 changes: 62 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## [v11.0.0](https://github.com/apiato/apiato/compare/v10.0.15...v11.0.0) - 2022-04-27
Apiato 11 includes a variety of changes to the application skeleton. Please consult the diff to see what's new.

# Release Notes

### Added

- Added support for `Laravel 9.0`
- Added new method to transformers: nullableItem()
This helps in situations when you want to check if a relation is null and act base on that. So instead of writing something like this: `return $user->something ? $this->item($user->something, new SomethingTransformer()) : $this->primitive(null);` you can just write `$this->nullableItem($user->something, new SomethingTransformer())` which returns null if the relation doesn't exist.
- Added apiato:generate:policy command
- You can publish compatible containers configs using php artisan `vendor:publish` for now these containers are updated:
Documentation
SocialAuth
- Added new method: `transactionalRun()` to actions. This is just a wrapper around actions `run()` which puts in into a `db::transaction`
- New commands:
- apiato:generate:factory
- apiato:generate:event
- apiato:generate:listener
- apiato:generate:middleware
- `apiato:generate:container` command is greatly improved with new goodies!
- added option to generate API events & listeners for generated container
- added option to generate API tests for generated container
- While generating Containers (API only) You can now choose to generate:
- **Events Listeners** (experimental! I think this might be useless!)
If you choose to generate Events: Events will be implemented in Tasks, e.g. CreateOrderTask will fire OrderCreatedEvent
- **Tests**
If you choose to generate Tests:
If Events are generated then the generated Tests will also test Events being fired!
**Note:** some generated tests are more like placeholders which you can uncomment and modify to your use case but nevertheless you will be way ahead!
You can find the placeholder tests by searching for **TODO TEST**


### Fixed

- Fixed a small issue with the `HashIdTrait`
- Email verification now works actually! See the docs for more info.
- +Numerous more bugfixes...

### Changed

- Updated Dependencies in `composer.json` file to the latest versions
- In case of an `exception with empty error bag` we will now return {} instead of []
- Localization language files are now loaded from `languages` folder instead of `resources/languages`
- Global throttling on routes is now named `api` and is only applied to api routes and not the web routes and can be bypassed using `withoutMiddleware()` method on route.
- Login attribute (email, name, etc...) is now case insensitive. This behaviour can be changed in the configs.
- You can now choose between `Multi Action` or `Single Action` Controllers when using `apiato:generate:container` command.
- Almost all middlewares are moved from ship to core
- apiato:generate:serviceprovider is removed and changed into multiple separate commands
- apiato:generate:provider:generic
- apiato:generate:provider:main
- apiato:generate:provider:middleware
- apiato:generate:provider:event

### Removed

- Removed(command): apiato:permissions:toRole
- Dropped support for Settings, Debugger, Payment




2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<img src="https://github.com/apiato/documentation/blob/master/images/apiato.jpg" alt="Apiato Logo"/>
</p>

<h3 align="center">Build scalable API's faster | With PHP 8.0 and Laravel 8.0</h3>
<h3 align="center">Build scalable API's faster | With PHP 8.0 and Laravel 9.0</h3>

<p align="center">
<a href="https://travis-ci.org/apiato/apiato"><img src="https://travis-ci.org/apiato/apiato.svg" alt="Build Status"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
namespace App\Containers\AppSection\Authentication\Actions;

use Apiato\Core\Exceptions\IncorrectIdException;
use App\Containers\AppSection\Authentication\Classes\LoginCustomAttribute;
use App\Containers\AppSection\Authentication\Exceptions\LoginFailedException;
use App\Containers\AppSection\Authentication\Tasks\CallOAuthServerTask;
use App\Containers\AppSection\Authentication\Tasks\ExtractLoginCustomAttributeTask;
use App\Containers\AppSection\Authentication\Tasks\MakeRefreshCookieTask;
use App\Containers\AppSection\Authentication\Traits\LoginAttributeCaseSensitivityTrait;
use App\Containers\AppSection\Authentication\UI\API\Requests\LoginProxyPasswordGrantRequest;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;

class ApiLoginProxyForWebClientAction extends Action
class ApiLoginProxyForWebClientAction extends ParentAction
{
use LoginAttributeCaseSensitivityTrait;

/**
* @param LoginProxyPasswordGrantRequest $request
* @return array
Expand All @@ -30,8 +27,8 @@ public function run(LoginProxyPasswordGrantRequest $request): array
]
);

list($username) = app(ExtractLoginCustomAttributeTask::class)->run($sanitizedData);
$sanitizedData = $this->enrichSanitizedData($this->processLoginAttributeCaseSensitivity($username), $sanitizedData);
list($username) = LoginCustomAttribute::extract($sanitizedData);
$sanitizedData = $this->enrichSanitizedData($username, $sanitizedData);

$responseContent = app(CallOAuthServerTask::class)->run($sanitizedData, $request->headers->get('accept-language'));
$refreshCookie = app(MakeRefreshCookieTask::class)->run($responseContent['refresh_token']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
namespace App\Containers\AppSection\Authentication\Actions;

use App\Containers\AppSection\Authentication\UI\API\Requests\LogoutRequest;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;
use Laravel\Passport\RefreshTokenRepository;
use Laravel\Passport\TokenRepository;
use Lcobucci\JWT\Parser;

class ApiLogoutAction extends Action
class ApiLogoutAction extends ParentAction
{
/**
* @param LogoutRequest $request
* @return void
*/
public function run(LogoutRequest $request): void
{
$id = app(Parser::class)->parse($request->bearerToken())->claims()->get('jti');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use App\Containers\AppSection\Authentication\Tasks\CallOAuthServerTask;
use App\Containers\AppSection\Authentication\Tasks\MakeRefreshCookieTask;
use App\Containers\AppSection\Authentication\UI\API\Requests\RefreshProxyRequest;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;
use Illuminate\Support\Facades\Request;

class ApiRefreshProxyForWebClientAction extends Action
class ApiRefreshProxyForWebClientAction extends ParentAction
{
/**
* @param RefreshProxyRequest $request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use App\Containers\AppSection\Authentication\Tasks\CreatePasswordResetTokenTask;
use App\Containers\AppSection\Authentication\UI\API\Requests\ForgotPasswordRequest;
use App\Containers\AppSection\User\Tasks\FindUserByEmailTask;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;
use App\Ship\Parents\Exceptions\Exception;
use Illuminate\Support\Facades\Mail;

class ForgotPasswordAction extends Action
class ForgotPasswordAction extends ParentAction
{
/**
* @param ForgotPasswordRequest $request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
namespace App\Containers\AppSection\Authentication\Actions;

use App\Containers\AppSection\Authentication\UI\API\Requests\GetAuthenticatedUserRequest;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;
use Illuminate\Contracts\Auth\Authenticatable;

class GetAuthenticatedUserAction extends Action
class GetAuthenticatedUserAction extends ParentAction
{
/**
* @param GetAuthenticatedUserRequest $request
* @return Authenticatable
*/
public function run(GetAuthenticatedUserRequest $request): Authenticatable
{
return $request->user();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use App\Containers\AppSection\Authentication\UI\API\Requests\RegisterUserRequest;
use App\Containers\AppSection\User\Models\User;
use App\Ship\Exceptions\CreateResourceFailedException;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;

class RegisterUserAction extends Action
class RegisterUserAction extends ParentAction
{
/**
* @param RegisterUserRequest $request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
use App\Containers\AppSection\User\Tasks\FindUserByEmailTask;
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Exceptions\UpdateResourceFailedException;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;

class ResetPasswordAction extends Action
class ResetPasswordAction extends ParentAction
{
/**
* @param ResetPasswordRequest $request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

use App\Containers\AppSection\Authentication\Tasks\SendVerificationEmailTask;
use App\Containers\AppSection\Authentication\UI\API\Requests\SendVerificationEmailRequest;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;

class SendVerificationEmailAction extends Action
class SendVerificationEmailAction extends ParentAction
{
/**
* @param SendVerificationEmailRequest $request
* @return void
*/
public function run(SendVerificationEmailRequest $request): void
{
app(SendVerificationEmailTask::class)->run($request->user(), $request->verification_url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use App\Containers\AppSection\User\Models\User;
use App\Containers\AppSection\User\Tasks\FindUserByIdTask;
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;
use Throwable;

class VerifyEmailAction extends Action
class VerifyEmailAction extends ParentAction
{
/**
* @param VerifyEmailRequest $request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
namespace App\Containers\AppSection\Authentication\Actions;

use Apiato\Core\Exceptions\IncorrectIdException;
use App\Containers\AppSection\Authentication\Classes\LoginCustomAttribute;
use App\Containers\AppSection\Authentication\Exceptions\LoginFailedException;
use App\Containers\AppSection\Authentication\Tasks\ExtractLoginCustomAttributeTask;
use App\Containers\AppSection\Authentication\Tasks\LoginTask;
use App\Containers\AppSection\Authentication\Traits\LoginAttributeCaseSensitivityTrait;
use App\Containers\AppSection\Authentication\UI\WEB\Requests\LoginRequest;
use App\Containers\AppSection\User\Models\User;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Auth;

class WebLoginAction extends Action
class WebLoginAction extends ParentAction
{
use LoginAttributeCaseSensitivityTrait;

/**
* @param LoginRequest $request
* @return User|Authenticatable|null
Expand All @@ -31,10 +28,10 @@ public function run(LoginRequest $request): User|Authenticatable|null
'remember_me' => false,
]);

list($username, $loginAttribute) = app(ExtractLoginCustomAttributeTask::class)->run($sanitizedData);
list($username, $loginAttribute) = LoginCustomAttribute::extract($sanitizedData);

$loggedIn = app(LoginTask::class)->run(
$this->processLoginAttributeCaseSensitivity($username),
$username,
$sanitizedData['password'],
$loginAttribute,
$sanitizedData['remember_me']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace App\Containers\AppSection\Authentication\Actions;

use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Actions\Action as ParentAction;
use Illuminate\Support\Facades\Auth;

class WebLogoutAction extends Action
class WebLogoutAction extends ParentAction
{
/**
* @return void
*/
public function run(): void
{
Auth::logout();
Auth::guard('web')->logout();
}
}
Loading

0 comments on commit 21fc123

Please sign in to comment.