-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added request attribute interface (#2)
* Added request attribute interface * Fixed typos + minor issues + updated README
- Loading branch information
Showing
11 changed files
with
501 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Files to exclude when creating archive | ||
/.github export-ignore | ||
/tests export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/phpstan.neon export-ignore | ||
/phpunit.xml.dist export-ignore |
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
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
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,29 @@ | ||
<?php | ||
/** | ||
* SimpleMVC | ||
* | ||
* @link http://github.com/simplemvc/framework | ||
* @copyright Copyright (c) Enrico Zimuel (https://www.zimuel.it) | ||
* @license https://opensource.org/licenses/MIT MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace SimpleMVC\Controller; | ||
|
||
interface AttributeInterface | ||
{ | ||
/** | ||
* Add an attribute for the next PSR-7 request in a pipeline | ||
* | ||
* @param mixed $value | ||
*/ | ||
public function addRequestAttribute(string $name, $value): void; | ||
|
||
/** | ||
* Get a request attribute, if $name is not specified return | ||
* all the attributes as array | ||
* | ||
* @return mixed | ||
*/ | ||
public function getRequestAttribute(string $name = null); | ||
} |
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,36 @@ | ||
<?php | ||
/** | ||
* SimpleMVC | ||
* | ||
* @link http://github.com/simplemvc/framework | ||
* @copyright Copyright (c) Enrico Zimuel (https://www.zimuel.it) | ||
* @license https://opensource.org/licenses/MIT MIT License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace SimpleMVC\Controller; | ||
|
||
trait AttributeTrait | ||
{ | ||
/** @var mixed[] */ | ||
protected array $attributes = []; | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function addRequestAttribute(string $name, $value): void | ||
{ | ||
$this->attributes[$name] = $value; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getRequestAttribute(string $name = null) | ||
{ | ||
if (empty($name)) { | ||
return $this->attributes; | ||
} | ||
return $this->attributes[$name] ?? null; | ||
} | ||
} |
Oops, something went wrong.