forked from apiato/apiato
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introducing the SubAction component in Porto.
Tried to avoid that for long time, but seems now way to avoid it. In some situations, where you have large Actions, you need to share some sequence of Tasks (not only tasks) to avoid duplicate code between both actions, they should be able to call SubAction
- Loading branch information
Showing
3 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Ship\Parents\Actions; | ||
|
||
/** | ||
* Class Action. | ||
* | ||
* @author Mahmoud Zalt <[email protected]> | ||
*/ | ||
abstract class SubAction extends Action | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: "Sub Actions" | ||
category: "Components" | ||
order: 5 | ||
--- | ||
|
||
### Definition & Principles | ||
|
||
Read from the [**Porto SAP Documentation (#SubActions)**](https://github.com/Mahmoudz/Porto#SubActions). | ||
|
||
### Rules | ||
|
||
- All SubActions MUST extend from `App\Ship\Parents\Actions\SubAction`. | ||
|
||
### Folder Structure | ||
|
||
``` | ||
- app | ||
- Containers | ||
- {container-name} | ||
- Actions | ||
- ValidateAddressSubAction.php | ||
- BuildOrderSubAction.php | ||
- ... | ||
``` | ||
|
||
### Code Sample | ||
|
||
**ValidateAddressSubAction User Action:** | ||
|
||
```php | ||
<?php | ||
|
||
namespace App\Containers\Shipment\Actions; | ||
|
||
use App\Containers\Recipient\Models\Recipient; | ||
use App\Containers\Recipient\Tasks\UpdateRecipientTask; | ||
use App\Containers\Shipment\Tasks\ValidateAddressWithEasyPostTask; | ||
use App\Containers\Shipment\Tasks\ValidateAddressWithMelissaDataTask; | ||
use App\Ship\Parents\Actions\SubAction; | ||
|
||
class ValidateAddressSubAction extends SubAction | ||
{ | ||
public function run(Recipient $recipient) | ||
{ | ||
$hasValidAddress = true; | ||
|
||
$easyPostResponse = $this->call(ValidateAddressWithEasyPostTask::class, [$recipient]); | ||
|
||
... | ||
} | ||
} | ||
``` | ||
|
||
**Every feature available for Actions, is also available in SubActions.** |