<commit_before><?php
/**
 * Created by PhpStorm.
 * User: <NAME>
 * Date: 18.03.14
 * Time: 14:56
 */

namespace Brother\CommonBundle;


use Doctrine\Bundle\MongoDBBundle\Logger\Logger;
use Elao\ErrorNotifierBundle\Listener\Notifier;
use Exception;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;

class AppDebug {
    static public $log = array();

    static $username = false;

    /**
     * @var ContainerInterface
     */
    static $container = null;

    /**
     * @var Logger
     */
    static $logger = null;

    /**
     * @var Notifier
     */
    static $listener = null;

    static $request = null;

    /**
     * C-tor
     *
     */
    public function __construct()
    {
    }

    /**
     * Enter description here...
     *
     * @return string
     */

    static public function getUsername()
    {
        if (!self::$container->has('security.context')) {
            return null;
        }

        if (null === $token = self::$container->get('security.context')->getToken()) {
            return null;
        }

        if (!is_object($user = $token->getUser())) {
            return null;
        }

        return $user;
    }

    /**
     * Print data for debugging using @see print_r() function
     *
     * @param mixed $data printed data
     * @param string $title custom title for data
     */
    static function myPrint_r($data, $title = '')
    {
        echo "<br /><b>" . $title . "</b><br />\n";
        echo '<pre>';
        print_r($data);
        echo "</pre>\n";
    }

    /**
     * Short version of myPrint_r
     *
     * @param mixed $object
     * @param string $title
     * @param int $lineCount
     * @param bool $isEcho
     */
    public static function _d($object, $title = '', $lineCount = 1, $isEcho=true)
    {
        $s = "<br /><b>" . $title . "</b><br />\n<PRE>" . print_r($object, true) . "</PRE><BR/>";
        $exception = new Exception("Debug exception " . $title . ' ' . print_r($object, true));
        if ($lineCount) {
            ini_set('memory_limit', '4048M');
            $trace = $exception->getTrace();
//            $trace = debug_backtrace(false, $lineCount);
            $count = count($trace);
            for ($i = 0; $i < $lineCount && $i < $count; $i++) {
                if (isset($trace[$i]['file']) && isset($trace[$i]['line'])) {
                    $s .= "file $i: " . $trace[$i]['file'] . "<br/>line: " . $trace[$i]['line'] . "<br/>\n";
                }
            }
        }
        if (defined('DEV') && $isEcho) {
            echo $s;
        } else {
            self::createMailAndSend($exception, $_REQUEST);
            self::writeLog($s, false, 'debug');
        }
    }

    /**
     * @param $object
     * @param string $title
     * @param bool $debug
     * @param int $count
     */
    public static function _dx($object, $title = '', $debug = true, $count = 15)
    {
        self::_d($object, $title, $count, $debug);
        if (defined('DEV')) {
            die(0);
        }
    }

    /**
     * WriteLog on screen and log file
     *
     * @param string $s
     * @param bool $isEcho
     * @param string $name
     *
     */
    public static function writeLog($s, $isEcho = true, $name = 'batch')
    {
//        $name .= date('_Y_m_d');
        if (is_array($s) || is_object($s)) {
            $s = print_r($s, true);
        }
        $s .= "; user: " . self::getUsername() . "; mem: " . memory_get_usage();
        if ($isEcho) {
            echo strftime('%Y-%m-%d %H:%M:%S') . ": " . $s . "<br/>\n";
        }
        if ($log = self::$logger) {
            $log->info($s);
        }
    }

    /**
     * @param $exception
     */
    public static function createMailAndSend($exception)
    {
        self::$listener->createMailAndSend($exception, self::getRequest(), self::$container);
    }

    /**
     * @param $logger
     */
    public static function setLogger($logger)
    {
        self::$logger = $logger;
    }

    /**
     * @return null|Request
     */
    private static function getRequest()
    {
        if (self::$request == null) {
            self::$request = Request::createFromGlobals();
            self::$request->setSession(self::$container->get('session'));
        }
        return self::$request;
    }

    /**
     * @param ContainerInterface $container
     */
    public static function setContainer($container)
    {
        self::$container = $container;
        self::$logger = $container->get('logger');
        self::$listener = $container->get('elao.error_notifier.listener');
    }

} <commit_msg>Fix test<commit_after><?php
/**
 * Created by PhpStorm.
 * User: <NAME>
 * Date: 18.03.14
 * Time: 14:56
 */

