Skip to content

Commit

Permalink
Merge pull request #2416 from magento-borg/pr
Browse files Browse the repository at this point in the history
[Borg] PHP-7.2-Support PR
  • Loading branch information
Joan He authored Apr 21, 2018
2 parents 6a69901 + 31780d9 commit 782bc0e
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 106 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"zendframework/zend-log": "^2.9.1",
"zendframework/zend-mail": "^2.9.0",
"zendframework/zend-modulemanager": "^2.7",
"zendframework/zend-mvc": "~2.6.3",
"zendframework/zend-mvc": "~2.7.0",
"zendframework/zend-serializer": "^2.7.2",
"zendframework/zend-server": "^2.6.1",
"zendframework/zend-servicemanager": "^2.7.8",
Expand Down Expand Up @@ -273,7 +273,8 @@
"psr-4": {
"Magento\\Framework\\": "lib/internal/Magento/Framework/",
"Magento\\Setup\\": "setup/src/Magento/Setup/",
"Magento\\": "app/code/Magento/"
"Magento\\": "app/code/Magento/",
"Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/"
},
"psr-0": {
"": [
Expand Down
279 changes: 219 additions & 60 deletions composer.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
return [
'/\.(jpe?g|png|gif|ttf|swf|eot|woff|pdf|mp3|pdf|jar|jbf|php\.dist)$/',
'/pub\/opt\/magento\/var/',
'/COPYING\.txt/'
'/COPYING\.txt/',
'/setup\/src\/Zend\/Mvc\/Controller\/LazyControllerAbstractFactory\.php/'
];
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Amqp/TopologyInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function install()
$amqpConfig = $this->configPool->get($exchange->getConnection());
$this->exchangeInstaller->install($amqpConfig->getChannel(), $exchange);
}
} catch (\PhpAmqpLib\Exception\AMQPExceptionInterface $e) {
} catch (\Exception $e) {
$this->logger->error("AMQP topology installation failed: {$e->getMessage()}\n{$e->getTraceAsString()}");
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"zendframework/zend-code": "~3.3.0",
"zendframework/zend-crypt": "^2.6.0",
"zendframework/zend-http": "^2.6.0",
"zendframework/zend-mvc": "~2.6.3",
"zendframework/zend-mvc": "~2.7.0",
"zendframework/zend-stdlib": "^2.7.7",
"zendframework/zend-uri": "^2.5.1",
"zendframework/zend-validator": "^2.6.0"
Expand Down
39 changes: 0 additions & 39 deletions setup/config/di.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,6 @@

return [
'di' => [
'allowed_controllers' => [
\Magento\Setup\Controller\Index::class,
\Magento\Setup\Controller\LandingInstaller::class,
\Magento\Setup\Controller\LandingUpdater::class,
\Magento\Setup\Controller\CreateBackup::class,
\Magento\Setup\Controller\CompleteBackup::class,
\Magento\Setup\Controller\Navigation::class,
\Magento\Setup\Controller\Home::class,
\Magento\Setup\Controller\SelectVersion::class,
\Magento\Setup\Controller\License::class,
\Magento\Setup\Controller\ReadinessCheckInstaller::class,
\Magento\Setup\Controller\ReadinessCheckUpdater::class,
\Magento\Setup\Controller\Environment::class,
\Magento\Setup\Controller\DependencyCheck::class,
\Magento\Setup\Controller\DatabaseCheck::class,
\Magento\Setup\Controller\UrlCheck::class,
\Magento\Setup\Controller\ValidateAdminCredentials::class,
\Magento\Setup\Controller\AddDatabase::class,
\Magento\Setup\Controller\WebConfiguration::class,
\Magento\Setup\Controller\CustomizeYourStore::class,
\Magento\Setup\Controller\CreateAdminAccount::class,
\Magento\Setup\Controller\Install::class,
\Magento\Setup\Controller\Success::class,
\Magento\Setup\Controller\Modules::class,
\Magento\Setup\Controller\ModuleGrid::class,
\Magento\Setup\Controller\ExtensionGrid::class,
\Magento\Setup\Controller\StartUpdater::class,
\Magento\Setup\Controller\UpdaterSuccess::class,
\Magento\Setup\Controller\BackupActionItems::class,
\Magento\Setup\Controller\Maintenance::class,
\Magento\Setup\Controller\OtherComponentsGrid::class,
\Magento\Setup\Controller\DataOption::class,
\Magento\Setup\Controller\Marketplace::class,
\Magento\Setup\Controller\SystemConfig::class,
\Magento\Setup\Controller\InstallExtensionGrid::class,
\Magento\Setup\Controller\UpdateExtensionGrid::class,
\Magento\Setup\Controller\MarketplaceCredentials::class,
\Magento\Setup\Controller\Session::class,
],
'instance' => [
'preference' => [
\Zend\EventManager\EventManagerInterface::class => 'EventManager',
Expand Down
7 changes: 6 additions & 1 deletion setup/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@
'aliases' => [
'translator' => 'MvcTranslator'
]
]
],
'controllers' => [
'abstract_factories' => [
\Zend\Mvc\Controller\LazyControllerAbstractFactory::class,
],
],
];
8 changes: 7 additions & 1 deletion setup/src/Magento/Setup/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ public function bootstrap(array $configuration)
}

$listeners = $this->getListeners($serviceManager, $configuration);
$application = new ZendApplication($configuration, $serviceManager);
$application = new ZendApplication(
$configuration,
$serviceManager,
$serviceManager->get('EventManager'),
$serviceManager->get('Request'),
$serviceManager->get('Response')
);
$application->bootstrap($listeners);
return $application;
}
Expand Down
217 changes: 217 additions & 0 deletions setup/src/Zend/Mvc/Controller/LazyControllerAbstractFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
<?php
/**
* @link http://github.com/zendframework/zend-mvc for the canonical source repository
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License
* @SuppressWarnings(PHPMD)
*/

