Skip to content

Commit fc61460

Browse files
committed
Merge branch 'patch-3' of github.com:pmzandbergen/magento2 into 2.4-develop-prs
2 parents 10818bc + 987cd9b commit fc61460

File tree

7 files changed

+180
-13
lines changed

7 files changed

+180
-13
lines changed

lib/internal/Magento/Framework/Async/Code/Generator/ProxyDeferredGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private function getReturnTypeValue(\ReflectionMethod $method): ?string
246246
$returnTypeValue = null;
247247
$returnType = $method->getReturnType();
248248
if ($returnType) {
249-
$returnTypeValue = ($returnType->allowsNull() ? '?' : '');
249+
$returnTypeValue = ($returnType->allowsNull() && $returnType->getName() !== 'mixed' ? '?' : '');
250250
$returnTypeValue .= ($returnType->getName() === 'self')
251251
? $this->_getFullyQualifiedClassName($method->getDeclaringClass()->getName())
252252
: $returnType->getName();

lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ private function extractParameterType(
352352
$typeName = $parameterType;
353353
}
354354

355-
if ($parameter->allowsNull()) {
355+
if ($parameter->allowsNull() && $typeName !== 'mixed') {
356356
$typeName = '?' . $typeName;
357357
}
358358

lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private function getReturnTypeValue(\ReflectionMethod $method): ?string
212212
$returnTypeValue = null;
213213
$returnType = $method->getReturnType();
214214
if ($returnType) {
215-
$returnTypeValue = ($returnType->allowsNull() ? '?' : '');
215+
$returnTypeValue = ($returnType->allowsNull() && $returnType->getName() !== 'mixed' ? '?' : '');
216216
$returnTypeValue .= ($returnType->getName() === 'self')
217217
? $this->_getFullyQualifiedClassName($method->getDeclaringClass()->getName())
218218
: $returnType->getName();

lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
<?php
22
/**
3-
* Proxy generator
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
86
declare(strict_types=1);
97

108
namespace Magento\Framework\ObjectManager\Code\Generator;
119

12-
/**
13-
* Class Proxy
14-
*
15-
* @package Magento\Framework\ObjectManager\Code\Generator
16-
*/
1710
class Proxy extends \Magento\Framework\Code\Generator\EntityAbstract
1811
{
1912
/**
2013
* Entity type
2114
*/
22-
const ENTITY_TYPE = 'proxy';
15+
public const ENTITY_TYPE = 'proxy';
2316

2417
/**
2518
* Marker interface
2619
*/
27-
const NON_INTERCEPTABLE_INTERFACE = \Magento\Framework\ObjectManager\NoninterceptableInterface::class;
20+
public const NON_INTERCEPTABLE_INTERFACE = \Magento\Framework\ObjectManager\NoninterceptableInterface::class;
2821

2922
/**
3023
* Returns default result class name
@@ -287,7 +280,7 @@ private function getReturnTypeValue(\ReflectionMethod $method): ?string
287280
$returnTypeValue = null;
288281
$returnType = $method->getReturnType();
289282
if ($returnType) {
290-
$returnTypeValue = ($returnType->allowsNull() ? '?' : '');
283+
$returnTypeValue = ($returnType->allowsNull() && $returnType->getName() !== 'mixed' ? '?' : '');
291284
$returnTypeValue .= ($returnType->getName() === 'self')
292285
? $this->_getFullyQualifiedClassName($method->getDeclaringClass()->getName())
293286
: $returnType->getName();

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/ProxyTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
class ProxyTest extends TestCase
1717
{
18+
private const MIXED_TYPE_PHP_VERSION = '8.0.0';
19+
1820
/**
1921
* @var MockObject
2022
*/
@@ -52,4 +54,36 @@ public function testGenerate()
5254
$model->expects($this->once())->method('_validateData')->willReturn(true);
5355
$this->assertEquals('sample_file.php', $model->generate());
5456
}
57+
58+
public function testGenerateMixedType()
59+
{
60+
if (version_compare(PHP_VERSION, self::MIXED_TYPE_PHP_VERSION) < 0) {
61+
$this->markTestSkipped('This test requires at least PHP version ' . self::MIXED_TYPE_PHP_VERSION);
62+
}
63+
64+
require_once __DIR__ . '/_files/SampleMixed.php';
65+
$model = $this->getMockBuilder(Proxy::class)
66+
->setMethods(['_validateData'])
67+
->setConstructorArgs(
68+
[
69+
\Magento\Framework\ObjectManager\Code\Generator\SampleMixed::class,
70+
null,
71+
$this->ioObjectMock,
72+
null,
73+
null,
74+
$this->createMock(FileResolver::class)
75+
]
76+
)
77+
->getMock();
78+
$sampleMixedProxyCode = file_get_contents(__DIR__ . '/_files/SampleMixedProxy.txt');
79+
80+
$this->ioObjectMock->expects($this->once())->method('generateResultFileName')
81+
->with('\\' . \Magento\Framework\ObjectManager\Code\Generator\SampleMixed_Proxy::class)
82+
->willReturn('sample_mixed_file.php');
83+
$this->ioObjectMock->expects($this->once())->method('writeResultFile')
84+
->with('sample_mixed_file.php', $sampleMixedProxyCode);
85+
86+
$model->expects($this->once())->method('_validateData')->willReturn(true);
87+
$this->assertEquals('sample_mixed_file.php', $model->generate());
88+
}
5589
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\ObjectManager\Code\Generator;
9+
10+
/**
11+
* Class SampleMixed for Proxy and Factory generation with mixed type
12+
*/
13+
class SampleMixed
14+
{
15+
/**
16+
* @var mixed
17+
*/
18+
protected mixed $mixed = null;
19+
20+
/**
21+
* @param mixed $mixed
22+
* @return void
23+
*/
24+
public function setMixed(mixed $mixed = null): void
25+
{
26+
$this->mixed = $mixed;
27+
}
28+
29+
/**
30+
* @return mixed
31+
*/
32+
public function getMixed(): mixed
33+
{
34+
return $this->mixed;
35+
}
36+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
namespace Magento\Framework\ObjectManager\Code\Generator;
2+
3+
/**
4+
* Proxy class for @see \Magento\Framework\ObjectManager\Code\Generator\SampleMixed
5+
*/
6+
class SampleMixed_Proxy extends SampleMixed implements \Magento\Framework\ObjectManager\NoninterceptableInterface
7+
{
8+
/**
9+
* Object Manager instance
10+
*
11+
* @var \Magento\Framework\ObjectManagerInterface
12+
*/
13+
protected $_objectManager = null;
14+
15+
/**
16+
* Proxied instance name
17+
*
18+
* @var string
19+
*/
20+
protected $_instanceName = null;
21+
22+
/**
23+
* Proxied instance
24+
*
25+
* @var \Magento\Framework\ObjectManager\Code\Generator\SampleMixed
26+
*/
27+
protected $_subject = null;
28+
29+
/**
30+
* Instance shareability flag
31+
*
32+
* @var bool
33+
*/
34+
protected $_isShared = null;
35+
36+
/**
37+
* Proxy constructor
38+
*
39+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
40+
* @param string $instanceName
41+
* @param bool $shared
42+
*/
43+
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = '\\Magento\\Framework\\ObjectManager\\Code\\Generator\\SampleMixed', $shared = true)
44+
{
45+
$this->_objectManager = $objectManager;
46+
$this->_instanceName = $instanceName;
47+
$this->_isShared = $shared;
48+
}
49+
50+
/**
51+
* @return array
52+
*/
53+
public function __sleep()
54+
{
55+
return ['_subject', '_isShared', '_instanceName'];
56+
}
57+
58+
/**
59+
* Retrieve ObjectManager from global scope
60+
*/
61+
public function __wakeup()
62+
{
63+
$this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
64+
}
65+
66+
/**
67+
* Clone proxied instance
68+
*/
69+
public function __clone()
70+
{
71+
$this->_subject = clone $this->_getSubject();
72+
}
73+
74+
/**
75+
* Get proxied instance
76+
*
77+
* @return \Magento\Framework\ObjectManager\Code\Generator\SampleMixed
78+
*/
79+
protected function _getSubject()
80+
{
81+
if (!$this->_subject) {
82+
$this->_subject = true === $this->_isShared
83+
? $this->_objectManager->get($this->_instanceName)
84+
: $this->_objectManager->create($this->_instanceName);
85+
}
86+
return $this->_subject;
87+
}
88+
89+
/**
90+
* {@inheritdoc}
91+
*/
92+
public function setMixed(mixed $mixed = null) : void
93+
{
94+
$this->_getSubject()->setMixed($mixed);
95+
}
96+
97+
/**
98+
* {@inheritdoc}
99+
*/
100+
public function getMixed() : mixed
101+
{
102+
return $this->_getSubject()->getMixed();
103+
}
104+
}

0 commit comments

Comments
 (0)