src/Sulu/Component/DocumentManager/ProxyFactory.php
public function createProxyForNode($fromDocument, NodeInterface $targetNode, $options = [])
    {
        // if node is already registered then just return the registered document
        $locale = $this->registry->getOriginalLocaleForDocument($fromDocument);
        if ($this->registry->hasNode($targetNode, $locale)) {
            $document = $this->registry->getDocumentForNode($targetNode, $locale);

            // If the parent is not loaded in the correct locale, reload it in the correct locale.
            if ($this->registry->getOriginalLocaleForDocument($document) !== $locale) {
                $hydrateEvent = new HydrateEvent($targetNode, $locale);
                $hydrateEvent->setDocument($document);
                $this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
            }

            return $document;
        }

        $initializer = function(LazyLoadingInterface $document, $method, array $parameters, &$initializer) use (
            $targetNode,
            $options,
            $locale
        ) {
            $hydrateEvent = new HydrateEvent($targetNode, $locale, $options);
            $hydrateEvent->setDocument($document);
            $this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent);

            $initializer = null;
        };

        $targetMetadata = $this->metadataFactory->getMetadataForPhpcrNode($targetNode);
        $proxy = $this->proxyFactory->createProxy($targetMetadata->getClass(), $initializer);
        $locale = $this->registry->getOriginalLocaleForDocument($fromDocument);
        $this->registry->registerDocument($proxy, $targetNode, $locale);

        return $proxy;
    }
public function createProxyForNode($fromDocument, NodeInterface $targetNode, $options = [])
    {
        // if node is already registered then just return the registered document
        $locale = $this->registry->getOriginalLocaleForDocument($fromDocument);
        if ($this->registry->hasNode($targetNode, $locale)) {
            $document = $this->registry->getDocumentForNode($targetNode, $locale);

            // If the parent is not loaded in the correct locale, reload it in the correct locale.
            if ($this->registry->getOriginalLocaleForDocument($document) !== $locale) {
                $hydrateEvent = new HydrateEvent($targetNode, $locale);
                $hydrateEvent->setDocument($document);
                $this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
            }

            return $document;
        }

        $initializer = function(LazyLoadingInterface $document, $method, array $parameters, &$initializer) use (
            $targetNode,
            $options,
            $locale
        ) {
            $hydrateEvent = new HydrateEvent($targetNode, $locale, $options);
            $hydrateEvent->setDocument($document);
            $this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent);

            $initializer = null;
        };

        $targetMetadata = $this->metadataFactory->getMetadataForPhpcrNode($targetNode);
        $proxy = $this->proxyFactory->createProxy($targetMetadata->getClass(), $initializer);
        $locale = $this->registry->getOriginalLocaleForDocument($fromDocument);
        $this->registry->registerDocument($proxy, $targetNode, $locale);

        return $proxy;
    }
public function createProxyForNode ( $ fromDocument , NodeInterface $ targetNode , $ options = [ ] ) { // if node is already registered then just return the registered document $ locale = $ this -> registry -> getOriginalLocaleForDocument ( $ fromDocument ) ; if ( $ this -> registry -> hasNode ( $ targetNode , $ locale ) ) { $ document = $ this -> registry -> getDocumentForNode ( $ targetNode , $ locale ) ; // If the parent is not loaded in the correct locale, reload it in the correct locale. if ( $ this -> registry -> getOriginalLocaleForDocument ( $ document ) !== $ locale ) { $ hydrateEvent = new HydrateEvent ( $ targetNode , $ locale ) ; $ hydrateEvent -> setDocument ( $ document ) ; $ this -> dispatcher -> dispatch ( Events :: HYDRATE , $ hydrateEvent ) ; } return $ document ; } $ initializer = function ( LazyLoadingInterface $ document , $ method , array $ parameters , & $ initializer ) use ( $ targetNode , $ options , $ locale ) { $ hydrateEvent = new HydrateEvent ( $ targetNode , $ locale , $ options ) ; $ hydrateEvent -> setDocument ( $ document ) ; $ this -> dispatcher -> dispatch ( Events :: HYDRATE , $ hydrateEvent ) ; $ initializer = null ; } ; $ targetMetadata = $ this -> metadataFactory -> getMetadataForPhpcrNode ( $ targetNode ) ; $ proxy = $ this -> proxyFactory -> createProxy ( $ targetMetadata -> getClass ( ) , $ initializer ) ; $ locale = $ this -> registry -> getOriginalLocaleForDocument ( $ fromDocument ) ; $ this -> registry -> registerDocument ( $ proxy , $ targetNode , $ locale ) ; return $ proxy ; }
Create a new proxy object from the given document for
the given target node.

TODO: We only pass the document here in order to correctly evaluate its locale
later. I wonder if it necessary.

@param object $fromDocument
@param NodeInterface $targetNode
@param array $options

@return \ProxyManager\Proxy\GhostObjectInterface
Create a new proxy object from the given document for the given target node .