8 use Interop\Container\ContainerInterface;
9 use Interop\Container\Exception\ContainerException;
16 use Zend\Console\Request;
17 use Zend\EventManager\EventManagerInterface;
18 use Zend\EventManager\ListenerAggregateInterface;
19 use Zend\Mvc\Application;
20 use Zend\Mvc\MvcEvent;
21 use Zend\Router\Http\RouteMatch;
22 use Zend\ServiceManager\Exception\ServiceNotCreatedException;
23 use Zend\ServiceManager\Exception\ServiceNotFoundException;
24 use Zend\ServiceManager\FactoryInterface;
25 use Zend\ServiceManager\ServiceLocatorInterface;
26 use Zend\Stdlib\RequestInterface;
43 private $listeners = [];
50 private $controllersToSkip = [
51 \Magento\Setup\Controller\Session::class => [
'index',
'unlogin'],
52 \Magento\Setup\Controller\Success::class => [
'index']
62 public function attach(EventManagerInterface $events, $priority = 1)
64 $sharedEvents = $events->getSharedManager();
65 $this->listeners[] = $sharedEvents->attach(
67 MvcEvent::EVENT_BOOTSTRAP,
68 [$this,
'onBootstrap'],
76 public function detach(EventManagerInterface $events)
78 foreach ($this->listeners as
$index => $listener) {
79 if ($events->detach($listener)) {
80 unset($this->listeners[
$index]);
91 public function onBootstrap(MvcEvent $e)
95 $initParams =
$application->getServiceManager()->get(self::BOOTSTRAP_PARAM);
98 $serviceManager->setService(\
Magento\Framework\
App\
Filesystem\DirectoryList::class, $directoryList);
103 $eventManager->attach(MvcEvent::EVENT_DISPATCH, [$this,
'authPreDispatch'], 100);
114 public function authPreDispatch($event)
117 $routeMatch = $event->getRouteMatch();
119 $action = $routeMatch->getParam(
'action');
121 $skipCheck = array_key_exists(
$controller, $this->controllersToSkip)
122 && in_array($action, $this->controllersToSkip[
$controller]);
129 if ($serviceManager->get(\
Magento\Framework\
App\DeploymentConfig::class)->isAvailable()) {
131 $objectManagerProvider = $serviceManager->get(\
Magento\Setup\Model\ObjectManagerProvider::class);
136 $adminAppState->setAreaCode(\
Magento\Framework\
App\Area::AREA_ADMINHTML);
140 $sessionConfig->setCookiePath($cookiePath);
143 \
Magento\Backend\Model\Auth\Session::class,
145 'sessionConfig' => $sessionConfig,
146 'appState' => $adminAppState
152 if (!$authentication->isLoggedIn() ||
153 !$adminSession->isAllowed(
'Magento_Backend::setup_wizard')
155 $adminSession->destroy();
159 $response->getHeaders()->addHeaderLine(
'Location', $baseUrl .
'index.php/session/unlogin');
161 $event->stopPropagation();
181 $backendApp = $backendAppList->getBackendApp(
'setup');
184 $baseUrl = parse_url(
$url->getBaseUrl(), PHP_URL_PATH);
186 $cookiePath = $baseUrl . $backendApp->getCookiePath();
195 return $this->extractInitParameters($serviceLocator->get(
'Application'));
209 private function extractInitParameters(Application
$application)
213 if (isset(
$config[self::BOOTSTRAP_PARAM])) {
216 foreach ([
State::PARAM_MODE, AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] as $initKey) {
217 if (isset($_SERVER[$initKey])) {
218 $result[$initKey] = $_SERVER[$initKey];
233 private function extractFromCli(RequestInterface
$request)
235 if (!(
$request instanceof Request)) {
238 $bootstrapParam =
new ComplexParameter(self::BOOTSTRAP_PARAM);
239 foreach (
$request->getContent() as $paramStr) {
240 $result = $bootstrapParam->getFromString($paramStr);
257 if (!isset($initParams[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS][
DirectoryList::ROOT])) {
258 throw new \LogicException(
'Magento root directory is not specified.');
260 $config = $initParams[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS];
273 $driverPool =
new Filesystem\DriverPool();
276 new Filesystem\Directory\ReadFactory($driverPool),
277 new Filesystem\Directory\WriteFactory($driverPool)
static getDistroBaseUrlPath($server)
attach(EventManagerInterface $events, $priority=1)
detach(EventManagerInterface $events)
createFilesystem(DirectoryList $directoryList)
createService(ServiceLocatorInterface $serviceLocator)
createDirectoryList($initParams)
static getUrlNoScript($url)