Skip to content

Commit c30a7ae

Browse files
committed
Adding deployment configuration for environments
1 parent 3419c71 commit c30a7ae

File tree

7 files changed

+118
-10
lines changed

7 files changed

+118
-10
lines changed

app/code/Magento/Config/Model/Config/Backend/Admin/Robots.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
namespace Magento\Config\Model\Config\Backend\Admin;
1111

12-
use Magento\Framework\App\Filesystem\DirectoryList;
13-
1412
class Robots extends \Magento\Framework\App\Config\Value
1513
{
1614
/**
@@ -39,12 +37,13 @@ public function __construct(
3937
\Magento\Framework\App\Config\ScopeConfigInterface $config,
4038
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
4139
\Magento\Framework\Filesystem $filesystem,
40+
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot,
4241
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
4342
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
4443
array $data = []
4544
) {
4645
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
47-
$this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
46+
$this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath());
4847
$this->_file = 'robots.txt';
4948
}
5049

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* @by SwiftOtter, Inc., 04/01/2017
4+
* @website https://swiftotter.com
5+
**/
6+
7+
namespace Magento\Config\Model\Config\Reader\Source\Deployed;
8+
9+
use Magento\Framework\Config\ConfigOptionsListConstants;
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
12+
class DocumentRoot
13+
{
14+
private $config;
15+
16+
public function __construct(\Magento\Framework\App\DeploymentConfig $config)
17+
{
18+
$this->config = $config;
19+
}
20+
21+
public function getPath()
22+
{
23+
return $this->isPub() ? DirectoryList::PUB : DirectoryList::ROOT;
24+
}
25+
26+
public function isPub()
27+
{
28+
return (bool)$this->config->get(ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Test\Unit\Model\Config\Reader\Source\Deployed;
7+
8+
use Magento\Config\Model\Config\Reader;
9+
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
10+
use Magento\Framework\App\Config;
11+
use Magento\Framework\App\DeploymentConfig;
12+
use Magento\Config\Model\Placeholder\PlaceholderInterface;
13+
use Magento\Config\Model\Placeholder\PlaceholderFactory;
14+
use Magento\Framework\App\Filesystem\DirectoryList;
15+
use Magento\Framework\Config\ConfigOptionsListConstants;
16+
17+
/**
18+
* Test class for checking settings that defined in config file
19+
*/
20+
class DocumentRootTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $configMock;
26+
27+
/**
28+
* @var PlaceholderInterface|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $placeholderMock;
31+
32+
/**
33+
* @var Config\ScopeCodeResolver|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $scopeCodeResolverMock;
36+
37+
/**
38+
* @var SettingChecker
39+
*/
40+
private $documentRoot;
41+
42+
/**
43+
* @var array
44+
*/
45+
private $env;
46+
47+
public function setUp()
48+
{
49+
$this->configMock = $this->getMockBuilder(DeploymentConfig::class)
50+
->disableOriginalConstructor()
51+
->getMock();
52+
53+
$this->documentRoot = new Reader\Source\Deployed\DocumentRoot($this->configMock);
54+
}
55+
56+
public function testGetPath()
57+
{
58+
$this->configMockSetForDocumentRootIsPub();
59+
60+
$this->assertSame(DirectoryList::PUB, $this->documentRoot->getPath());
61+
}
62+
63+
public function testIsPub()
64+
{
65+
$this->configMockSetForDocumentRootIsPub();
66+
67+
$this->assertSame(true, $this->documentRoot->isPub());
68+
}
69+
70+
private function configMockSetForDocumentRootIsPub()
71+
{
72+
$this->configMock->expects($this->any())
73+
->method('get')
74+
->willReturnMap([
75+
[
76+
ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB,
77+
null,
78+
true
79+
],
80+
]);
81+
}
82+
}

app/code/Magento/Sitemap/Model/Sitemap.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
namespace Magento\Sitemap\Model;
1010

11-
use Magento\Framework\App\Filesystem\DirectoryList;
12-
1311
/**
1412
* Sitemap model
1513
*
@@ -177,13 +175,14 @@ public function __construct(
177175
\Magento\Store\Model\StoreManagerInterface $storeManager,
178176
\Magento\Framework\App\RequestInterface $request,
179177
\Magento\Framework\Stdlib\DateTime $dateTime,
178+
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot,
180179
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
181180
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
182181
array $data = []
183182
) {
184183
$this->_escaper = $escaper;
185184
$this->_sitemapData = $sitemapData;
186-
$this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
185+
$this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath());
187186
$this->_categoryFactory = $categoryFactory;
188187
$this->_productFactory = $productFactory;
189188
$this->_cmsFactory = $cmsFactory;

generated/.htaccess

-2
This file was deleted.

lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class ConfigOptionsListConstants
3030
const CONFIG_PATH_DB = 'db';
3131
const CONFIG_PATH_RESOURCE = 'resource';
3232
const CONFIG_PATH_CACHE_TYPES = 'cache_types';
33+
const CONFIG_PATH_DOCUMENT_ROOT_IS_PUB = 'directories/document_root_is_pub';
34+
3335
/**#@-*/
3436

3537
/**#@+

vendor/.htaccess

-2
This file was deleted.

0 commit comments

Comments
 (0)