diff options
| author | Loic GUEGAN <loic@Manzerbredes> | 2016-01-23 14:37:24 +0100 |
|---|---|---|
| committer | Loic GUEGAN <loic@Manzerbredes> | 2016-01-23 14:37:24 +0100 |
| commit | 189f7a9ef4c6265dbac232e5c5685aebbbfc7c53 (patch) | |
| tree | d397facc1e45cee4713ea95b0eaa4ffa9cbf0921 /server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Factory.php | |
| parent | 2984adf171c49940e683fa997e8cdc60fcf1d60b (diff) | |
| parent | a44cc1d2e3c0f147e91a5c052ac7fd879e34e706 (diff) | |
Merge branch 'develop' of github.com:manzerbredes/istic-openstack into develop
Diffstat (limited to 'server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Factory.php')
| -rw-r--r-- | server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Factory.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Factory.php b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Factory.php new file mode 100644 index 0000000..a4570f6 --- /dev/null +++ b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Factory.php @@ -0,0 +1,81 @@ +<?php + +/* + * This file is part of the JsonSchema package. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace JsonSchema\Constraints; + +use JsonSchema\Exception\InvalidArgumentException; +use JsonSchema\Uri\UriRetriever; +use JsonSchema\Validator; + +/** + * Factory for centralize constraint initialization. + */ +class Factory +{ + /** + * @var UriRetriever + */ + protected $uriRetriever; + + /** + * @param UriRetriever $uriRetriever + */ + public function __construct(UriRetriever $uriRetriever = null) + { + if (!$uriRetriever) { + $uriRetriever = new UriRetriever(); + } + + $this->uriRetriever = $uriRetriever; + } + + /** + * @return UriRetriever + */ + public function getUriRetriever() + { + return $this->uriRetriever; + } + + /** + * Create a constraint instance for the given constraint name. + * + * @param string $constraintName + * @return ConstraintInterface|ObjectConstraint + * @throws InvalidArgumentException if is not possible create the constraint instance. + */ + public function createInstanceFor($constraintName) + { + switch ($constraintName) { + case 'array': + case 'collection': + return new CollectionConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + case 'object': + return new ObjectConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + case 'type': + return new TypeConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + case 'undefined': + return new UndefinedConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + case 'string': + return new StringConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + case 'number': + return new NumberConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + case 'enum': + return new EnumConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + case 'format': + return new FormatConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + case 'schema': + return new SchemaConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + case 'validator': + return new Validator(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + } + + throw new InvalidArgumentException('Unknown constraint ' . $constraintName); + } +} |
