-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added symfony validator feature #2
Conversation
src/Jms/YamlValidatorConverter.php
Outdated
} | ||
|
||
if ($rules) { | ||
if (!!count($rules)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use a more intuitive boolean. !==0
is more understandable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied better codding. See 3151dcb
src/Jms/YamlValidatorConverter.php
Outdated
} | ||
} | ||
|
||
if (!!count($rules)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use !==0
or >0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied better codding. See 3151dcb
} | ||
} | ||
|
||
protected function visitSimpleType(&$class, &$data, SimpleType $type, $name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can have also arrays of objects, not just primitives, they have to be validated too.
essentially each property needs the rule Valid
to apply recursive validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented feature to apply these rules. See c1699dc
tests/Converter/JMS/Xsd2JmsBase.php
Outdated
@@ -38,7 +38,7 @@ protected function getClasses($xml) | |||
public function getBaseTypeConversions() | |||
{ | |||
return [ | |||
['xs:dateTime', 'DateTime'], | |||
['xs:dateTime', 'GoetasWebservices\\Xsd\\XsdToPhp\\XMLSchema\\DateTime'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is used as dataProvider
in testElementOfBaseType. Adjusted to fill param $phpName with GoetasWebservices\\Xsd\\XsdToPhp\\XMLSchema\\DateTime
value. See 32dc6ff
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy; | ||
use GoetasWebservices\XML\XSDReader\SchemaReader; | ||
|
||
abstract class Xsd2ValidatorBase extends \PHPUnit_Framework_TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently there is only one class that inherits from this (Xsd2ValidatorTest
) isn't this premature architecture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. See baff9be
<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ex="http://www.example.com"> | ||
<xs:complexType name="complexType-1"> | ||
<xs:sequence> | ||
<xs:element name="column1"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is good, I will add another test, having <xs:element name="column1" maxOccours="unbounded">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created some tests in separate cases. See f42fe40
{ | ||
$xml = " | ||
<xs:schema targetNamespace=\"http://www.example.com\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"> | ||
<xs:element name=\"element-one\"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is good, I will add another test, having <xs:element name="element-one" maxOccours="unbounded">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created some tests in separate cases. See f42fe40
$ymlValidations, | ||
[ | ||
[ | ||
'NotBlank' => null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pay attention, there is a subtle difference between NotBlank
and NotNull
.
In almost all the cases you should use not null probably
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based NotBlank doc implement not equal to a blank string and also not equal to null. It's great for me. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in xml, a node that says:
minOccours=1, regex="[a-z]"
and empty string is a valid value :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect. You convinced me, :)
tests/Validator/ValidatorTest.php
Outdated
public function setUp() | ||
{ | ||
$loader = new ClassLoader(); | ||
$loader->addPsr4("OTA\\", "/home/goetas/projects/goetas-webservices-xsd2php/ota/php"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this are just example paths.. they have to be configured.
src/Jms/YamlValidatorConverter.php
Outdated
'Count' => ['min' => 1] | ||
]; | ||
} | ||
$property["validator"][] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably this is not necessary (or is an constraint that we do not know yet if apply or not)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first is necessary for simple type/native type for indicate if required or not.
…s array. Fix some bugs for visit array elements.
Reading extended elements still need to be implemented. |
…ot use 'validator' item. Fix some bugs.
If somebody is interested in sponsoring this feature I can continue to work on it. Pricing can be agreed (compatible with west-european hourly rates). |
After a lot of work, this is almost done. Only a bit of documentation in missing. |
Syntax should be: <?php
use Symfony\Component\Validator\Validation;
// get the validator
$builder = Validation::createValidatorBuilder();
foreach (glob('soap/validation/*.yml') as $file) {
$builder->addYamlMapping($file);
}
$validator = $builder->getValidator();
// validate $object
$violations = $validator->validate($object, null, ['xsd_rules']); |
No description provided.