<commit_before><?php

/**
 * http://phpconsole.com
 *
 * A detached logging facility for PHP, JS and other environments, with analytical twist, to aid your daily development routine.
 *
 * Watch quick tutorial at: https://vimeo.com/58393977
 *
 * @link https://github.com/phpconsole
 * @copyright Copyright (c) 2012 - 2013 phpconsole.com
 * @license See LICENSE file
 * @version 1.4.1
 */


class Phpconsole {

    private $version;
    private $type;
    private $api_address;
    private $domain;
    private $users;
    private $user_api_keys;
    private $projects;
    private $initialized;
    private $snippets;
    private $counters;
    private $curl_error_reporting_enabled;
    private $backtrace_depth;
    private $path_to_cert;
    private $passed_ssl_test;
    private $ssl_test_error_message;
    private $ssl_verification_enabled;
    private $context_enabled;
    private $context_size;

    /*
    ================
    PUBLIC FUNCTIONS
    ================
    */

    /**
     * Constructor - sets preferences
     */
    public function __construct() {

        $this->version = '1.4.1';
        $this->type = 'php';
        $this->api_address = 'https://app.phpconsole.com/api/0.1/';
        $this->domain = false;
        $this->users = array();
        $this->user_api_keys = array();
        $this->projects = array();
        $this->initialized = false;
        $this->snippets = array();
        $this->counters = array();
        $this->curl_error_reporting_enabled = true;
        $this->backtrace_depth = 0;
        $this->path_to_cert = '';
        $this->passed_ssl_test = false;
        $this->ssl_test_error_message = '';
        $this->ssl_verification_enabled = true;
        $this->context_enabled = true;
        $this->context_size = 3;
    }

    /**
     * Set domain
     *
     * @access  public
     * @param   string
     * @return  void
     */
    public function set_domain($domain) {

        $this->domain = $domain;
    }

    /**
     * Add user (developer)
     *
     * @access  public
     * @param   string
     * @param   string
     * @param   string
     * @return  void
     */
    public function add_user($nickname, $user_api_key, $project_api_key) {

        if($this->domain === false) {
            throw new Exception('Domain variable not set.');
        }

        $user_hash = md5($user_api_key.$this->domain);

        $this->users[$nickname] = $user_hash;
        $this->user_api_keys[$user_hash] = $user_api_key;
        $this->projects[$user_hash] = $project_api_key;
    }

    /**
     * User defined php shutdown function
     *
     * @access  public
     * @param   object
     * @return  void
     */
    public static function shutdown($object) {

        if($object->ssl_verification_enabled) {
            $object->_test_ssl();
        }

        $any_snippets = is_array($object->snippets) && count($object->snippets) > 0;
        $any_counters = is_array($object->counters) && count($object->counters) > 0;

        if($any_snippets || $any_counters) {
            $object->_curl($object->api_address, array(
                'client_code_version' => $object->version,
                'client_code_type' => $object->type,
                'snippets' => $object->snippets,
                'counters' => $object->counters
            ));
        }
    }

    /**
     * Add data to phpconsole's local queue
     *
     * @access  public
     * @param   mixed
     * @param   string
     * @return  mixed
     */
    public function send($data_sent, $user = false) {

        $this->_register_shutdown();

        $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

        $user_hashed_api_key = false;
        $user_api_key = false;
        $project_api_key = false;
        $continue = false;

        if($user === 'all') {
            $this->set_backtrace_depth($this->backtrace_depth+1);
            foreach($this->users as $nickname => $user_hash) {
                $this->send($data_sent, $nickname);
            }
            $this->set_backtrace_depth($this->backtrace_depth-1);

            return $data_sent;
        }
        else if($user === false) {
            if($this->_is_set_cookie('phpconsole_user')) {
                $user_hashed_api_key = $this->_read_cookie('phpconsole_user');
            }
        }
        else {
            if(isset($this->users[$user])) {
                $user_hashed_api_key = $this->users[$user];
            }
        }

        if($user_hashed_api_key !== false) {
            if(isset($this->projects[$user_hashed_api_key])) {
                $project_api_key = $this->projects[$user_hashed_api_key];
                $user_api_key = $this->user_api_keys[$user_hashed_api_key];
                $continue = true;
            }
        }

        if($continue) {

            $data_sent_encoded = base64_encode(json_encode($data_sent));
            $file_name = $bt[$this->backtrace_depth]['file'];
            $line_number = $bt[$this->backtrace_depth]['line'];
            $context = $this->_read_context($file_name, $line_number);
            $address = $this->_current_page_address();

            $this->snippets[] =  array(
                'data_sent' => $data_sent_encoded,
                'context' => $context,
                'file_name' => $file_name,
                'line_number' => $line_number,
                'address' => $address,
                'user_api_key' => $user_api_key,
                'project_api_key' => $project_api_key
            );
        }

        return $data_sent;
    }

