Skip to content
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

Merged
merged 36 commits into from
Apr 29, 2019

Conversation

goetas
Copy link
Member

@goetas goetas commented Oct 31, 2016

No description provided.

}

if ($rules) {
if (!!count($rules)) {
Copy link
Member Author

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

Copy link
Contributor

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

}
}

if (!!count($rules)) {
Copy link
Member Author

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

Copy link
Contributor

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)
Copy link
Member Author

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.

Copy link
Contributor

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

@@ -38,7 +38,7 @@ protected function getClasses($xml)
public function getBaseTypeConversions()
{
return [
['xs:dateTime', 'DateTime'],
['xs:dateTime', 'GoetasWebservices\\Xsd\\XsdToPhp\\XMLSchema\\DateTime'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this?

Copy link
Contributor

@davidsonalencar davidsonalencar Nov 1, 2016

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
Copy link
Member Author

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?

Copy link
Contributor

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">
Copy link
Member Author

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">

Copy link
Contributor

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\">
Copy link
Member Author

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">

Copy link
Contributor

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
Copy link
Member Author

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

Copy link
Contributor

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?

Copy link
Member Author

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. You convinced me, :)

public function setUp()
{
$loader = new ClassLoader();
$loader->addPsr4("OTA\\", "/home/goetas/projects/goetas-webservices-xsd2php/ota/php");
Copy link
Member Author

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.

'Count' => ['min' => 1]
];
}
$property["validator"][] = [
Copy link
Member Author

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)

Copy link
Contributor

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.

@goetas goetas changed the title Added symfony validator feature [WIP] Added symfony validator feature Nov 1, 2016
@davidsonalencar
Copy link
Contributor

Reading extended elements still need to be implemented.

@goetas
Copy link
Member Author

goetas commented Jan 20, 2019

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).

@goetas goetas changed the title [WIP] Added symfony validator feature Added symfony validator feature Apr 27, 2019
@goetas
Copy link
Member Author

goetas commented Apr 27, 2019

After a lot of work, this is almost done.
Validating the objects before or after xsd serialization/deserialization now is possible using the symfony/validator generated metadata!

Only a bit of documentation in missing.

@goetas
Copy link
Member Author

goetas commented Apr 27, 2019

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']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants