Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Robots.php
Go to the documentation of this file.
1 <?php
11 
14 
18 class Robots extends \Magento\Framework\App\Config\Value
19 {
23  protected $_directory;
24 
28  protected $_file;
29 
41  public function __construct(
42  \Magento\Framework\Model\Context $context,
43  \Magento\Framework\Registry $registry,
45  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
46  \Magento\Framework\Filesystem $filesystem,
47  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
48  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
49  array $data = [],
50  \Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot = null
51  ) {
52  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
53 
54  $documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
55  $this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath());
56  $this->_file = 'robots.txt';
57  }
58 
64  protected function _getDefaultValue()
65  {
66  if ($this->_directory->isFile($this->_file)) {
67  return $this->_directory->readFile($this->_file);
68  }
69  return false;
70  }
71 
77  protected function _afterLoad()
78  {
79  if (!(string)$this->getValue()) {
80  $this->setValue($this->_getDefaultValue());
81  }
82 
83  return parent::_afterLoad();
84  }
85 
91  public function afterSave()
92  {
93  if ($this->getValue()) {
94  $this->_directory->writeFile($this->_file, $this->getValue());
95  }
96 
97  return parent::afterSave();
98  }
99 }
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], \Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot=null)
Definition: Robots.php:41
$config
Definition: fraud_order.php:17
$resource
Definition: bulk.php:12
$filesystem