Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

ZendViewRendererFactory override HelperPluginManager #54

@popovserhii

Description

@popovserhii

I have Factory which retrieves PhpRenderer from Container and injects this to my AssetMiddleware which prepare js/css files and appends them to view helpers (headLink, headStyle, inlineScript, headScript). During this time PhpRenderer initialize HelperPluginManager

public function getHelperPluginManager()
{
	if (null === $this->__helpers) {
		$this->setHelperPluginManager(new HelperPluginManager(new ServiceManager()));
	}
	return $this->__helpers;
}

But when I inject \Zend\Expressive\ZendView\ZendViewRenderer to my Action \Zend\Expressive\ZendView\ZendViewRendererFactory override HelperPluginManager which was initialized before

// Inject helpers
$this->injectHelpers($renderer, $container);

Factory simply check if HelperPluginManager was registered in Container. There is no check if PhpRenderer already has initialized HelperPluginManager

private function retrieveHelperManager(ContainerInterface $container) : HelperPluginManager
{
	if ($container->has(HelperPluginManager::class)) {
		return $container->get(HelperPluginManager::class);
	}

	if (! $container instanceof InteropContainerInterface) {
		throw new Exception\InvalidContainerException(sprintf(
			'%s expects a %s instance to its constructor; however, your service'
			. ' container is an instance of %s, which does not implement that'
			. ' interface. Consider switching to zend-servicemanager for your'
			. ' container implementation if you wish to use the zend-view renderer.',
			HelperPluginManager::class,
			InteropContainerInterface::class,
			get_class($container)
		));
	}

	return new HelperPluginManager($container);
}

This behavior creates two different HelperPluginManager and creates many problems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions