Skip to content

Commit

Permalink
Use getLanguageStrings language method through MediaLibrary LanguageI…
Browse files Browse the repository at this point in the history
…nterface

Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Sep 28, 2023
1 parent e2e976f commit 178830b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 6 deletions.
2 changes: 1 addition & 1 deletion metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'extend' => [
// Core
\OxidEsales\Eshop\Core\ViewConfig::class => \OxidEsales\MediaLibrary\Core\ViewConfig::class,
\OxidEsales\Eshop\Core\Language::class => \OxidEsales\MediaLibrary\Core\Language::class,
\OxidEsales\Eshop\Core\Language::class => \OxidEsales\MediaLibrary\Transition\Core\Language::class,
\OxidEsales\Eshop\Core\Utils::class => \OxidEsales\MediaLibrary\Core\Utils::class,
],
'controllers' => [
Expand Down
1 change: 1 addition & 0 deletions services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
imports:
- { resource: src/Image/Service/services.yaml }
- { resource: src/Transition/Core/services.yaml }

services:

Expand Down
7 changes: 3 additions & 4 deletions src/Application/Controller/MediaLangJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace OxidEsales\MediaLibrary\Application\Controller;

use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Language;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\MediaLibrary\Core\Utils;
use OxidEsales\MediaLibrary\Transition\Core\LanguageInterface;

/**
* Class MediaLangJs
Expand All @@ -22,14 +22,13 @@ class MediaLangJs extends FrontendController
*/
public function init()
{
/** @var \OxidEsales\MediaLibrary\Core\Language $oLang */
$oLang = oxNew(Language::class);
$languages = $this->getService(LanguageInterface::class);

header('Content-Type: application/javascript');

/** @var Utils $oUtils */
$oUtils = Registry::getUtils();
$sJson = $oUtils->encodeJson($oLang->getLanguageStrings());
$sJson = $oUtils->encodeJson($languages->getLanguageStringsArray());
$oUtils->showMessageAndExit(";( function(g){ g.i18n = " . $sJson . "; })(window);");
}
}
4 changes: 3 additions & 1 deletion src/Core/Language.php → src/Transition/Core/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* See LICENSE file for license details.
*/

namespace OxidEsales\MediaLibrary\Core;
namespace OxidEsales\MediaLibrary\Transition\Core;

/**
* Class Language
Expand All @@ -14,6 +14,8 @@
*/
class Language extends Language_parent
{
protected $_aAdditionalLangFiles = [];

/**
* @param null|integer $iLang
* @param null|bool $blAdminMode
Expand Down
8 changes: 8 additions & 0 deletions src/Transition/Core/LanguageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace OxidEsales\MediaLibrary\Transition\Core;

interface LanguageInterface
{
public function getLanguageStringsArray(): array;
}
22 changes: 22 additions & 0 deletions src/Transition/Core/LanguageProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace OxidEsales\MediaLibrary\Transition\Core;

use OxidEsales\MediaLibrary\Core\Language;

class LanguageProxy implements LanguageInterface
{
/** @var Language $language */
private $language;

public function __construct(\OxidEsales\Eshop\Core\Language $language)
{
/** @var Language $language */
$this->language = $language;
}

public function getLanguageStringsArray(): array
{
return $this->language->getLanguageStrings();
}
}
10 changes: 10 additions & 0 deletions src/Transition/Core/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
_defaults:
public: false
autowire: true
bind:
OxidEsales\Eshop\Core\Language: '@=service("OxidEsales\\MediaLibrary\\Core\\Registry").getLang()'

OxidEsales\MediaLibrary\Transition\Core\LanguageInterface:
class: OxidEsales\MediaLibrary\Transition\Core\LanguageProxy
public: true
30 changes: 30 additions & 0 deletions tests/Integration/Transition/Core/LanguageProxyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\MediaLibrary\Tests\Integration\Transition\Core;

use OxidEsales\MediaLibrary\Transition\Core\Language;
use OxidEsales\MediaLibrary\Transition\Core\LanguageProxy;
use PHPUnit\Framework\TestCase;

class LanguageProxyTest extends TestCase
{
public function testGetLanguageStrings(): void
{
$languageStringsList = ['somekey' => 'someValue'];

/** @var \OxidEsales\Eshop\Core\Language $languageMock */
$languageMock = $this->createPartialMock(Language::class, ['getLanguageStrings']);
$languageMock->method('getLanguageStrings')->willReturn($languageStringsList);

$sut = new LanguageProxy($languageMock);

$this->assertSame($languageStringsList, $sut->getLanguageStringsArray());
}
}

0 comments on commit 178830b

Please sign in to comment.