Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 782bc0e

Browse files
author
Joan He
authored
Merge pull request #2416 from magento-borg/pr
[Borg] PHP-7.2-Support PR
2 parents 6a69901 + 31780d9 commit 782bc0e

File tree

9 files changed

+456
-106
lines changed

9 files changed

+456
-106
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"zendframework/zend-log": "^2.9.1",
6868
"zendframework/zend-mail": "^2.9.0",
6969
"zendframework/zend-modulemanager": "^2.7",
70-
"zendframework/zend-mvc": "~2.6.3",
70+
"zendframework/zend-mvc": "~2.7.0",
7171
"zendframework/zend-serializer": "^2.7.2",
7272
"zendframework/zend-server": "^2.6.1",
7373
"zendframework/zend-servicemanager": "^2.7.8",
@@ -273,7 +273,8 @@
273273
"psr-4": {
274274
"Magento\\Framework\\": "lib/internal/Magento/Framework/",
275275
"Magento\\Setup\\": "setup/src/Magento/Setup/",
276-
"Magento\\": "app/code/Magento/"
276+
"Magento\\": "app/code/Magento/",
277+
"Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/"
277278
},
278279
"psr-0": {
279280
"": [

composer.lock

Lines changed: 219 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/static/testsuite/Magento/Test/Legacy/_files/copyright/blacklist.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
return [
77
'/\.(jpe?g|png|gif|ttf|swf|eot|woff|pdf|mp3|pdf|jar|jbf|php\.dist)$/',
88
'/pub\/opt\/magento\/var/',
9-
'/COPYING\.txt/'
9+
'/COPYING\.txt/',
10+
'/setup\/src\/Zend\/Mvc\/Controller\/LazyControllerAbstractFactory\.php/'
1011
];

lib/internal/Magento/Framework/Amqp/TopologyInstaller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function install()
9292
$amqpConfig = $this->configPool->get($exchange->getConnection());
9393
$this->exchangeInstaller->install($amqpConfig->getChannel(), $exchange);
9494
}
95-
} catch (\PhpAmqpLib\Exception\AMQPExceptionInterface $e) {
95+
} catch (\Exception $e) {
9696
$this->logger->error("AMQP topology installation failed: {$e->getMessage()}\n{$e->getTraceAsString()}");
9797
}
9898
}

lib/internal/Magento/Framework/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"zendframework/zend-code": "~3.3.0",
3333
"zendframework/zend-crypt": "^2.6.0",
3434
"zendframework/zend-http": "^2.6.0",
35-
"zendframework/zend-mvc": "~2.6.3",
35+
"zendframework/zend-mvc": "~2.7.0",
3636
"zendframework/zend-stdlib": "^2.7.7",
3737
"zendframework/zend-uri": "^2.5.1",
3838
"zendframework/zend-validator": "^2.6.0"

setup/config/di.config.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,6 @@
66

77
return [
88
'di' => [
9-
'allowed_controllers' => [
10-
\Magento\Setup\Controller\Index::class,
11-
\Magento\Setup\Controller\LandingInstaller::class,
12-
\Magento\Setup\Controller\LandingUpdater::class,
13-
\Magento\Setup\Controller\CreateBackup::class,
14-
\Magento\Setup\Controller\CompleteBackup::class,
15-
\Magento\Setup\Controller\Navigation::class,
16-
\Magento\Setup\Controller\Home::class,
17-
\Magento\Setup\Controller\SelectVersion::class,
18-
\Magento\Setup\Controller\License::class,
19-
\Magento\Setup\Controller\ReadinessCheckInstaller::class,
20-
\Magento\Setup\Controller\ReadinessCheckUpdater::class,
21-
\Magento\Setup\Controller\Environment::class,
22-
\Magento\Setup\Controller\DependencyCheck::class,
23-
\Magento\Setup\Controller\DatabaseCheck::class,
24-
\Magento\Setup\Controller\UrlCheck::class,
25-
\Magento\Setup\Controller\ValidateAdminCredentials::class,
26-
\Magento\Setup\Controller\AddDatabase::class,
27-
\Magento\Setup\Controller\WebConfiguration::class,
28-
\Magento\Setup\Controller\CustomizeYourStore::class,
29-
\Magento\Setup\Controller\CreateAdminAccount::class,
30-
\Magento\Setup\Controller\Install::class,
31-
\Magento\Setup\Controller\Success::class,
32-
\Magento\Setup\Controller\Modules::class,
33-
\Magento\Setup\Controller\ModuleGrid::class,
34-
\Magento\Setup\Controller\ExtensionGrid::class,
35-
\Magento\Setup\Controller\StartUpdater::class,
36-
\Magento\Setup\Controller\UpdaterSuccess::class,
37-
\Magento\Setup\Controller\BackupActionItems::class,
38-
\Magento\Setup\Controller\Maintenance::class,
39-
\Magento\Setup\Controller\OtherComponentsGrid::class,
40-
\Magento\Setup\Controller\DataOption::class,
41-
\Magento\Setup\Controller\Marketplace::class,
42-
\Magento\Setup\Controller\SystemConfig::class,
43-
\Magento\Setup\Controller\InstallExtensionGrid::class,
44-
\Magento\Setup\Controller\UpdateExtensionGrid::class,
45-
\Magento\Setup\Controller\MarketplaceCredentials::class,
46-
\Magento\Setup\Controller\Session::class,
47-
],
489
'instance' => [
4910
'preference' => [
5011
\Zend\EventManager\EventManagerInterface::class => 'EventManager',

setup/config/module.config.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@
3434
'aliases' => [
3535
'translator' => 'MvcTranslator'
3636
]
37-
]
37+
],
38+
'controllers' => [
39+
'abstract_factories' => [
40+
\Zend\Mvc\Controller\LazyControllerAbstractFactory::class,
41+
],
42+
],
3843
];

setup/src/Magento/Setup/Application.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ public function bootstrap(array $configuration)
4040
}
4141

