Skip to content

New way of handling references #277

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 15, 2016
Merged

New way of handling references #277

merged 1 commit into from
Aug 15, 2016

Conversation

psafarov
Copy link

@psafarov psafarov commented Jun 4, 2016

I had issues compiling schemas containing circular references with RefResolver, so the way of handling references was changed, now Validator contains SchemaStorage object inside, which contains all schemas and can resolve references when it's needed. The pros of this approach are:

  • lazy loading, if some schemas are not used, they won't be loaded
  • no infinite loops, thanks to lazy evaluation again
  • api becomes kind of simpler
<?php
// You can pass reference which will be handled by SchemaStorage::resolveRef
$validator->check($data, (object)['$ref' => 'file://path/to/your/shcema'])

@@ -7,3 +7,4 @@ coverage
.settings
composer.lock
docs-api
.idea/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please omit this change and add this to a global .gitignore https://help.github.com/articles/ignoring-files/#create-a-global-gitignore

@bighappyface
Copy link
Collaborator

@psafarov please rebase this on master

@@ -27,29 +31,13 @@ public function getUriRetriever()
}

/**
* @param UriRetrieverInterface $uriRetriever
*/
public function setUriRetriever($uriRetriever)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This approach prevents reuse of an instance of SchemaStorage by only allowing a user to set the retriever or resolver only during instantiation. The goal of simplifying instantiation SchemaStorage is achieved but I am not sure that is a problem nor am I sure it is germane to the main goal of handling circular references.

I am not sure I think this is an improvement but I won't hold up this PR for this if the community supports this move.

Copy link
Author

@psafarov psafarov Jun 27, 2016

Choose a reason for hiding this comment

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

@bighappyface you're right, it's not only about circular references. I also wanted to simplify the interface. Now there is no RefResolvers you need to know about, until you have to

@ElectroLutz
Copy link

ElectroLutz commented Aug 1, 2016

Any info on this one? I would like to see this in a release.

@bighappyface
Copy link
Collaborator

@FlorianSW @steffkes @mirfilip would you mind giving this PR a review? This looks to be all but certainly a major update that would push us to 3.0.0.

SchemaStorage $schemaStorage = null,
UriRetriever $uriRetriever = null,
Factory $factory = null
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't it be kinda easier to move $schemaStorage to the end of the list? if we'd append it to the existing list, we wouldn't introduce a BC-Break at this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 This seems like an unnecessary breaking change. However, if this is already a breaking change (and in this core functionality), it probably doesn't make sense to reorder arguments, if it makes sense. Unfortunately, I don't see a good reason to do it here? :)

Copy link
Author

@psafarov psafarov Aug 3, 2016

Choose a reason for hiding this comment

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

@steffkes @FlorianSW I think, you're right, it's better to be in the end

@steffkes
Copy link
Contributor

steffkes commented Aug 2, 2016

just had a first glance over the changes - did add a comment where i thought it's need. will have a more detailed look during this week - given this PR is still open and not already merged


/**
* Factory for centralize constraint initialization.
*/
class Factory
{
/**
* @var SchemaStorage
*/
protected $schemaStorage;
Copy link
Contributor

Choose a reason for hiding this comment

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

We've a getter method for $uriRetriever, wouldn't it make sense to have one for $schemStorage, too?

@FlorianSW
Copy link
Contributor

Added some comments. For now it looks sane and reasonable, but someone (:P) should test it in a real life example, just to make sure it's working like expected :)

@psafarov
Copy link
Author

psafarov commented Aug 3, 2016

@FlorianSW I can't say It has no bugs for sure, but this code is used in production in a company, no problems so far

@bighappyface
Copy link
Collaborator

@psafarov I have merged a few PRs this morning and I put this PR out of sync. Would you please rebase on master?

@psafarov
Copy link
Author

@bighappyface done

@bighappyface
Copy link
Collaborator

@psafarov sorry for the confusion. It looks like you merged master in okay but rebasing is different than merging master in. There should only be one commit in this PR.

@psafarov
Copy link
Author

psafarov commented Aug 11, 2016

@bighappyface fixed.

@bighappyface
Copy link
Collaborator

With community support I'll merge it into master. The plan is to merge it and then bump to 3.0.0 so indicate BC-breaking changes.

Other PRs I have merged have probably already put us in a position to bump to 3.0.0 anyway.

@bighappyface
Copy link
Collaborator

bighappyface commented Aug 15, 2016

Based on the passing tests, the account of this code being in production, the need for verified handling of circular references, and what feels like community approval and support, I am going to move this along and am going to cut release 3.0.0.

+1

@bighappyface bighappyface merged commit 1296583 into jsonrainbow:master Aug 15, 2016
@bighappyface bighappyface mentioned this pull request Aug 15, 2016
@neoascetic
Copy link

👍

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

Successfully merging this pull request may close these issues.

6 participants