You are here

class ProfilerExtension in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Twig/Extension/ProfilerExtension.php \Drupal\webprofiler\Twig\Extension\ProfilerExtension
  2. 8.2 webprofiler/src/Twig/Extension/ProfilerExtension.php \Drupal\webprofiler\Twig\Extension\ProfilerExtension
  3. 4.x webprofiler/src/Twig/Extension/ProfilerExtension.php \Drupal\webprofiler\Twig\Extension\ProfilerExtension

Class ProfilerExtension

Hierarchy

  • class \Drupal\webprofiler\Twig\Extension\ProfilerExtension extends \Drupal\webprofiler\Twig\Extension\Twig_Extension_Profiler

Expanded class hierarchy of ProfilerExtension

1 string reference to 'ProfilerExtension'
webprofiler.services.yml in webprofiler/webprofiler.services.yml
webprofiler/webprofiler.services.yml
1 service uses ProfilerExtension
twig.extension.profiler in webprofiler/webprofiler.services.yml
Drupal\webprofiler\Twig\Extension\ProfilerExtension

File

webprofiler/src/Twig/Extension/ProfilerExtension.php, line 12

Namespace

Drupal\webprofiler\Twig\Extension
View source
class ProfilerExtension extends \Twig_Extension_Profiler {

  /**
   * @var \Symfony\Component\Stopwatch\Stopwatch
   */
  private $stopwatch;
  private $events;
  private $ideLink;
  private $classShortener;

  /**
   * {@inheritdoc}
   */
  public function __construct(\Twig_Profiler_Profile $profile, Stopwatch $stopwatch = NULL, IdeLinkGeneratorInterface $ideLink, ClassShortenerInterface $classShortener) {
    parent::__construct($profile);
    $this->ideLink = $ideLink;
    $this->classShortener = $classShortener;
    $this->stopwatch = $stopwatch;
    $this->events = new \SplObjectStorage();
  }

  /**
   * {@inheritdoc}
   */
  public function enter(\Twig_Profiler_Profile $profile) {
    if ($this->stopwatch && $profile
      ->isTemplate()) {
      $this->events[$profile] = $this->stopwatch
        ->start($profile
        ->getName(), 'template');
    }
    parent::enter($profile);
  }

  /**
   * {@inheritdoc}
   */
  public function leave(\Twig_Profiler_Profile $profile) {
    parent::leave($profile);
    if ($this->stopwatch && $profile
      ->isTemplate()) {
      $this->events[$profile]
        ->stop();
      unset($this->events[$profile]);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getFunctions() {
    return [
      new \Twig_SimpleFunction('abbr', [
        $this,
        'getAbbr',
      ]),
      new \Twig_SimpleFunction('idelink', [
        $this,
        'getIdeLink',
      ]),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'native_profiler';
  }

  /**
   * @param $class
   *
   * @return string
   */
  public function getAbbr($class) {
    return $this->classShortener
      ->shortenClass($class);
  }

  /**
   * @param $file
   * @param $line
   *
   * @return string
   */
  public function getIdeLink($file, $line) {
    return $this->ideLink
      ->generateLink($file, $line);
  }

}

Members