Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move parameter type construction out of ParamDefinitionFactory
- Loading branch information
1 parent
039b1ad
commit 93e4df0
Showing
8 changed files
with
209 additions
and
148 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
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 @@ | ||
<?php | ||
|
||
namespace ParamProcessor\PackagePrivate; | ||
|
||
use ParamProcessor\ParamDefinition; | ||
use ValueParsers\NullParser; | ||
use ValueValidators\NullValidator; | ||
|
||
class ParamType { | ||
|
||
private $typeId; | ||
|
||
private $className; | ||
private $stringParser; | ||
private $typedParser; | ||
private $validator; | ||
private $validationCallback; | ||
|
||
private function __construct( string $typeId ) { | ||
$this->typeId = $typeId; | ||
} | ||
|
||
public static function newFromArray( string $typeId, array $spec ): self { | ||
$type = new self( $typeId ); | ||
|
||
$type->className = array_key_exists( 'definition', $spec ) ? $spec['definition'] : ParamDefinition::class; | ||
$type->stringParser = array_key_exists( 'string-parser', $spec ) ? $spec['string-parser'] : NullParser::class; | ||
$type->typedParser = array_key_exists( 'typed-parser', $spec ) ? $spec['typed-parser'] : NullParser::class; | ||
$type->validator = array_key_exists( 'validator', $spec ) ? $spec['validator'] : NullValidator::class; | ||
$type->validationCallback = array_key_exists( 'validation-callback', $spec ) ? $spec['validation-callback'] : null; | ||
|
||
return $type; | ||
} | ||
|
||
public function getClassName(): string { | ||
return $this->className; | ||
} | ||
|
||
public function getValidatorClass(): string { | ||
return $this->validator; | ||
} | ||
|
||
public function getValidationCallback(): ?callable { | ||
return $this->validationCallback; | ||
} | ||
|
||
public function getStringParserClass(): string { | ||
return $this->stringParser; | ||
} | ||
|
||
public function getTypedParserClass(): string { | ||
return $this->typedParser; | ||
} | ||
|
||
} |
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
Oops, something went wrong.