load() public method

Reads the contents of a PHP file stripping the opening and closing PHP tags.
public load ( string $file, string | null $type = null ) : string
$file string
$type string | null
return string
Example #1
0
    /**
     * Tests the load() method.
     */
    public function testLoad()
    {
        $this->assertEquals("\n\n\$GLOBALS['TL_TEST'] = true;\n", $this->loader->load($this->getRootDir() . '/vendor/contao/test-bundle/Resources/contao/config/config.php'));
        $content = <<<'EOF'


$GLOBALS['TL_DCA']['tl_test'] = [
    'config' => [
        'dataContainer' => 'DC_Table',
        'sql' => [
            'keys' => [
                'id' => 'primary',
            ],
        ],
    ],
    'fields' => [
        'id' => [
            'sql' => "int(10) unsigned NOT NULL auto_increment"
        ],
    ],
];

EOF;
        $this->assertEquals($content, $this->loader->load($this->getRootDir() . '/vendor/contao/test-bundle/Resources/contao/dca/tl_test.php'));
        $this->assertEquals("\n\n\$GLOBALS['TL_TEST'] = true;\n", $this->loader->load($this->getRootDir() . '/vendor/contao/test-bundle/Resources/contao/languages/en/tl_test.php'));
    }
Example #2
0
 /**
  * Read the contents of a PHP file, stripping the opening and closing PHP tags
  *
  * @param string $strName The name of the PHP file
  *
  * @return string The PHP code without the PHP tags
  *
  * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0.
  *             Use the Contao\CoreBundle\Config\Loader\PhpFileLoader instead.
  */
 protected static function readPhpFileWithoutTags($strName)
 {
     @trigger_error('Using System::readPhpFileWithoutTags() has been deprecated and will no longer work in Contao 5.0. Use the Contao\\CoreBundle\\Config\\Loader\\PhpFileLoader instead.', E_USER_DEPRECATED);
     // Convert to absolute path
     if (strpos($strName, TL_ROOT . '/') === false) {
         $strName = TL_ROOT . '/' . $strName;
     }
     $loader = new PhpFileLoader();
     return $loader->load($strName);
 }