declare(strict_types=1);

namespace Zend\Mvc\Controller;

use Interop\Container\ContainerInterface;
use ReflectionClass;
use ReflectionParameter;
use Zend\Console\Adapter\AdapterInterface as ConsoleAdapterInterface;
use Zend\Filter\FilterPluginManager;
use Zend\Hydrator\HydratorPluginManager;
use Zend\InputFilter\InputFilterPluginManager;
use Zend\Log\FilterPluginManager as LogFilterManager;
use Zend\Log\FormatterPluginManager as LogFormatterManager;
use Zend\Log\ProcessorPluginManager as LogProcessorManager;
use Zend\Log\WriterPluginManager as LogWriterManager;
use Zend\Serializer\AdapterPluginManager as SerializerAdapterManager;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\DispatchableInterface;
use Zend\Validator\ValidatorPluginManager;

/**
* Reflection-based factory for controllers.
*
* To ease development, this factory may be used for controllers with
* type-hinted arguments that resolve to services in the application
* container; this allows omitting the step of writing a factory for
* each controller.
*
* You may use it as either an abstract factory:
*
* <code>
* 'controllers' => [
* 'abstract_factories' => [
* LazyControllerAbstractFactory::class,
* ],
* ],
* </code>
*
* Or as a factory, mapping a controller class name to it:
*
* <code>
* 'controllers' => [
* 'factories' => [
* MyControllerWithDependencies::class => LazyControllerAbstractFactory::class,
* ],
* ],
* </code>
*
* The latter approach is more explicit, and also more performant.
*
* The factory has the following constraints/features:
*
* - A parameter named `$config` typehinted as an array will receive the
* application "config" service (i.e., the merged configuration).
* - Parameters type-hinted against array, but not named `$config` will
* be injected with an empty array.
* - Scalar parameters will be resolved as null values.
* - If a service cannot be found for a given typehint, the factory will
* raise an exception detailing this.
* - Some services provided by Zend Framework components do not have
* entries based on their class name (for historical reasons); the
* factory contains a map of these class/interface names to the
* corresponding service name to allow them to resolve.
*
* `$options` passed to the factory are ignored in all cases, as we cannot
* make assumptions about which argument(s) they might replace.
*/
class LazyControllerAbstractFactory implements AbstractFactoryInterface
{
/**
* Maps known classes/interfaces to the service that provides them; only
* required for those services with no entry based on the class/interface
* name.
*
* Extend the class if you wish to add to the list.
*
* @var string[]
*/
protected $aliases = [
ConsoleAdapterInterface::class => 'ConsoleAdapter',
FilterPluginManager::class => 'FilterManager',
HydratorPluginManager::class => 'HydratorManager',
InputFilterPluginManager::class => 'InputFilterManager',
LogFilterManager::class => 'LogFilterManager',
LogFormatterManager::class => 'LogFormatterManager',
LogProcessorManager::class => 'LogProcessorManager',
LogWriterManager::class => 'LogWriterManager',
SerializerAdapterManager::class => 'SerializerAdapterManager',
ValidatorPluginManager::class => 'ValidatorManager',
];

/**
* {@inheritDoc}
*
* @return DispatchableInterface
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$reflectionClass = new ReflectionClass($requestedName);

if (null === ($constructor = $reflectionClass->getConstructor())) {
return new $requestedName();
}

$reflectionParameters = $constructor->getParameters();

if (empty($reflectionParameters)) {
return new $requestedName();
}

$parameters = array_map(
$this->resolveParameter($container->getServiceLocator(), $requestedName),
$reflectionParameters
);

return new $requestedName(...$parameters);
}

/**
* {@inheritDoc}
*/
public function canCreate(ContainerInterface $container, $requestedName)
{
if (! class_exists($requestedName)) {
return false;
}

return in_array(DispatchableInterface::class, class_implements($requestedName), true);
}

/**
* Resolve a parameter to a value.
*
* Returns a callback for resolving a parameter to a value.
*
* @param ContainerInterface $container
* @param string $requestedName
* @return callable
*/
private function resolveParameter(ContainerInterface $container, $requestedName)
{
/**
* @param ReflectionClass $parameter
* @return mixed
* @throws ServiceNotFoundException If type-hinted parameter cannot be
* resolved to a service in the container.
*/
return function (ReflectionParameter $parameter) use ($container, $requestedName) {
if ($parameter->isArray()
&& $parameter->getName() === 'config'
&& $container->has('config')
) {
return $container->get('config');
}

if ($parameter->isArray()) {
return [];
}

if (! $parameter->getClass()) {
return;
}

$type = $parameter->getClass()->getName();
$type = isset($this->aliases[$type]) ? $this->aliases[$type] : $type;

if (! $container->has($type)) {
throw new ServiceNotFoundException(sprintf(
'Unable to create controller "%s"; unable to resolve parameter "%s" using type hint "%s"',
$requestedName,
$parameter->getName(),
$type
));
}

return $container->get($type);
};
}

/**
* Determine if we can create a service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @return bool
* @SuppressWarnings("unused")
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return $this->canCreate($serviceLocator, $requestedName);
}

/**
* Create service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @return mixed
* @SuppressWarnings("unused")
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return $this($serviceLocator, $requestedName);
}
}

0 comments on commit 782bc0e

Please sign in to comment.