Skip to content

Commit 4a70e04

Browse files
author
Dmytro Poperechnyy
committed
MAGETWO-33060: Refactor __() to return Phrase object
1 parent 8892e7b commit 4a70e04

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

app/code/Magento/Payment/Block/Info/Cc.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ protected function _prepareSpecificInformation($transport = null)
9797
$transport = parent::_prepareSpecificInformation($transport);
9898
$data = [];
9999
if ($ccType = $this->getCcTypeName()) {
100-
$data[__('Credit Card Type')] = $ccType;
100+
$data[(string)__('Credit Card Type')] = $ccType;
101101
}
102102
if ($this->getInfo()->getCcLast4()) {
103-
$data[__('Credit Card Number')] = sprintf('xxxx-%s', $this->getInfo()->getCcLast4());
103+
$data[(string)__('Credit Card Number')] = sprintf('xxxx-%s', $this->getInfo()->getCcLast4());
104104
}
105105
if (!$this->getIsSecureMode()) {
106106
if ($ccSsIssue = $this->getInfo()->getCcSsIssue()) {
107-
$data[__('Switch/Solo/Maestro Issue Number')] = $ccSsIssue;
107+
$data[(string)__('Switch/Solo/Maestro Issue Number')] = $ccSsIssue;
108108
}
109109
$year = $this->getInfo()->getCcSsStartYear();
110110
$month = $this->getInfo()->getCcSsStartMonth();
111111
if ($year && $month) {
112-
$data[__('Switch/Solo/Maestro Start Date')] = $this->_formatCardDate($year, $month);
112+
$data[(string)__('Switch/Solo/Maestro Start Date')] = $this->_formatCardDate($year, $month);
113113
}
114114
}
115115
return $transport->setData(array_merge($data, $transport->getData()));

app/code/Magento/Store/Ui/DataProvider/Options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getOptions(array $options = [])
5353
$storeCollection = $this->systemStore->getStoreCollection();
5454

5555
$currentOptions = [
56-
__('All Store Views') => [
56+
(string)__('All Store Views') => [
5757
'label' => __('All Store Views'),
5858
'value' => 0,
5959
],

app/functions.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Create value-object \Magento\Framework\Phrase
99
*
10-
* @return string
10+
* @return \Magento\Framework\Phrase
1111
*/
1212
function __()
1313
{
@@ -18,11 +18,5 @@ function __()
1818
$argc = $argc[0];
1919
}
2020

21-
/**
22-
* Type casting to string is a workaround.
23-
* Many places in client code at the moment are unable to handle the \Magento\Framework\Phrase object properly.
24-
* The intended behavior is to use __toString(),
25-
* so that rendering of the phrase happens only at the last moment when needed
26-
*/
27-
return (string)new \Magento\Framework\Phrase($text, $argc);
21+
return new \Magento\Framework\Phrase($text, $argc);
2822
}

lib/internal/Magento/Framework/Phrase.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
namespace Magento\Framework;
99

10+
use Zend\Stdlib\JsonSerializable;
1011
use Magento\Framework\Phrase\RendererInterface;
1112

12-
class Phrase
13+
class Phrase implements JsonSerializable
1314
{
1415
/**
1516
* Default phrase renderer. Allows stacking renderers that "don't know about each other"
@@ -84,4 +85,14 @@ public function __toString()
8485
{
8586
return $this->render();
8687
}
88+
89+
/**
90+
* Specify data which should be serialized to JSON
91+
*
92+
* @return string
93+
*/
94+
public function jsonSerialize()
95+
{
96+
return $this->render();
97+
}
8798
}

0 commit comments

Comments
 (0)