Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T15902 nativearray #15968

Merged
merged 2 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
- `Phalcon\Html\Link\Interfaces\LinkProviderInterface`
- `Phalcon\Html\Link\AbstractLink`
- `Phalcon\Html\Link\AbstractLinkProvider` to be used in the link class but also the proxy-psr13 repo [#15930](https://github.com/phalcon/cphalcon/issues/15930)

- Added `Phalcon\Translate\Adapter\Csv::toArray()` and `Phalcon\Translate\Adapter\NativeArray::toArray()` to return the translation array back [#15902](https://github.com/phalcon/cphalcon/issues/15902)
-
## Removed
- Removed `Phalcon\Container\Container` and moved its contents to the `proxy-psr11` repo [#15928](https://github.com/phalcon/cphalcon/issues/15928)
- Removed `Phalcon\Http\Message\*` and `Phalcon\Http\Server\*` classes. This removes PSR from Phalcon. PSR-7 available in v6 [#15929](https://github.com/phalcon/cphalcon/issues/15929)
Expand Down
10 changes: 10 additions & 0 deletions phalcon/Translate/Adapter/Csv.zep
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ class Csv extends AbstractAdapter implements ArrayAccess
fclose(fileHandler);
}

/**
* Returns the internal array
*
* @return array
*/
public function toArray() -> array
{
return this->translate;
}

/**
* @todo to be removed when we get traits
*/
Expand Down
10 changes: 10 additions & 0 deletions phalcon/Translate/Adapter/NativeArray.zep
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,14 @@ class NativeArray extends AbstractAdapter implements ArrayAccess

return this->replacePlaceholders(translation, placeholders);
}

/**
* Returns the internal array
*
* @return array
*/
public function toArray() -> array
{
return this->translate;
}
}
49 changes: 49 additions & 0 deletions tests/unit/Translate/Adapter/Csv/ToArrayCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Tests\Unit\Translate\Adapter\Csv;

use Phalcon\Tests\Fixtures\Traits\TranslateCsvTrait;
use Phalcon\Translate\Adapter\Csv;
use Phalcon\Translate\InterpolatorFactory;
use UnitTester;

class ToArrayCest
{
use TranslateCsvTrait;

/**
* Tests Phalcon\Translate\Adapter\Csv :: toArray()
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2020-09-09
*/
public function translateAdapterCsvToArray(UnitTester $I)
{
$I->wantToTest('Translate\Adapter\Csv - toArray()');

$language = $this->getCsvConfig()['en'];
$translator = new Csv(new InterpolatorFactory(), $language);

$expected = [
'hi' => 'Hello',
'bye' => 'Good Bye',
'hello-key' => 'Hello %name%',
'song-key' => 'This song is %song% (%artist%)',
];
$actual = $translator->toArray();
$I->assertSame($expected, $actual);
}
}
50 changes: 50 additions & 0 deletions tests/unit/Translate/Adapter/NativeArray/ToArrayCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Tests\Unit\Translate\Adapter\NativeArray;

use Phalcon\Tests\Fixtures\Traits\TranslateNativeArrayTrait;
use Phalcon\Translate\Adapter\NativeArray;
use Phalcon\Translate\InterpolatorFactory;
use UnitTester;

class ToArrayCest
{
use TranslateNativeArrayTrait;

/**
* Tests Phalcon\Translate\Adapter\NativeArray :: toArray()
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2020-09-09
*/
public function translateAdapterNativeToArray(UnitTester $I)
{
$I->wantToTest('Translate\Adapter\NativeArray - toArray()');

$language = $this->getArrayConfig()['en'];

$translator = new NativeArray(
new InterpolatorFactory(),
[
'content' => $language,
]
);

$expected = $language;
$actual = $translator->toArray();
$I->assertSame($expected, $actual);
}
}