Overview

Namespaces

  • Faulancer
    • Controller
    • Exception
    • Form
      • Validator
        • Type
    • Helper
      • Reflection
    • Http
    • Mail
    • ORM
      • User
    • Service
      • Factory
    • ServiceLocator
    • Session
    • View
      • Helper

Classes

  • AssetList
  • Block
  • CodeBlock
  • EndBlock
  • EscapeString
  • FlashBag
  • FormData
  • FormError
  • GenerateCsrfToken
  • Highlighter
  • ParentTemplate
  • RenderBlock
  • RenderView
  • Route
  • Translate
  • User
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 
<?php
/**
 * Class CodeBlock | CodeBlock.php
 * @package Faulancer\View\Helper
 * @author  Florian Knapp <office@florianknapp.de>
 */
namespace Faulancer\View\Helper;

use Faulancer\View\AbstractViewHelper;
use Faulancer\View\ViewController;

/**
 * Class CodeBlock
 */
class CodeBlock extends AbstractViewHelper
{

    /**
     * @param ViewController $view
     * @param                $filename
     * @param int            $actualLine
     * @return string
     * @codeCoverageIgnore
     */
    public function __invoke(ViewController $view, $filename, $actualLine = 0)
    {

        $lineNr = 0;
        $lines  = '';
        $file   = fopen($filename, 'r');

        $tabChar = '&nbsp;&nbsp;&nbsp;&nbsp;';
        $regularChar = '&nbsp;';

        while ($line = fgets($file)) {

            $lineNr++;

            if ($lineNr >= $actualLine - 6 && $lineNr <= $actualLine + 3) {

                $l = str_replace("\t", $tabChar, $line);
                $l = str_replace(" ", $regularChar, $l);

                if ($lineNr === $actualLine) {
                    $lines .= '<span class="line highlight"><span class="line-nr">' . $lineNr . '</span>' . $view->highlighter($l, 'php') . '</span>';
                } else {
                    $lines .= '<span class="line"><span class="line-nr">' . $lineNr . '</span>' . $view->highlighter($l, 'php') . '</span>';
                }

            }

        }

        return $lines;

    }

}
API documentation generated by ApiGen