<commit_before><?php
namespace Apigee\Util;

/**
 * A class that represents infomration about an Edge organization.
 */
class OrgConfig
{

    /**
     * The organization name.
     * @var string
     */
    public $orgName;

    /**
     * The endpoint URL of the organization.
     * This is the URL to which you make API calls.
     * @var string
     */
    public $endpoint;

    /**
     * A logger that implements the \Psr\Log\LoggerInterface interface.
     * See the {@link Apigee\Drupal\WatchdogLogger} class for an example that
     * implements the Psr\Log\LoggerInterface.
     * @var \Psr\Log\LoggerInterface|null
     */
    public $logger;

    /**
     * The email address of the authenticated user in the organization.
     * @var null|string
     */
    public $user_mail;

    /**
     * @var array
     * Array of objects that may subscribe to receive events that various
     * objects may fire.
     * Elements are implementors of
     * Symfony\Component\EventDispatcher\EventSubscriberInterface
     */
    public $subscribers;

    /**
     * @var array
     * Array of HTTP options. The only options currently supported are
     * 'follow_location', 'connection_timeout' and 'timeout'.
     */
    public $http_options;

    /**
     * @var array
     * Array of callables to be called after each REST transaction. Each
     * callback should accept a single array parameter.
     */
    public $debug_callbacks;

    /**
     * @var string|null
     * User-Agent information to be added to the standard Guzzle UA header.
     */
    public $user_agent;

    /**
     * @var KeyValueStoreInterface|null
     */
    public $variable_store;

    /**
     * @var string
     * Optionally holds content to be sent in the Referer HTTP header.
     */
    public $referer;

    /**
     * @var bool
     */
    public $redirect_disable = FALSE;

