This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from wavevision/feature/valid-props-object
Feature/valid props object
- Loading branch information
Showing
17 changed files
with
263 additions
and
38 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 |
---|---|---|
|
@@ -118,4 +118,5 @@ function (?string $modifier): bool { | |
} | ||
); | ||
} | ||
|
||
} |
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,10 @@ | ||
<?php declare (strict_types = 1); | ||
|
||
namespace Wavevision\PropsControl\Exceptions; | ||
|
||
use Exception; | ||
|
||
class InvalidProps extends Exception | ||
{ | ||
|
||
} |
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,10 @@ | ||
<?php declare (strict_types = 1); | ||
|
||
namespace Wavevision\PropsControl\Exceptions; | ||
|
||
use Exception; | ||
|
||
class InvalidState extends Exception | ||
{ | ||
|
||
} |
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 declare (strict_types = 1); | ||
|
||
namespace Wavevision\PropsControl; | ||
|
||
use Nette\SmartObject; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ProcessedProps | ||
{ | ||
|
||
use SmartObject; | ||
|
||
/** | ||
* @var mixed[] | ||
*/ | ||
private $values = []; | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __set(string $name, $value): void | ||
{ | ||
$this->values[$name] = $value; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getValues(): array | ||
{ | ||
return $this->values; | ||
} | ||
|
||
} |
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,78 @@ | ||
<?php declare (strict_types = 1); | ||
|
||
namespace Wavevision\PropsControl; | ||
|
||
use Nette\MemberAccessException; | ||
use Nette\SmartObject; | ||
use stdClass; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ValidProps extends stdClass | ||
{ | ||
|
||
use SmartObject; | ||
|
||
/** | ||
* @var Props|null | ||
*/ | ||
private $props; | ||
|
||
/** | ||
* @var mixed[] | ||
*/ | ||
private $values; | ||
|
||
/** | ||
* @param mixed[] $values | ||
*/ | ||
public function __construct(array $values) | ||
{ | ||
$this->values = $values; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function &__get(string $name) | ||
{ | ||
if (!$this->isSet($name)) { | ||
throw new MemberAccessException("Prop '$name' does on exist in validated props object."); | ||
} | ||
return $this->values[$name]; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function get(string $prop) | ||
{ | ||
return $this->values[$prop]; | ||
} | ||
|
||
/** | ||
* @return mixed|null | ||
*/ | ||
public function getNullable(string $prop) | ||
{ | ||
return $this->isSet($prop) ? $this->get($prop) : null; | ||
} | ||
|
||
public function isSet(string $prop): bool | ||
{ | ||
return array_key_exists($prop, $this->values); | ||
} | ||
|
||
public function getProps(): ?Props | ||
{ | ||
return $this->props; | ||
} | ||
|
||
public function setProps(Props $props): self | ||
{ | ||
$this->props = $props; | ||
return $this; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -48,4 +48,5 @@ function () use ($modifiers): array { | |
} | ||
); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -11,4 +11,5 @@ protected function getPropsClass(): string | |
{ | ||
return ''; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -42,4 +42,5 @@ protected function define(): array | |
self::TYPE => Expect::anyOf(...self::TYPES)->default(self::TYPE_ONE), | ||
]; | ||
} | ||
|
||
} |
Oops, something went wrong.