<commit_before><?php declare(strict_types=1);


namespace BFITech\ZapAdmin;


use BFITech\ZapCore\Common;
use BFITech\ZapCore\Logger;
use BFITech\ZapStore\SQL;
use BFITech\ZapStore\SQLError;
use BFITech\ZapOAuth\OAuthError;
use BFITech\ZapOAuth\OAuthCommon;
use BFITech\ZapOAuth\OAuth10Permission;
use BFITech\ZapOAuth\OAuth10Action;
use BFITech\ZapOAuth\OAuth20Permission;
use BFITech\ZapOAuth\OAuth20Action;


/**
 * OAuthManage class.
 *
 * General workflow:
 *
 * 1. Extend this class, e.g. OAuthManageCustom, with method
 *    fetch_profile() overridden.
 * 2. Instantiate OAuthManageCustom $so. Let's call this instance
 *    super-oauth.
 * 3. Register services with $so->add_service() with
 *    appropriate service parameters.
 * 4. Use $perm = $so->get_permission_instance() that will
 *    initiate sequence of acquiring access token, along with
 *    access token secret for OAuth1 and refresh token for OAuth2.
 * 5. When access token is obtained, use it to make API calls
 *    with $act = $so->get_action_instance(). $act->request()
 *    wraps regular API calls. Specific to OAuth2, there is
 *    $act->refresh() that requests access token given a
 *    previously-obtained refresh token.
 *
 * To override default http client, e.g. for testing, create a method
 * http_client_custom on your super-oauth, with the exact same args with
 * those in Common::http_client.
 *
 * @SuppressWarnings(PHPMD.LongVariable)
 */
class OAuthManage extends AuthManage {

	/** Redirect URL after successful callback. */
	public $callback_ok_redirect = null;

	/** Redirect URL after failed callback. */
	public $callback_fail_redirect = null;

	/** Service info hash table. */
	private $services = [];

	/**
	 * Configure.
	 *
	 * Available configurables:
	 *   - (bool)check_table: Check table existence.
	 *
	 * @param string $key Config key name.
	 * @param string $val Config value.
	 * @return OAuthManage Instance of this class for chaining.
	 * @throws BFITech.ZapStore.SQLError on table creation failure.
	 */
	public function config(string $key, string $val=null) {
		switch ($key) {
			case 'check_table':
				if ($val)
					$this->create_table();
				break;
		}
		return $this;
	}

	/**
	 * Create OAuth session table.
	 *<commit_msg>Looser type for OAuthManage::config second param.<commit_after><?php declare(strict_types=1);


namespace BFITech\ZapAdmin;


use BFITech\ZapCore\Common;
use BFITech\ZapCore\Logger;
use BFITech\ZapStore\SQL;
use BFITech\ZapStore\SQLError;
use BFITech\ZapOAuth\OAuthError;
use BFITech\ZapOAuth\OAuthCommon;
use BFITech\ZapOAuth\OAuth10Permission;
use BFITech\ZapOAuth\OAuth10Action;
use BFITech\ZapOAuth\OAuth20Permission;
use BFITech\ZapOAuth\OAuth20Action;


/**
 * OAuthManage class.
 *
 * General workflow:
 *
 * 1. Extend this class, e.g. OAuthManageCustom, with method
 *    fetch_profile() overridden.
 * 2. Instantiate OAuthManageCustom $so. Let's call this instance
 *    super-oauth.
 * 3. Register services with $so->add_service() with
 *    appropriate service parameters.
 * 4. Use $perm = $so->get_permission_instance() that will
 *    initiate sequence of acquiring access token, along with
 *    access token secret for OAuth1 and refresh token for OAuth2.
 * 5. When access token is obtained, use it to make API calls
 *    with $act = $so->get_action_instance(). $act->request()
 *    wraps regular API calls. Specific to OAuth2, there is
 *    $act->refresh() that requests access token given a
 *    previously-obtained refresh token.
 *
 * To override default http client, e.g. for testing, create a method
 * http_client_custom on your super-oauth, with the exact same args with
 * those in Common::http_client.
 *
 * @SuppressWarnings(PHPMD.LongVariable)
 */
class OAuthManage extends AuthManage {

	/** Redirect URL after successful callback. */
	public $callback_ok_redirect = null;

	/** Redirect URL after failed callback. */
	public $callback_fail_redirect = null;

	/** Service info hash table. */
	private $services = [];

	/**
	 * Configure.
	 *
	 * Available configurables:
	 *   - (bool)check_table: Check table existence.
	 *
	 * @param string $key Config key name.
	 * @param any $val Config value.
	 * @return OAuthManage Instance of this class for chaining.
	 * @throws BFITech.ZapStore.SQLError on table creation failure.
	 */
	public function config(string $key, $val=null) {
		switch ($key) {
			case 'check_table':
				if ((bool)$val)
					$this->create_table();
				break;
		}
		return $this;
	}

	/**
	 * Create OAuth session table.
	 *
{'fraction_non_alphanumeric': 0.10587975243147657, 'fraction_numerical': 0.007515473032714412, 'mean_word_length': 3.7832980972515857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '191518', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1442, 'n_words': 440}