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.
add request state keeper to store data on the request object
- Loading branch information
Showing
3 changed files
with
74 additions
and
15 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,45 @@ | ||
<?php | ||
|
||
namespace App\Ship\Parents\Requests; | ||
|
||
/** | ||
* Class StateKeeperTrait | ||
* | ||
* @author Mahmoud Zalt <[email protected]> | ||
*/ | ||
trait StateKeeperTrait | ||
{ | ||
|
||
/** | ||
* Stores Data of any kind during the request life cycle. | ||
* This helps related Actions can share data from different steps. | ||
* | ||
* @var array | ||
*/ | ||
public $state = []; | ||
|
||
/** | ||
* @param array $data | ||
* | ||
* @return $this | ||
*/ | ||
public function keep(array $data = []) | ||
{ | ||
foreach ($data as $key => $value) { | ||
$this->state[$key] = $value; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param $key | ||
* | ||
* @return mixed | ||
*/ | ||
public function retrieve($key) | ||
{ | ||
return $this->state[$key]; | ||
} | ||
|
||
} |
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