From c53e6a218536b19348bc98901975b219e0cef31e Mon Sep 17 00:00:00 2001 From: MBriedis Date: Mon, 27 Apr 2015 21:27:27 +0300 Subject: [PATCH] Validation suppor for methods --- src/Briedis/ApiBuilder/Method.php | 15 ++++++++++++++- src/Briedis/ApiBuilder/StructureValidator.php | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Briedis/ApiBuilder/Method.php b/src/Briedis/ApiBuilder/Method.php index be23a39..7da85c3 100644 --- a/src/Briedis/ApiBuilder/Method.php +++ b/src/Briedis/ApiBuilder/Method.php @@ -4,9 +4,12 @@ namespace Briedis\ApiBuilder; +use Briedis\ApiBuilder\Exceptions\InvalidStructureException; +use Illuminate\Contracts\Validation\ValidatesWhenResolved; use Illuminate\Support\Str; +use Input; -abstract class Method{ +abstract class Method implements ValidatesWhenResolved{ /** * Requests uri (without trailing and preceding slashes) */ @@ -64,4 +67,14 @@ public function getDocUrl(){ public function getDocElementName(){ return Str::slug(static::METHOD . '-' . static::URI); } + + /** + * Validate the given class instance. + * @return void + * @throws InvalidStructureException + */ + public function validate(){ + $validator = new StructureValidator($this->getRequest()); + $validator->validate(Input::all()); + } } \ No newline at end of file diff --git a/src/Briedis/ApiBuilder/StructureValidator.php b/src/Briedis/ApiBuilder/StructureValidator.php index 92a132e..f4ecb26 100644 --- a/src/Briedis/ApiBuilder/StructureValidator.php +++ b/src/Briedis/ApiBuilder/StructureValidator.php @@ -18,10 +18,10 @@ class StructureValidator{ private $parameterDepthStack = []; /** - * @param StructureBuilder $structure Structure to be validated against + * @param StructureInterface $structure Structure to be validated against * @param array $parameterDepthStack */ - public function __construct(StructureBuilder $structure, array &$parameterDepthStack = []){ + public function __construct(StructureInterface $structure, array &$parameterDepthStack = []){ $this->structure = $structure; $this->parameterDepthStack = $parameterDepthStack; }