How to read file using ReadInterface function readFile in Magento 2?

Hi, all amazing devs!

I have recently started learning Magento 2 and one of the things I have learned so far is how to create theme modules and modules that install a page. For example, I have this InstallData.php code

<?php

namespace EDU361Task3Setup;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkExceptionFileSystemException;
use MagentoFrameworkFilesystemDirectoryReadInterface;
/**
* Class InstallData
* u/package EDU361Task3Setup
* u/version 1.0.0
*/
class InstallData implements InstallDataInterface
{
/**
* u/var MagentoCmsModelPageFactory
*/
protected $pageFactory;
/**
* u/param MagentoCmsModelPageFactory $pageFactory
*/
public function __construct(MagentoCmsModelPageFactory $pageFactory)
{
$this -> pageFactory = $pageFactory;
}
/**
* u/param ModuleDataSetupInterface $setup
* u/param ModuleContextInterface $context
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$content = file_get_contents(dirname(dirname(__FILE__)).’/view/frontend/templates/delivery.html’);
$setup->startSetup();
$page = $this->pageFactory->create();
$page->setTitle('JYSK delivery')
->setIdentifier('delivery')
->setIsActive(1)
->setPageLayout('1column')
->setStores([0])
->setContent($content)
->setMetaKeywords('Meta keywords for JYSK delivery page')
->setMetaDescription('Meta description for JYSK delivery page')
->save();
$setup->endSetup();
}
}

I highlighted two parts of the code. So far, I’m reading my file using $content, but I want to achieve the same result but the Magento way using ReadInterface.

Any insights on how I could approach this, would be helpful.

submitted by /u/raynsi
[link] [comments]