Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 882f504
Showing
12 changed files
with
268 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/nbproject/ | ||
/.idea/ | ||
/vendor/ | ||
/build/ |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Serkin Alexander <serkin.alexander@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,26 @@ | ||
{ | ||
"name": "serkin/volan", | ||
"type": "library", | ||
"description": "PHP array schema validator", | ||
"keywords": ["php", "validation"], | ||
"homepage": "https://github.com/serkin/volan", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Serkin Alexander", | ||
"email": "serkin.alexander@gmail.com", | ||
"homepage": "http://linkedin.com/in/SerkinAlexander", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.5", | ||
"symfony/yaml": "~2.6" | ||
}, | ||
|
||
"autoload": { | ||
"psr-4": { | ||
"Volan\\": "src/" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
<phpunit | ||
bootstrap="vendor/autoload.php" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
colors="true" | ||
verbose="true"> | ||
<php> | ||
<var name="fixture_path" value="tests/fixtures"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="string"> | ||
<directory suffix='.php'>tests/unit/String</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,6 @@ | ||
<?php | ||
|
||
namespace Volan; | ||
|
||
class CustomRecursiveArrayIterator extends \RecursiveArrayIterator | ||
{} |
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,17 @@ | ||
<?php | ||
|
||
namespace Volan\Validator; | ||
|
||
|
||
abstract class AbstractValidator | ||
{ | ||
|
||
public function isRequired() | ||
{ | ||
return false; | ||
} | ||
|
||
abstract function isValid($arrNode, $schemaNode); | ||
|
||
|
||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Volan\Validator; | ||
|
||
class required_string extends AbstractValidator | ||
{ | ||
|
||
public function isRequired() { | ||
return true; | ||
} | ||
|
||
public function isValid($arrNode, $schemaNode) | ||
{ | ||
return false; | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Volan; | ||
|
||
class Volan | ||
{ | ||
|
||
private $schema; | ||
|
||
|
||
public function __construct($schema) { | ||
$this->schema = $schema; | ||
} | ||
|
||
public function validate($arr) | ||
{ | ||
|
||
foreach ($arr as $node): | ||
if(empty($node['_type']) or class_exists($node['_type'], true)): | ||
return 0; | ||
endif; | ||
|
||
$nodeTypeClassString = "\Volan\Validator\\" . $node['_type']; | ||
|
||
$nodeTypeClass = new $nodeTypeClassString; | ||
|
||
unset($node['_type']); | ||
$keys = array_keys($node); | ||
endforeach; | ||
|
||
} | ||
|
||
} |
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,19 @@ | ||
root: | ||
books: | ||
_type: strict_array | ||
title: | ||
_type: required_string | ||
price: | ||
_type: float | ||
comments: | ||
_type: strict_nested_array | ||
|
||
author: | ||
_type: required_string | ||
id_user: | ||
_type: required_mongoid | ||
hide: | ||
_type: boolean | ||
comment: | ||
_type: string | ||
|
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,3 @@ | ||
root: | ||
title: | ||
_type: required_string |
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,37 @@ | ||
<?php | ||
|
||
use Symfony\Component\Yaml\Parser; | ||
|
||
class required_string extends PHPUnit_Framework_TestCase | ||
{ | ||
public $schema; | ||
|
||
|
||
public function setUp() | ||
{ | ||
$yaml = new Parser(); | ||
$this->schema = $yaml->parse(file_get_contents($GLOBALS['fixture_path'] . '/schema/string/required_string.yml')); | ||
} | ||
|
||
public function additionProvider() | ||
{ | ||
return [ | ||
['title' => null], | ||
['title' => []], | ||
['title' => ''], | ||
['title' => [1,2,3]] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider additionProvider | ||
*/ | ||
public function testInvalidData($arr) | ||
{ | ||
|
||
$validator = new \Volan\Volan($this->schema); | ||
$result = $validator->validate($arr); | ||
|
||
$this->assertTrue($result); | ||
} | ||
} |