Snippets

Michael Schramm WatchHelperTrait.php

Created by Michael Schramm
<?php

namespace Util\Helper;

use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\Stopwatch\Stopwatch;

/**
 * stop watch calls.
 */
trait WatchHelperTrait
{
    /**
     * @DI\Inject("debug.stopwatch", required=false)
     *
     * @var Stopwatch
     */
    public $stopwatch;

    /**
     * @param string $section
     */
    protected function watchOpenSection($section)
    {
        if (!$this->stopwatch) {
            return;
        }

        $this->stopwatch->openSection($section);
    }

    /**
     * @param string $section
     */
    protected function watchCloseSection($section)
    {
        if (!$this->stopwatch) {
            return;
        }

        $this->stopwatch->stopSection($section);
    }

    /**
     * @param string $name
     * @param string $catagory
     */
    protected function watchStart($name, $catagory = null)
    {
        if (!$this->stopwatch) {
            return;
        }

        $this->stopwatch->start($name, $catagory);
    }

    /**
     * @param string $name
     */
    protected function watchLap($name)
    {
        if (!$this->stopwatch) {
            return;
        }

        $this->stopwatch->lap($name);
    }

    /**
     * @param string $name
     */
    protected function watchStop($name)
    {
        if (!$this->stopwatch) {
            return;
        }

        $this->stopwatch->stop($name);
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.