diff --git a/src/mibew/libs/classes/Mibew/Controller/AbstractController.php b/src/mibew/libs/classes/Mibew/Controller/AbstractController.php index bf46f41b..1a96ae31 100644 --- a/src/mibew/libs/classes/Mibew/Controller/AbstractController.php +++ b/src/mibew/libs/classes/Mibew/Controller/AbstractController.php @@ -120,20 +120,6 @@ abstract class AbstractController implements public function setAssetManager(AssetManagerInterface $manager) { $this->assetManager = $manager; - - // Update URL generator in the style helpers - if (!is_null($this->style) && $this->style instanceof HandlebarsAwareInterface) { - $handlebars = $this->style->getHandlebars(); - if ($handlebars->hasHelper('asset')) { - $handlebars->getHelper('asset')->setAssetUrlGenerator($manager->getUrlGenerator()); - } - if ($handlebars->hasHelper('jsAssets')) { - $handlebars->getHelper('jsAssets')->setAssetManager($manager); - } - if ($handlebars->hasHelper('cssAssets')) { - $handlebars->getHelper('cssAssets')->setAssetManager($manager); - } - } } /** @@ -358,18 +344,12 @@ abstract class AbstractController implements $hbs->addHelper( 'asset', new AssetHelper( - $this->getAssetManager()->getUrlGenerator(), + $this, array('CurrentStyle' => $style->getFilesPath()) ) ); - $hbs->addHelper( - 'jsAssets', - new JsAssetsHelper($this->getAssetManager()) - ); - $hbs->addHelper( - 'cssAssets', - new CssAssetsHelper($this->getAssetManager()) - ); + $hbs->addHelper('jsAssets', new JsAssetsHelper($this)); + $hbs->addHelper('cssAssets', new CssAssetsHelper($this)); } return $style; diff --git a/src/mibew/libs/classes/Mibew/Handlebars/Helper/AbstractAssetsHelper.php b/src/mibew/libs/classes/Mibew/Handlebars/Helper/AbstractAssetsHelper.php index 2817b2c6..c446d975 100644 --- a/src/mibew/libs/classes/Mibew/Handlebars/Helper/AbstractAssetsHelper.php +++ b/src/mibew/libs/classes/Mibew/Handlebars/Helper/AbstractAssetsHelper.php @@ -29,37 +29,22 @@ use Mibew\Asset\AssetManagerInterface; /** * Contains for basic functionality for all helpers which renders assets lists. */ -abstract class AbstractAssetsHelper implements HelperInterface, AssetManagerAwareInterface +abstract class AbstractAssetsHelper implements HelperInterface { /** - * @var AssetManagerInterface|null + * @var AssetManagerAwareInterface|null */ - protected $manager = null; + protected $assetManagerContainer = null; /** * Class constructor. * - * @param AssetUrlGeneratorInterface $manager An instance of Asset Manager. + * @param AssetManagerAwareInterface $manager_container An object which know + * where to get an appropriate Asset Manager. */ - public function __construct(AssetManagerInterface $manager) + public function __construct(AssetManagerAwareInterface $manager_container) { - $this->manager = $manager; - } - - /** - * {@inheritdoc} - */ - public function getAssetManager() - { - return $this->manager; - } - - /** - * {@inheritdoc} - */ - public function setAssetManager(AssetManagerInterface $manager) - { - $this->manager = $manager; + $this->assetManagerContainer = $manager_container; } /** @@ -95,6 +80,17 @@ abstract class AbstractAssetsHelper implements HelperInterface, AssetManagerAwar return new SafeString(implode("\n", $buffer)); } + /** + * Extracts asset manager from the asset manager's container related with + * the object. + * + * @return AssetManagerInterface + */ + protected function getAssetManager() + { + return $this->assetManagerContainer->getAssetManager(); + } + /** * Renders URL of an asset. * diff --git a/src/mibew/libs/classes/Mibew/Handlebars/Helper/AssetHelper.php b/src/mibew/libs/classes/Mibew/Handlebars/Helper/AssetHelper.php index dbd2af0b..0f5a267e 100644 --- a/src/mibew/libs/classes/Mibew/Handlebars/Helper/AssetHelper.php +++ b/src/mibew/libs/classes/Mibew/Handlebars/Helper/AssetHelper.php @@ -22,6 +22,7 @@ namespace Mibew\Handlebars\Helper; use Handlebars\Context; use Handlebars\Helper as HelperInterface; use Handlebars\Template; +use Mibew\Asset\AssetManagerAwareInterface; use Mibew\Asset\Generator\UrlGeneratorInterface as AssetUrlGeneratorInterface; /** @@ -36,7 +37,7 @@ use Mibew\Asset\Generator\UrlGeneratorInterface as AssetUrlGeneratorInterface; * paths. Lets assume that the following array is passed to the constructor: * * $helper = new AssetHelper( - * $generator, + * $asset_manager_container, * array('CustomStorage' => 'custom/files/storage') * ); * @@ -54,22 +55,23 @@ class AssetHelper implements HelperInterface protected $locations = null; /** - * @var AssetUrlGeneratorInterface|null + * @var AssetManagerAwareInterface|null */ - protected $generator = null; + protected $assetManagerContainer = null; /** * Class constructor. * - * @param AssetUrlGeneratorInterface $generator An instance of URL generator + * @param AssetManagerAwareInterface $manager_container An object which + * knows where to get an appropriate Asset Manager. * @param array $locations Associative array of locations that can be used * as prefixes for asset relative paths. The keys are prefixes and the * values are locations relative paths. These paths must not content * neither leading nor trailing slashes. */ - public function __construct(AssetUrlGeneratorInterface $generator, $locations = array()) + public function __construct(AssetManagerAwareInterface $manager_container, $locations = array()) { - $this->generator = $generator; + $this->assetManagerContainer = $manager_container; // Strip slashes from location paths. foreach ($locations as $name => $path) { @@ -77,26 +79,6 @@ class AssetHelper implements HelperInterface } } - /** - * Gets instance of Asset URL Generator. - * - * @return AssetUrlGeneratorInterface - */ - public function getAssetUrlGenerator() - { - return $this->generator; - } - - /** - * Sets an instance of Asset URL Generator. - * - * @param AssetUrlGeneratorInterface $generator - */ - public function setAssetUrlGenerator(AssetUrlGeneratorInterface $generator) - { - $this->generator = $generator; - } - /** * {@inheritdoc} */ @@ -120,7 +102,18 @@ class AssetHelper implements HelperInterface ); } - return $this->generator->generate($relative_path); + return $this->getAssetUrlGenerator()->generate($relative_path); + } + + /** + * Extracts an instance of Asset URL Generator from the Asset Manager + * container related with the object. + * + * @return AssetUrlGeneratorInterface + */ + protected function getAssetUrlGenerator() + { + return $this->assetManagerContainer->getAssetManager()->getUrlGenerator(); } /**