Skip to content

Commit

Permalink
Validation suppor for methods
Browse files Browse the repository at this point in the history
  • Loading branch information
briedis committed Apr 27, 2015
1 parent 6632d9a commit c53e6a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/Briedis/ApiBuilder/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions src/Briedis/ApiBuilder/StructureValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c53e6a2

Please sign in to comment.