Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Nested Objects #46

Open
Norcoen opened this issue Feb 25, 2016 · 6 comments
Open

Nested Objects #46

Norcoen opened this issue Feb 25, 2016 · 6 comments
Labels

Comments

@Norcoen
Copy link

Norcoen commented Feb 25, 2016

I'm getting NULL for nested objects, is it possible do use this recursively?

@Ocramius
Copy link
Owner

Possibly duplicate of #45 ?

@Norcoen
Copy link
Author

Norcoen commented Feb 25, 2016

Might be a duplicate.
My Objects are already created and nested before I can create the hydrator, is this a problem?

@Ocramius
Copy link
Owner

@Norcoen shouldn't be. Can you write an example script with just composer require ocramius/generated-hydrator?

@Norcoen
Copy link
Author

Norcoen commented Feb 25, 2016

Sry, I don't think I can extract all of the things I'm using.
My main problem is, that PHPExcel uses arrays to apply styles, but only gives back objects, making it impossible to write a condition to not apply styles that already have a value.
Maybe I can just write an example from scratch, will try that.

Can you provide an example of #45's "pass hydrator as property value"? I don't understand what and to whom I'd have to pass it.

Right now I have this:

                $exampleClassName = "classA";
                $config        = new Configuration($exampleClassName );
                $hydratorClass = $config->createFactory()->getHydratorClass();
                $hydrator      = new $hydratorClass();

                $tmp = $this->getSampleObject();

                $tmp2 = $hydrator->extract($tmp);
                foreach ($tmp2 as $key => $possibleObj) {
                    if (is_object($possibleObj)) {
                        $nestedClassName = get_class($possibleObj);
                        var_dump($key, $nestedClassName);
                        $config        = new Configuration($nestedClassName);
                        $hydratorClass = $config->createFactory()->getHydratorClass();
                        $hydrator      = new $hydratorClass();

                        $tmp2[$key] = $hydrator->extract($possibleObj);
                    }
                }
                var_dump($tmp2);

Works for the first level, so I could do it recursively, possibly with array_walk_recursive(), but even the first level takes ages, because the object has properties like "parent", taking this to infinity.
So maybe I need to detect recursion manually to avoid this?

@Ocramius
Copy link
Owner

but even the first level takes ages, because the object has properties like "parent", taking this to infinity.

You are also re-generating the hydrators all the time there :-\

@slince
Copy link

slince commented Nov 28, 2017

+1

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

No branches or pull requests

3 participants