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

Hydrate Manager from json #15

Closed
electricjones opened this issue Aug 23, 2015 · 10 comments
Closed

Hydrate Manager from json #15

electricjones opened this issue Aug 23, 2015 · 10 comments
Milestone

Comments

@electricjones
Copy link
Owner

It should be possible to hydrate an instance from json. Maybe one of:

$manager->fromJson($json);
$manager->resetFromJson($json);
$manager->initFromJson($json);
@electricjones electricjones modified the milestone: 0.8.6 Sep 6, 2015
@smolinari
Copy link
Contributor

In reference to our discussion here, I'd like to take a crack at this.

Anything you'd like me to look out for?

Scott

@electricjones
Copy link
Owner Author

That's great! I would really appreciate it. Just be sure to branch off of develop. It should be relatively simple, please be sure to write a test or two and update the readme for it as well. If you have any questions, let me know. Make the changes to ManagesItemsTrait.

@smolinari
Copy link
Contributor

Ok. I have a first attempt working.

However, json_decode() can decode to an object or an array and I currently have the assoc array option set to true and am only testing for an array. Do we only want an array created from json_decode? Or do we want to give the option to create an object too?

Would there be a possible request to hydrate from other formats (XML, YAML)? Being the docs say the manager would be good for managing config data, I thought this might be useful or needed later, so I built in a parameter for the type.

Oh, and I called the method hydrateFrom(). 😃

Scott

@electricjones
Copy link
Owner Author

That's great. Can you issue a PR so I can see the code and test the build?

I think json_decode should decode to an array so you can just use one of the internal methods to add like reset(). And, yes, it would be great to hydrate from other formats. I had planned on starting with json, then yaml, and then allowing some kind of parser system so users can add their own formats for the rest of the craziness out there.

It also just occurred to me that there are possibly two things users may want.

  1. The initial hydration from json or rehydration from json (which would wipe all current data)
  2. And adding json data to the already existing stack.

Maybe two different methods? Luckily, Manager already has reset() and add() which should help.

@smolinari
Copy link
Contributor

I am not certain about the big picture for sure, but I find it hard to imagine a hydration from external sources as an appending type of function being common. I'd say, make it a reset and leave a possible appending feature for the future, should someone ask for it.

Scott

@smolinari
Copy link
Contributor

Actually, never mind. I can think of a scenario. I'll create it.

hydrateFrom('json', $data) causes a reset and creates a fresh manager.
appendFrom('json', $data) causes an adding of the data to the current manager.

Scott

@smolinari
Copy link
Contributor

Ok. PR is up!

#26

Scott

@smolinari
Copy link
Contributor

Edit: Hold on a sec...

Scott

@smolinari
Copy link
Contributor

Ok. That looks better. I think. LOL! 😃

Scott

@electricjones
Copy link
Owner Author

Merged #26.

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

No branches or pull requests

2 participants