namespace Brother\CommonBundle;


use Doctrine\Bundle\MongoDBBundle\Logger\Logger;
use Elao\ErrorNotifierBundle\Listener\Notifier;
use Exception;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;

class AppDebug {
    static public $log = array();

    static $username = false;

    /**
     * @var ContainerInterface
     */
    static $container = null;

    /**
     * @var Logger
     */
    static $logger = null;

    static $request = null;

    /**
     * C-tor
     *
     */
    public function __construct()
    {
    }

    /**
     * Enter description here...
     *
     * @return string
     */

    static public function getUsername()
    {
        if (!self::$container->has('security.context')) {
            return null;
        }

        if (null === $token = self::$container->get('security.context')->getToken()) {
            return null;
        }

        if (!is_object($user = $token->getUser())) {
            return null;
        }

        return $user;
    }

    /**
     * Print data for debugging using @see print_r() function
     *
     * @param mixed $data printed data
     * @param string $title custom title for data
     */
    static function myPrint_r($data, $title = '')
    {
        echo "<br /><b>" . $title . "</b><br />\n";
        echo '<pre>';
        print_r($data);
        echo "</pre>\n";
    }

    /**
     * Short version of myPrint_r
     *
     * @param mixed $object
     * @param string $title
     * @param int $lineCount
     * @param bool $isEcho
     */
    public static function _d($object, $title = '', $lineCount = 1, $isEcho=true)
    {
        $s = "<br /><b>" . $title . "</b><br />\n<PRE>" . print_r($object, true) . "</PRE><BR/>";
        $exception = new Exception("Debug exception " . $title . ' ' . print_r($object, true));
        if ($lineCount) {
            ini_set('memory_limit', '4048M');
            $trace = $exception->getTrace();
//            $trace = debug_backtrace(false, $lineCount);
            $count = count($trace);
            for ($i = 0; $i < $lineCount && $i < $count; $i++) {
                if (isset($trace[$i]['file']) && isset($trace[$i]['line'])) {
                    $s .= "file $i: " . $trace[$i]['file'] . "<br/>line: " . $trace[$i]['line'] . "<br/>\n";
                }
            }
        }
        if (defined('DEV') && $isEcho) {
            echo $s;
        } else {
            self::createMailAndSend($exception, $_REQUEST);
            self::writeLog($s, false, 'debug');
        }
    }

    /**
     * @param $object
     * @param string $title
     * @param bool $debug
     * @param int $count
     */
    public static function _dx($object, $title = '', $debug = true, $count = 15)
    {
        self::_d($object, $title, $count, $debug);
        if (defined('DEV')) {
            die(0);
        }
    }

    /**
     * WriteLog on screen and log file
     *
     * @param string $s
     * @param bool $isEcho
     * @param string $name
     *
     */
    public static function writeLog($s, $isEcho = true, $name = 'batch')
    {
//        $name .= date('_Y_m_d');
        if (is_array($s) || is_object($s)) {
            $s = print_r($s, true);
        }
        $s .= "; user: " . self::getUsername() . "; mem: " . memory_get_usage();
        if ($isEcho) {
            echo strftime('%Y-%m-%d %H:%M:%S') . ": " . $s . "<br/>\n";
        }
        if ($log = self::$logger) {
            $log->info($s);
        }
    }

    /**
     * @param $exception
     */
    public static function createMailAndSend($exception)
    {
        if (self::$container) {
            $listener = self::$container->get('elao.error_notifier.listener');
            /** @var $listener Notifier */
            $listener->createMailAndSend($exception, self::getRequest(), self::$container);
        }
    }

    /**
     * @param $logger
     */
    public static function setLogger($logger)
    {
        self::$logger = $logger;
    }

    /**
     * @return null|Request
     */
    private static function getRequest()
    {
        if (self::$request == null) {
            self::$request = Request::createFromGlobals();
            self::$request->setSession(self::$container->get('session'));
        }
        return self::$request;
    }

    /**
     * @param ContainerInterface $container
     */
    public static function setContainer($container)
    {
        self::$container = $container;
        self::$logger = $container->get('logger');
    }

} 
{'fraction_non_alphanumeric': 0.17433466221312358, 'fraction_numerical': 0.004094386380777934, 'mean_word_length': 1.8481129180730285, 'pattern_counts': {'":': 2, '<': 43, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1139961', 'n_tokens_mistral': 2890, 'n_tokens_neox': 2842, 'n_words': 625}