Skip to content

Commit fb62215

Browse files
bbatschetjwiebell
authored andcommitted
Cloud Integration (#5)
- Move repository files to root - Move di.xml file to root of etc - Move to factory pattern for Upward Conroller - Move configuration to standard Magento configuration settings
1 parent aab744a commit fb62215

File tree

13 files changed

+99
-18
lines changed

13 files changed

+99
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.idea
2+
composer.lock
3+
vendor

app/code/Magento/UpwardConnector/Controller/Upward.php renamed to Controller/Upward.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\App\ResponseInterface;
1313
use Magento\Framework\HTTP\PhpEnvironment\Response;
14-
use Magento\Upward\Controller as UpwardController;
1514
use Zend\Http\Response\Stream;
1615

1716
class Upward implements FrontControllerInterface
@@ -22,20 +21,18 @@ class Upward implements FrontControllerInterface
2221
private $response;
2322

2423
/**
25-
* @var UpwardController
24+
* @var UpwardControllerFactory
2625
*/
27-
private $upwardController;
26+
private $upwardFactory;
2827

2928
/**
3029
* @param Response $response
31-
* @param UpwardController $upwardController
30+
* @param UpwardControllerFactory $upwardFactory
3231
*/
33-
public function __construct(
34-
Response $response,
35-
UpwardController $upwardController
36-
) {
32+
public function __construct(Response $response, UpwardControllerFactory $upwardFactory)
33+
{
3734
$this->response = $response;
38-
$this->upwardController = $upwardController;
35+
$this->upwardFactory = $upwardFactory;
3936
}
4037

4138
/**
@@ -47,11 +44,13 @@ public function __construct(
4744
public function dispatch(RequestInterface $request)
4845
{
4946
/** @var \Zend\Http\Response $upwardResponse */
50-
$upwardResponse = ($this->upwardController)();
47+
$upwardResponse = $this->upwardFactory->create($request)();
5148
$content = $upwardResponse instanceof Stream ? $upwardResponse->getBody() : $upwardResponse->getContent();
49+
5250
$this->response->setHeaders($upwardResponse->getHeaders());
5351
$this->response->setStatusCode($upwardResponse->getStatusCode());
5452
$this->response->setContent($content);
53+
5554
return $this->response;
5655
}
5756
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\UpwardConnector\Controller;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Upward\Controller as UpwardController;
14+
15+
class UpwardControllerFactory
16+
{
17+
/**
18+
* Config path where UPWARD config file path is found.
19+
*/
20+
public const UPWARD_CONFIG_PATH = 'web/upward/path';
21+
22+
/**
23+
* @var ScopeConfigInterface
24+
*/
25+
private $config;
26+
27+
/**
28+
* @var ObjectManagerInterface
29+
*/
30+
private $objectManager;
31+
32+
/**
33+
* @param ObjectManagerInterface $objectManager
34+
* @param ScopeConfigInterface $scopeConfig
35+
*/
36+
public function __construct(ObjectManagerInterface $objectManager, ScopeConfigInterface $scopeConfig)
37+
{
38+
$this->objectManager = $objectManager;
39+
$this->config = $scopeConfig;
40+
}
41+
42+
/**
43+
* Create new UPWARD PHP controller for Request
44+
*
45+
* @param RequestInterface $request
46+
*
47+
* @return UpwardController
48+
*/
49+
public function create(RequestInterface $request): UpwardController
50+
{
51+
$upwardConfig = $this->scopeConfig->getValue(
52+
static::UPWARD_CONFIG_PATH,
53+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
54+
);
55+
56+
if (empty($upwardConfig)) {
57+
throw new \RuntimeException('Path to UPWARD configuration file not set.');
58+
}
59+
60+
return $this->objectManager->create(UpwardController::class, compact('request', 'upwardConfig'));
61+
}
62+
}
File renamed without changes.
File renamed without changes.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# magento2-upward-connector
1+
Magento_UpwardConnector module used for correctly routing frontend requests through UPWARD-PHP.

app/code/Magento/UpwardConnector/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/code/Magento/UpwardConnector/composer.json renamed to composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"require": {
1414
"php": "~7.1.3||~7.2.0",
15-
"magento/framework": "*",
15+
"magento/framework": "^102.0",
1616
"magento/upward": "dev-master"
1717
},
1818
"type": "magento2-module",

etc/adminhtml/system.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
10+
<system>
11+
<section id="web">
12+
<group id="upward" translate="label" type="text" sortOrder="300"
13+
showInDefault="1" showInWebsite="0" showInStore="0">
14+
<label>UPWARD Configuration</label>
15+
<field id="config_path" type="text" translate="label,comment"
16+
sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
17+
<label>UPWARD Config File</label>
18+
<config_path>web/upward/path</config_path>
19+
<comment>Server path to YAML configuration file for UPWARD</comment>
20+
</field>
21+
</group>
22+
</section>
23+
</system>
24+
</config>

0 commit comments

Comments
 (0)