    /**
     * Create an instance of OrgConfig.
     *
     * <p>The $options argument is an array containing the fields 'logger',
     * 'user_email', 'subscribers', 'debug_callbacks', and 'http_options'.</p>
     *
     * <p>For example:</p>
     * <pre>
     *   $logger = new Apigee\Drupal\WatchdogLogger();
     *   $logger::setLogThreshold($log_threshold);
     *   $user_mail = "<EMAIL>";
     *
     *   $options = array(
     *     'logger' => $logger,
     *     'user_mail' => $user_mail,
     *     'subscribers' => array(),
     *     'http_options' => array(
     *       'connection_timeout' => 10,
     *       'timeout' => 50,
     *     ),
     *     'variable_store' => new Apigee\Drupal\VariableCache()
     *   );
     * </pre>
     *
     * @param string $org_name
     * @param string $endpoint
     * @param string $user
     * @param string $pass
     * @param array $options
     */
    public function __construct($org_name, $endpoint, $user, $pass, $options = array())
    {
        $this->orgName = $org_name;
        $this->endpoint = $endpoint;

        $request_options = (array_key_exists('http_options', $options) ? $options['http_options'] : array());

        // Work around old bug in client implementations, wherein a key of
        // "connection_timeout" was passed instead of "connect_timeout".
        if (array_key_exists('connection_timeout', $request_options)) {
            $request_options['connect_timeout'] = $request_options['connection_timeout'];
            unset($request_options['connection_timeout']);
        }
        elseif (!array_key_exists('connect_timeout', $options)) {
            $request_options['connect_timeout'] = 10;
        }

        if (!array_key_exists('timeout', $options)) {
            $request_options['timeout'] = 10;
        }

        if (isset($request_options['follow_location'])) {
            $this->redirect_disable = !$request_options['follow_location'];
            unset($request_options['follow_location']);
        }

        $auth = (array_key_exists('auth', $options) ? $options['auth'] : 'basic');
        if ($auth != 'basic' && $auth != 'digest') {
            $auth = 'basic';
        }

        $request_options['auth'] = array($user, $pass, $auth);
        if (array_key_exists('referer', $options)) {
            $request_options['headers']['Referer'] = $options['referer'];
        }

        $proxy = null;
        if (!$proxy = getenv('HTTPS_PROXY')) {
          $proxy = getenv('HTTP_PROXY');
        }
        if (!empty($proxy)) {
            $request_options['proxy'] = $proxy;
        }

        $this->logger = array_key_exists('logger', $options) && $options['logger'] instanceof \Psr\Log\LoggerInterface ? $options['logger'] : new \Psr\Log\NullLogger();
        $this->user_mail = array_key_exists('user_mail', $options) ? $options['user_mail'] : null;
        $this->subscribers = array_key_exists('subscribers', $options) ? $options['subscribers'] : array();
        $this->http_options = $request_options;
        $this->debug_callbacks = array_key_exists('debug_callbacks', $options) ? $options['debug_callbacks'] : array();<commit_msg>DEVSOL-1561: Allow LoggerInterface implementation to be used as a subscriber<commit_after><?php
namespace Apigee\Util;

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Guzzle\Log\PsrLogAdapter;
use Guzzle\Plugin\Log\LogPlugin;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * A class that represents infomration about an Edge organization.
 */
class OrgConfig
{
    /**
     * A possible format of logs written by Guzzle's LogPlugin.
     * @see \Guzzle\Log\MessageFormatter
     */
    const LOG_SUBSCRIBER_FORMAT = ">>>>>>>>\n{request}\n<<<<<<<<\n{response}\n--------\n{curl_stderr}\n--------\nConnection time: {connect_time}\nTotal transaction time: {total_time}";

    /**
     * The organization name.
     * @var string
     */
    public $orgName;

    /**
     * The endpoint URL of the organization.
     * This is the URL to which you make API calls.
     * @var string
     */
    public $endpoint;

    /**
     * A logger that implements the \Psr\Log\LoggerInterface interface.
     * See the {@link Apigee\Drupal\WatchdogLogger} class for an example that
     * implements the Psr\Log\LoggerInterface.
     * @var \Psr\Log\LoggerInterface|null
     */
    public $logger;

    /**
     * The email address of the authenticated user in the organization.
     * @var null|string
     */
    public $user_mail;

    /**
     * @var array
     * Array of objects that may subscribe to receive events that various
     * objects may fire.
     * Elements are implementors of
     * Symfony\Component\EventDispatcher\EventSubscriberInterface
     */
    public $subscribers;

    /**
     * @var array
     * Array of HTTP options. The only options currently supported are
     * 'follow_location', 'connection_timeout' and 'timeout'.
     */
    public $http_options;

    /**
     * @var array
     * Array of callables to be called after each REST transaction. Each
     * callback should accept a single array parameter.
     */
    public $debug_callbacks;

    /**
     * @var string|null
     * User-Agent information to be added to the standard Guzzle UA header.
     */
    public $user_agent;

    /**
     * @var KeyValueStoreInterface|null
     */
    public $variable_store;

    /**
     * @var string
     * Optionally holds content to be sent in the Referer HTTP header.
     */
    public $referer;

    /**
     * @var bool
     */
    public $redirect_disable = FALSE;

    /**
     * Create an instance of OrgConfig.
     *
     * <p>The $options argument is an array containing the fields 'logger',
     * 'user_email', 'subscribers', 'debug_callbacks', and 'http_options'.</p>
     *
     * <p>For example:</p>
     * <pre>
     *   $logger = new Apigee\Drupal\WatchdogLogger();
     *   $logger::setLogThreshold($log_threshold);
     *   $user_mail = "<EMAIL>";
     *
     *   $options = array(
     *     'logger' => $logger,
     *     'user_mail' => $user_mail,
     *     'subscribers' => array(),
     *     'http_options' => array(
     *       'connection_timeout' => 10,
     *       'timeout' => 50,
     *     ),
     *     'variable_store' => new Apigee\Drupal\VariableCache()
     *   );
     * </pre>
     *
     * @param string $org_name
     * @param string $endpoint
     * @param string $user
     * @param string $pass
     * @param array $options
     */
    public function __construct($org_name, $endpoint, $user, $pass, $options = array())
    {
        $this->orgName = $org_name;
        $this->endpoint = $endpoint;

        $request_options = (array_key_exists('http_options', $options) ? $options['http_options'] : array());

        // Work around old bug in client implementations, wherein a key of
        // "connection_timeout" was passed instead of "connect_timeout".
        if (array_key_exists('connection_timeout', $request_options)) {
            $request_options['connect_timeout'] = $request_options['connection_timeout'];
            unset($request_options['connection_timeout']);
        }
        elseif (!array_key_exists('connect_timeout', $options)) {
            $request_options['connect_timeout'] = 10;
        }

        if (!array_key_exists('timeout', $options)) {
            $request_options['timeout'] = 10;
        }

        if (isset($request_options['follow_location'])) {
            $this->redirect_disable = !$request_options['follow_location'];
            unset($request_options['follow_location']);
        }

        $auth = (array_key_exists('auth', $options) ? $options['auth'] : 'basic');
        if ($auth != 'basic' && $auth != 'digest') {
            $auth = 'basic';
        }

        $request_options['auth'] = array($user, $pass, $auth);
        if (array_key_exists('referer', $options)) {
            $request_options['headers']['Referer'] = $options['referer'];
        }

        $proxy = null;
        if (!$proxy = getenv('HTTPS_PROXY')) {
          $proxy = getenv('HTTP_PROXY');
        }
        if (!empty($proxy)) {
            $request_options['proxy'] = $proxy;
        }

        $subscribers = array();
        if (array_key_exists('subscribers', $options) && is_array($options['subscribers'])) {
            foreach ($options['subscribers'] as $subscriber) {
                if ($subscriber instanceof LoggerInterface) {
                    if (array_key_exists('log_subscriber_format', $options)) {
                        $log_subscriber_format = $options['log_subscriber_format'];
                    }
                    else {
                        $log_subscriber_format = self::LOG_SUBSCRIBER_FORMAT;
                    }
                    $subscribers[] = new LogPlugin(new PsrLogAdapter($subscriber), $log_subscriber_format);
                }
                elseif ($subscriber instanceof EventSubscriberInterface) {
                    $subscribers[] = $subscriber;
                }
            }
        }

        $this->logger = array_key_exists('logger', $options) && $options['logger'] instanceof LoggerInterface ? $options['logger'] : new NullLogger();
        $this->user_mail = array_key_exists('user_mail', $options) ? $options['user_mail'] : null;
        $this->subscribers = $subscribers;
        $this->http_options = $request_options;
        $this->debug_callbacks = array_key_exists('debug_callbacks', $options) ? $options['debug_callbacks'] : array();
{'fraction_non_alphanumeric': 0.1345713782784721, 'fraction_numerical': 0.0017602534765006161, 'mean_word_length': 2.4123123123123125, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 55, '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': '4859608', 'n_tokens_mistral': 3339, 'n_tokens_neox': 3265, 'n_words': 777}