Skip to content

Commit 35ffba3

Browse files
committed
Updating per code review comments at hackathon
1 parent c30a7ae commit 35ffba3

File tree

6 files changed

+48
-8
lines changed

6 files changed

+48
-8
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
namespace Magento\Config\Model\Config\Backend\Admin;
1111

12+
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
13+
use Magento\Framework\App\ObjectManager;
14+
1215
class Robots extends \Magento\Framework\App\Config\Value
1316
{
1417
/**
@@ -37,12 +40,14 @@ public function __construct(
3740
\Magento\Framework\App\Config\ScopeConfigInterface $config,
3841
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
3942
\Magento\Framework\Filesystem $filesystem,
40-
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot,
4143
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
4244
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
43-
array $data = []
45+
array $data = [],
46+
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot = null
4447
) {
4548
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
49+
50+
$documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
4651
$this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath());
4752
$this->_file = 'robots.txt';
4853
}
Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,51 @@
11
<?php
22
/**
3-
* @by SwiftOtter, Inc., 04/01/2017
4-
* @website https://swiftotter.com
5-
**/
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
66

77
namespace Magento\Config\Model\Config\Reader\Source\Deployed;
88

99
use Magento\Framework\Config\ConfigOptionsListConstants;
1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111

12+
/**
13+
* Class DocumentRoot
14+
* @package Magento\Config\Model\Config\Reader\Source\Deployed
15+
*/
1216
class DocumentRoot
1317
{
1418
private $config;
1519

20+
/**
21+
* DocumentRoot constructor.
22+
* @param \Magento\Framework\App\DeploymentConfig $config
23+
*/
1624
public function __construct(\Magento\Framework\App\DeploymentConfig $config)
1725
{
1826
$this->config = $config;
1927
}
2028

29+
/**
30+
* A shortcut to load the document root path from the DirectoryList based on the
31+
* deployment configuration.
32+
*
33+
* @return string
34+
*/
2135
public function getPath()
2236
{
2337
return $this->isPub() ? DirectoryList::PUB : DirectoryList::ROOT;
2438
}
2539

40+
/**
41+
* Returns whether the deployment configuration specifies that the document root is
42+
* in the pub/ folder. This affects ares such as sitemaps and robots.txt (and will
43+
* likely be extended to control other areas).
44+
*
45+
* @return bool
46+
*/
2647
public function isPub()
2748
{
2849
return (bool)$this->config->get(ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB);
2950
}
30-
}
51+
}

app/code/Magento/Config/Test/Unit/Model/Config/Reader/Source/Deployed/DocumentRootTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,20 @@ public function setUp()
5353
$this->documentRoot = new Reader\Source\Deployed\DocumentRoot($this->configMock);
5454
}
5555

56+
/**
57+
* Ensures that the path returned matches the pub/ path.
58+
*/
5659
public function testGetPath()
5760
{
5861
$this->configMockSetForDocumentRootIsPub();
5962

6063
$this->assertSame(DirectoryList::PUB, $this->documentRoot->getPath());
6164
}
6265

66+
/**
67+
* Ensures that the deployment configuration returns the mocked value for
68+
* the pub/ folder.
69+
*/
6370
public function testIsPub()
6471
{
6572
$this->configMockSetForDocumentRootIsPub();

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// @codingStandardsIgnoreFile
88

99
namespace Magento\Sitemap\Model;
10+
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
11+
use Magento\Framework\App\ObjectManager;
1012

1113
/**
1214
* Sitemap model
@@ -175,13 +177,14 @@ public function __construct(
175177
\Magento\Store\Model\StoreManagerInterface $storeManager,
176178
\Magento\Framework\App\RequestInterface $request,
177179
\Magento\Framework\Stdlib\DateTime $dateTime,
178-
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot,
179180
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
180181
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
181-
array $data = []
182+
array $data = [],
183+
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot = null
182184
) {
183185
$this->_escaper = $escaper;
184186
$this->_sitemapData = $sitemapData;
187+
$documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
185188
$this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath());
186189
$this->_categoryFactory = $categoryFactory;
187190
$this->_productFactory = $productFactory;

generated/.htaccess

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Order allow,deny
2+
Deny from all

vendor/.htaccess

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Order allow,deny
2+
Deny from all

0 commit comments

Comments
 (0)