Skip to content

Commit

Permalink
added missing dependency (fixed #4), some code enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Jan 21, 2021
1 parent 6878624 commit 01831d1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.9.2] - 2021-01-21
- added missing multi-column-editor dependency (see #4)
- small code enhancements

## [1.9.1] - 2020-03-09
- fixed an error with esi tags appeared only in some circumstances

Expand Down
12 changes: 2 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"php": "^7.1",
"contao/core-bundle": "^4.4",
"wa72/htmlpagedom": "^1.3",
"heimrichhannot/contao-multi-column-editor-bundle": "^2.0",
"heimrichhannot/contao-utils-bundle": "^2.16",
"vanderlee/syllable": "^1.5"
},
Expand All @@ -41,16 +42,7 @@
"autoload": {
"psr-4": {
"HeimrichHannot\\HyphenatorBundle\\": "src/"
},
"classmap": [
"src/"
],
"exclude-from-classmap": [
"src/Resources/contao/config/",
"src/Resources/contao/dca/",
"src/Resources/contao/languages/",
"src/Resources/contao/templates/"
]
}
},
"autoload-dev": {
"psr-4": {
Expand Down
3 changes: 1 addition & 2 deletions src/DependencyInjection/HyphenatorExtension.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2020 Heimrich & Hannot GmbH
* Copyright (c) 2021 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand All @@ -22,7 +22,6 @@ public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));

$loader->load('listener.yml');
$loader->load('services.yml');
}
}
15 changes: 7 additions & 8 deletions src/EventListener/FrontendPageListener.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<?php

/*
* Copyright (c) 2020 Heimrich & Hannot GmbH
* Copyright (c) 2021 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/

namespace HeimrichHannot\HyphenatorBundle\EventListener;

use Contao\System;
use Symfony\Component\DependencyInjection\ContainerInterface;
use HeimrichHannot\HyphenatorBundle\Hyphenator\FrontendHyphenator;

class FrontendPageListener
{
/**
* @var ContainerInterface
* @var FrontendHyphenator
*/
private $container;
protected $frontendHyphenator;

/**
* Request constructor.
*/
public function __construct(ContainerInterface $container)
public function __construct(FrontendHyphenator $frontendHyphenator)
{
$this->container = $container;
$this->frontendHyphenator = $frontendHyphenator;
}

/**
Expand All @@ -36,6 +35,6 @@ public function __construct(ContainerInterface $container)
*/
public function modifyFrontendPage($strBuffer, $strTemplate)
{
return System::getContainer()->get('huh.hyphenator.frontend')->hyphenate($strBuffer);
return $this->frontendHyphenator->hyphenate($strBuffer);
}
}
5 changes: 0 additions & 5 deletions src/Resources/config/listener.yml

This file was deleted.

9 changes: 8 additions & 1 deletion src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
services:

huh.hyphenator.frontend:
class: HeimrichHannot\HyphenatorBundle\Hyphenator\FrontendHyphenator
public: true
autowire: true
autowire: true
HeimrichHannot\HyphenatorBundle\Hyphenator\FrontendHyphenator: "@huh.hyphenator.frontend"

huh.hyphenator.frontendPageListener:
class: HeimrichHannot\HyphenatorBundle\EventListener\FrontendPageListener
public: true
autowire: true
20 changes: 6 additions & 14 deletions tests/EventListener/FrontendPageListenerTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

/*
* Copyright (c) 2020 Heimrich & Hannot GmbH
* Copyright (c) 2021 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/

namespace HeimrichHannot\HyphenatorBundle\Tests\EventListener;

use Contao\System;
use Contao\TestCase\ContaoTestCase;
use HeimrichHannot\HyphenatorBundle\EventListener\FrontendPageListener;
use HeimrichHannot\HyphenatorBundle\Hyphenator\FrontendHyphenator;
Expand Down Expand Up @@ -36,7 +35,7 @@ protected function setUp()
*/
public function testCanBeInstantiated()
{
$listener = new FrontendPageListener($this->container);
$listener = new FrontendPageListener($this->createMock(FrontendHyphenator::class));

$this->assertInstanceOf(FrontendPageListener::class, $listener);
}
Expand All @@ -46,17 +45,10 @@ public function testCanBeInstantiated()
*/
public function testModifyFrontendPage()
{
$container = $this->mockContainer();
$container->set('huh.hyphenator.frontend', new FrontendHyphenator($this->container));
$hypenatorMock = $this->createMock(FrontendHyphenator::class);
$hypenatorMock->method('hyphenate')->willReturn('hyphenated text');

System::setContainer($container);

$pageData = ['language' => 'de'];

global $objPage;
$objPage = (object) $pageData;

$listener = new FrontendPageListener($this->container);
$this->assertSame('test', $listener->modifyFrontendPage('test', 'fe_page'));
$listener = new FrontendPageListener($hypenatorMock);
$this->assertSame('hyphenated text', $listener->modifyFrontendPage('test', 'fe_page'));
}
}

0 comments on commit 01831d1

Please sign in to comment.