Пример #1
0
 /**
  * @dataProvider isPathInDirectoryDataProvider
  * @param string $path
  * @param string $directory
  * @param boolean $expectedValue
  */
 public function testIsPathInDirectory($path, $directory, $expectedValue)
 {
     $this->assertEquals($expectedValue, Magento_Filesystem::isPathInDirectory($path, $directory));
 }
Пример #2
0
    /**
     * Retrieve block view from file (template)
     *
     * @param  string $fileName
     * @return string
     * @throws Exception
     */
    public function fetchView($fileName)
    {
        $viewShortPath = str_replace(Mage::getBaseDir(), '', $fileName);
        Magento_Profiler::start('TEMPLATE:' . $fileName, array('group' => 'TEMPLATE', 'file_name' => $viewShortPath));
        // EXTR_SKIP protects from overriding
        // already defined variables
        extract($this->_viewVars, EXTR_SKIP);
        $do = $this->getDirectOutput();
        if (!$do) {
            ob_start();
        }
        if ($this->getShowTemplateHints()) {
            echo <<<HTML
<div style="position:relative; border:1px dotted red; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;">
<div style="position:absolute; left:0; top:0; padding:2px 5px; background:red; color:white; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'"
onmouseout="this.style.zIndex='998'" title="{$fileName}">{$fileName}</div>
HTML;
            if (self::$_showTemplateHintsBlocks) {
                $thisClass = get_class($this);
                echo <<<HTML
<div style="position:absolute; right:0; top:0; padding:2px 5px; background:red; color:blue; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'" onmouseout="this.style.zIndex='998'"
title="{$thisClass}">{$thisClass}</div>
HTML;
            }
        }
        try {
            if ((Magento_Filesystem::isPathInDirectory($fileName, Mage::getBaseDir('app')) || Magento_Filesystem::isPathInDirectory($fileName, $this->_viewDir) || $this->_getAllowSymlinks()) && $this->_filesystem->isFile($fileName)) {
                include $fileName;
            } else {
                Mage::log("Invalid template file: '{$fileName}'", Zend_Log::CRIT, null, true);
            }
        } catch (Exception $e) {
            if (!$do) {
                ob_get_clean();
            }
            throw $e;
        }
        if ($this->getShowTemplateHints()) {
            echo '</div>';
        }
        if (!$do) {
            $html = ob_get_clean();
        } else {
            $html = '';
        }
        Magento_Profiler::stop('TEMPLATE:' . $fileName);
        return $html;
    }