4242
$listeners = $this->getListeners($serviceManager, $configuration);
43-
$application = new ZendApplication($configuration, $serviceManager);
43+
$application = new ZendApplication(
44+
$configuration,
45+
$serviceManager,
46+
$serviceManager->get('EventManager'),
47+
$serviceManager->get('Request'),
48+
$serviceManager->get('Response')
49+
);
4450
$application->bootstrap($listeners);
4551
return $application;
4652
}
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-mvc for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License
6+
* @SuppressWarnings(PHPMD)
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace Zend\Mvc\Controller;
12+
13+
use Interop\Container\ContainerInterface;
14+
use ReflectionClass;
15+
use ReflectionParameter;
16+
use Zend\Console\Adapter\AdapterInterface as ConsoleAdapterInterface;
17+
use Zend\Filter\FilterPluginManager;
18+
use Zend\Hydrator\HydratorPluginManager;
19+
use Zend\InputFilter\InputFilterPluginManager;
20+
use Zend\Log\FilterPluginManager as LogFilterManager;
21+
use Zend\Log\FormatterPluginManager as LogFormatterManager;
22+
use Zend\Log\ProcessorPluginManager as LogProcessorManager;
23+
use Zend\Log\WriterPluginManager as LogWriterManager;
24+
use Zend\Serializer\AdapterPluginManager as SerializerAdapterManager;
25+
use Zend\ServiceManager\AbstractFactoryInterface;
26+
use Zend\ServiceManager\Exception\ServiceNotFoundException;
27+
use Zend\ServiceManager\ServiceLocatorInterface;
28+
use Zend\Stdlib\DispatchableInterface;
29+
use Zend\Validator\ValidatorPluginManager;
30+
31+
/**
32+
* Reflection-based factory for controllers.
33+
*
34+
* To ease development, this factory may be used for controllers with
35+
* type-hinted arguments that resolve to services in the application
36+
* container; this allows omitting the step of writing a factory for
37+
* each controller.
38+
*
39+
* You may use it as either an abstract factory:
40+
*
41+
* <code>
42+
* 'controllers' => [
43+
* 'abstract_factories' => [
44+
* LazyControllerAbstractFactory::class,
45+
* ],
46+
* ],
47+
* </code>
48+
*
49+
* Or as a factory, mapping a controller class name to it:
50+
*
51+
* <code>
52+
* 'controllers' => [
53+
* 'factories' => [
54+
* MyControllerWithDependencies::class => LazyControllerAbstractFactory::class,
55+
* ],
56+
* ],
57+
* </code>
58+
*
59+
* The latter approach is more explicit, and also more performant.
60+
*
61+
* The factory has the following constraints/features:
62+
*
63+
* - A parameter named `$config` typehinted as an array will receive the
64+
* application "config" service (i.e., the merged configuration).
65+
* - Parameters type-hinted against array, but not named `$config` will
66+
* be injected with an empty array.
67+
* - Scalar parameters will be resolved as null values.
68+
* - If a service cannot be found for a given typehint, the factory will
69+
* raise an exception detailing this.
70+
* - Some services provided by Zend Framework components do not have
71+
* entries based on their class name (for historical reasons); the
72+
* factory contains a map of these class/interface names to the
73+
* corresponding service name to allow them to resolve.
74+
*
75+
* `$options` passed to the factory are ignored in all cases, as we cannot
76+
* make assumptions about which argument(s) they might replace.
77+
*/
78+
class LazyControllerAbstractFactory implements AbstractFactoryInterface
79+
{
80+
/**
81+
* Maps known classes/interfaces to the service that provides them; only
82+
* required for those services with no entry based on the class/interface
83+
* name.
84+
*
85+
* Extend the class if you wish to add to the list.
86+
*
87+
* @var string[]
88+
*/
89+
protected $aliases = [
90+
ConsoleAdapterInterface::class => 'ConsoleAdapter',
91+
FilterPluginManager::class => 'FilterManager',
92+
HydratorPluginManager::class => 'HydratorManager',
93+
InputFilterPluginManager::class => 'InputFilterManager',
94+
LogFilterManager::class => 'LogFilterManager',
95+
LogFormatterManager::class => 'LogFormatterManager',
96+
LogProcessorManager::class => 'LogProcessorManager',
97+
LogWriterManager::class => 'LogWriterManager',
98+
SerializerAdapterManager::class => 'SerializerAdapterManager',
99+
ValidatorPluginManager::class => 'ValidatorManager',
100+
];
101+
102+
/**
103+
* {@inheritDoc}
104+
*
105+
* @return DispatchableInterface
106+
*/
107+
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
108+
{
109+
$reflectionClass = new ReflectionClass($requestedName);
110+
111+
if (null === ($constructor = $reflectionClass->getConstructor())) {
112+
return new $requestedName();
113+
}
114+
115+
$reflectionParameters = $constructor->getParameters();
116+
117+
if (empty($reflectionParameters)) {
118+
return new $requestedName();
119+
}
120+
121+
$parameters = array_map(
122+
$this->resolveParameter($container->getServiceLocator(), $requestedName),
123+
$reflectionParameters
124+
);
125+
126+
return new $requestedName(...$parameters);
127+
}
128+
129+
/**
130+
* {@inheritDoc}
131+
*/
132+
public function canCreate(ContainerInterface $container, $requestedName)
133+
{
134+
if (! class_exists($requestedName)) {
135+
return false;
136+
}
137+
138+
return in_array(DispatchableInterface::class, class_implements($requestedName), true);
139+
}
140+
141+
/**
142+
* Resolve a parameter to a value.
143+
*
144+
* Returns a callback for resolving a parameter to a value.
145+
*
146+
* @param ContainerInterface $container
147+
* @param string $requestedName
148+
* @return callable
149+
*/
150+
private function resolveParameter(ContainerInterface $container, $requestedName)
151+
{
152+
/**
153+
* @param ReflectionClass $parameter
154+
* @return mixed
155+
* @throws ServiceNotFoundException If type-hinted parameter cannot be
156+
* resolved to a service in the container.
157+
*/
158+
return function (ReflectionParameter $parameter) use ($container, $requestedName) {
159+
if ($parameter->isArray()
160+
&& $parameter->getName() === 'config'
161+
&& $container->has('config')
162+
) {
163+
return $container->get('config');
164+
}
165+
166+
if ($parameter->isArray()) {
167+
return [];
168+
}
169+
170+
if (! $parameter->getClass()) {
171+
return;
172+
}
173+
174+
$type = $parameter->getClass()->getName();
175+
$type = isset($this->aliases[$type]) ? $this->aliases[$type] : $type;
176+
177+
if (! $container->has($type)) {
178+
throw new ServiceNotFoundException(sprintf(
179+
'Unable to create controller "%s"; unable to resolve parameter "%s" using type hint "%s"',
180+
$requestedName,
181+
$parameter->getName(),
182+
$type
183+
));
184+
}
185+
186+
return $container->get($type);
187+
};
188+
}
189+
190+
/**
191+
* Determine if we can create a service with name
192+
*
193+
* @param ServiceLocatorInterface $serviceLocator
194+
* @param $name
195+
* @param $requestedName
196+
* @return bool
197+
* @SuppressWarnings("unused")
198+
*/
199+
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
200+
{
201+
return $this->canCreate($serviceLocator, $requestedName);
202+
}
203+
204+
/**
205+
* Create service with name
206+
*
207+
* @param ServiceLocatorInterface $serviceLocator
208+
* @param $name
209+
* @param $requestedName
210+
* @return mixed
211+
* @SuppressWarnings("unused")
212+
*/
213+
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
214+
{
215+
return $this($serviceLocator, $requestedName);
216+
}
217+
}

0 commit comments

Comments
 (0)