Skip to content

Commit

Permalink
Improve structure
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpoensgen committed Feb 3, 2019
1 parent 3d3aea4 commit e200416
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>

<service class="Shopware\Components\Plugin\CachedConfigReader" id="sp_lazy_load.config" >
<factory service="shopware.plugin.cached_config_reader" method="getByPluginName"/>
<argument type="string">SpLazyLoad</argument>
</service>

<service class="SpLazyLoad\Subscriber\TemplateRegistration" id="sp_lazy_load.subscriber.template_registration">
<argument>%sp_lazy_load.plugin_dir%</argument>
<argument>%sp_lazy_load.plugin_name%</argument>
<argument type="service" id="shopware.plugin.cached_config_reader"/>
<argument type="service" id="sp_lazy_load.config"/>
<tag name="shopware.event_subscriber"/>
</service>

Expand Down
25 changes: 8 additions & 17 deletions Subscriber/TemplateRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\Common\Collections\ArrayCollection;
use Enlight\Event\SubscriberInterface;
use Shopware\Components\Plugin\CachedConfigReader;

class TemplateRegistration implements SubscriberInterface
{
Expand All @@ -14,27 +13,20 @@ class TemplateRegistration implements SubscriberInterface
private $pluginDir;

/**
* @var string
*/
private $pluginName;

/**
* @var CachedConfigReader
* @var array
*/
private $config;
private $pluginConfig;

/**
* TemplateRegistration constructor.
*
* @param string $pluginDir
* @param string $pluginName
* @param CachedConfigReader $config
* @param string $pluginDir
* @param array $pluginConfig
*/
public function __construct($pluginDir, $pluginName, CachedConfigReader $config)
public function __construct(string $pluginDir, array $pluginConfig)
{
$this->pluginDir = $pluginDir;
$this->pluginName = $pluginName;
$this->config = $config->getByPluginName($pluginName);
$this->pluginConfig = $pluginConfig;
}

/**
Expand Down Expand Up @@ -66,7 +58,6 @@ public function onAddJavascriptFiles()
{
$jsFiles = [
$this->prepareJavaScript(),
$this->pluginDir . '/vendor/lazysizes/lazysizes.min.js',
];

return new ArrayCollection($jsFiles);
Expand All @@ -77,9 +68,9 @@ public function onAddJavascriptFiles()
*/
public function prepareJavaScript()
{
$filename = $this->pluginDir . '/Resources/views/frontend/_public/src/js/lazySizesConfig.js';
$filename = $this->pluginDir . '/Resources/frontend/js/lazySizesConfig.js';

file_put_contents($filename, $this->config['lazySizesConfig']);
file_put_contents($filename, $this->pluginConfig['lazySizesConfig']);

return $filename;
}
Expand Down

0 comments on commit e200416

Please sign in to comment.