    /**
     * Increment selected counter
     *
     * @access  public
     * @param   int
     * @param   string
     * @return  void
     */
    public function count($number = 1, $user = false) {
<commit_msg>Switch back to serialize to capture more info about object.<commit_after><?php

/**
 * http://phpconsole.com
 *
 * A detached logging facility for PHP, JS and other environments, with analytical twist, to aid your daily development routine.
 *
 * Watch quick tutorial at: https://vimeo.com/58393977
 *
 * @link https://github.com/phpconsole
 * @copyright Copyright (c) 2012 - 2013 phpconsole.com
 * @license See LICENSE file
 * @version 1.4.1
 */


class Phpconsole {

    private $version;
    private $type;
    private $api_address;
    private $domain;
    private $users;
    private $user_api_keys;
    private $projects;
    private $initialized;
    private $snippets;
    private $counters;
    private $curl_error_reporting_enabled;
    private $backtrace_depth;
    private $path_to_cert;
    private $passed_ssl_test;
    private $ssl_test_error_message;
    private $ssl_verification_enabled;
    private $context_enabled;
    private $context_size;

    /*
    ================
    PUBLIC FUNCTIONS
    ================
    */

    /**
     * Constructor - sets preferences
     */
    public function __construct() {

        $this->version = '1.4.1';
        $this->type = 'php';
        $this->api_address = 'https://app.phpconsole.com/api/0.1/';
        $this->domain = false;
        $this->users = array();
        $this->user_api_keys = array();
        $this->projects = array();
        $this->initialized = false;
        $this->snippets = array();
        $this->counters = array();
        $this->curl_error_reporting_enabled = true;
        $this->backtrace_depth = 0;
        $this->path_to_cert = '';
        $this->passed_ssl_test = false;
        $this->ssl_test_error_message = '';
        $this->ssl_verification_enabled = true;
        $this->context_enabled = true;
        $this->context_size = 3;
    }

    /**
     * Set domain
     *
     * @access  public
     * @param   string
     * @return  void
     */
    public function set_domain($domain) {

        $this->domain = $domain;
    }

    /**
     * Add user (developer)
     *
     * @access  public
     * @param   string
     * @param   string
     * @param   string
     * @return  void
     */
    public function add_user($nickname, $user_api_key, $project_api_key) {

        if($this->domain === false) {
            throw new Exception('Domain variable not set.');
        }

        $user_hash = md5($user_api_key.$this->domain);

        $this->users[$nickname] = $user_hash;
        $this->user_api_keys[$user_hash] = $user_api_key;
        $this->projects[$user_hash] = $project_api_key;
    }

    /**
     * User defined php shutdown function
     *
     * @access  public
     * @param   object
     * @return  void
     */
    public static function shutdown($object) {

        if($object->ssl_verification_enabled) {
            $object->_test_ssl();
        }

        $any_snippets = is_array($object->snippets) && count($object->snippets) > 0;
        $any_counters = is_array($object->counters) && count($object->counters) > 0;

        if($any_snippets || $any_counters) {
            $object->_curl($object->api_address, array(
                'client_code_version' => $object->version,
                'client_code_type' => $object->type,
                'snippets' => $object->snippets,
                'counters' => $object->counters
            ));
        }
    }

    /**
     * Add data to phpconsole's local queue
     *
     * @access  public
     * @param   mixed
     * @param   string
     * @return  mixed
     */
    public function send($data_sent, $user = false) {

        $this->_register_shutdown();

        $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

        $user_hashed_api_key = false;
        $user_api_key = false;
        $project_api_key = false;
        $continue = false;

        if($user === 'all') {
            $this->set_backtrace_depth($this->backtrace_depth+1);
            foreach($this->users as $nickname => $user_hash) {
                $this->send($data_sent, $nickname);
            }
            $this->set_backtrace_depth($this->backtrace_depth-1);

            return $data_sent;
        }
        else if($user === false) {
            if($this->_is_set_cookie('phpconsole_user')) {
                $user_hashed_api_key = $this->_read_cookie('phpconsole_user');
            }
        }
        else {
            if(isset($this->users[$user])) {
                $user_hashed_api_key = $this->users[$user];
            }
        }

        if($user_hashed_api_key !== false) {
            if(isset($this->projects[$user_hashed_api_key])) {
                $project_api_key = $this->projects[$user_hashed_api_key];
                $user_api_key = $this->user_api_keys[$user_hashed_api_key];
                $continue = true;
            }
        }

        if($continue) {

            $data_sent_encoded = base64_encode(serialize($data_sent));
            $file_name = $bt[$this->backtrace_depth]['file'];
            $line_number = $bt[$this->backtrace_depth]['line'];
            $context = $this->_read_context($file_name, $line_number);
            $address = $this->_current_page_address();

            $this->snippets[] =  array(
                'data_sent' => $data_sent_encoded,
                'context' => $context,
                'file_name' => $file_name,
                'line_number' => $line_number,
                'address' => $address,
                'user_api_key' => $user_api_key,
                'project_api_key' => $project_api_key
            );
        }

        return $data_sent;
    }

    /**
     * Increment selected counter
     *
     * @access  public
     * @param   int
     * @param   string
     * @return  void
     */
    public function count($number = 1, $user = false) {

{'fraction_non_alphanumeric': 0.13826839826839826, 'fraction_numerical': 0.0058874458874458874, 'mean_word_length': 2.0198692810457515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 141, 'https://': 6, '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': '1174294', 'n_tokens_mistral': 3641, 'n_tokens_neox': 3458, 'n_words': 633}