Recently I wrote question about PHP DOM manipulating: https://forum.phalcon.io/discussion/1218/php-dom-manipulation-offtop-

So, I decided to use queryPath (querypath.org) for PHP DOM Manipulation. I want to implement QueryPath as a service, that returns the object who can manipulate with DOM of the current action view. But I can not understand how to get the current view's content in callback function.

I did this in the following way:

$di->setShared('qp', function() use ($di)
                {
                    $view = $di->getShared("view");
                    $dispatcher = $di->getShared("dispatcher");

                    $view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
                    $view->start();
                    $view->render(
                        $dispatcher->getControllerName(),
                        $dispatcher->getActionName(),
                        $dispatcher->getParams()
                    );
                    $view->finish();
                    return \QueryPath::with($view->getContent());
            });

But it seems too complicated. Is there a better way to get contents of the current action view?