<commit_before><?php
include_once 'JWT.php';
/**
 * Twilio API Capability Token generator
 *
 * @category Services
 * @package  Services_Twilio
 * @author <NAME> <<EMAIL>>
 * @license  http://creativecommons.org/licenses/MIT/ MIT
 */
class Services_Twilio_API_Capability
{
	protected $accountSid;
	protected $authToken;
	private $version;
	private $friendlyName;
	private $policies;

	public function __construct($accountSid, $authToken, $version, $friendlyName)
	{
		$this->accountSid = $accountSid;
		$this->authToken = $authToken;
		$this->version = $version;
		$this->friendlyName = $friendlyName;
		$this->policies = array();
	}

	public function addPolicy($url, $method, $queryFilter = array(), $postFilter = array(), $allow = true) {
		$policy = new Policy($url, $method, $queryFilter, $postFilter, $allow);
		array_push($this->policies, $policy);
	}

	public function allow($url, $method, $queryFilter = array(), $postFilter = array()) {
		$this->addPolicy($url, $method, $queryFilter, $postFilter, true);
	}

	public function deny($url, $method, $queryFilter = array(), $postFilter = array()) {
		$this->addPolicy($url, $method, $queryFilter, $postFilter, false);
	}

	/**
	 * Generates a new token based on the credentials and permissions that
	 * previously has been granted to this token.
	 *
	 * @param $ttl the expiration time of the token (in seconds). Default
	 *        value is 3600 (1hr)
	 * @param $extraAttributes extra attributes to be tied to the jwt.
	 * @return the newly generated token that is valid for $ttl seconds
	 */
	public function generateToken($ttl = 3600, $extraAttributes = null)
	{
		$payload = array(
			'version' => $this->version,
			'friendly_name' => $this->friendlyName,
			'policies' => array(),
			'iss' => $this->accountSid,
			'exp' => time() + $ttl
		);
		if(isset($extraAttributes)) {
			foreach ($extraAttributes as $key => $value) {
				$payload[$key] = $value;
			}
		}<commit_msg>Read deprecated methods to remove the need for a major version bump<commit_after><?php
include_once 'JWT.php';
/**
 * Twilio API Capability Token generator
 *
 * @category Services
 * @package  Services_Twilio
 * @author <NAME> <<EMAIL>>
 * @license  http://creativecommons.org/licenses/MIT/ MIT
 */
class Services_Twilio_API_Capability
{
	protected $accountSid;
	protected $authToken;
	private $version;
	private $friendlyName;
	private $policies;

	public function __construct($accountSid, $authToken, $version, $friendlyName)
	{
		$this->accountSid = $accountSid;
		$this->authToken = $authToken;
		$this->version = $version;
		$this->friendlyName = $friendlyName;
		$this->policies = array();
	}

	public function addPolicyDeconstructed($url, $method, $queryFilter = array(), $postFilter = array(), $allow = true) {
		$policy = new Policy($url, $method, $queryFilter, $postFilter, $allow);
		array_push($this->policies, $policy);
	}

	public function allow($url, $method, $queryFilter = array(), $postFilter = array()) {
		$this->addPolicyDeconstructed($url, $method, $queryFilter, $postFilter, true);
	}

	public function deny($url, $method, $queryFilter = array(), $postFilter = array()) {
		$this->addPolicyDeconstructed($url, $method, $queryFilter, $postFilter, false);
	}

	/**
	 * @deprecated Please use {Services_Twilio_API_Capability.allow, Services_Twilio_API_Capability.disallow} instead
	 */
	public function addPolicy($policy) {
		array_push($this->policies, $policy);
	}

	/**
	 * @deprecated Please use {Services_Twilio_API_Capability.allow, Services_Twilio_API_Capability.disallow} instead
	 */
	public function generatePolicy($url, $method, $queryFilter = array(), $postFilter = array(), $allow = true)
	{
		$policy = new Policy($url, $method, $queryFilter, $postFilter, $allow);
		return $policy;
	}

	/**
	 * @deprecated Please use {Services_Twilio_API_Capability.allow, Services_Twilio_API_Capability.disallow} instead
	 */
	public function generateAndAddPolicy($url, $method, $queryFilter = array(), $postFilter = array(), $allow = true) {
		$policy = $this->generatePolicy($url, $method, $queryFilter, $postFilter, $allow);
		$this->addPolicy($policy);
	}

	/**
	 * Generates a new token based on the credentials and permissions that
	 * previously has been granted to this token.
	 *
	 * @param $ttl the expiration time of the token (in seconds). Default
	 *        value is 3600 (1hr)
	 * @param $extraAttributes extra attributes to be tied to the jwt.
	 * @return the newly generated token that is valid for $ttl seconds
	 */
	public function generateToken($ttl = 3600, $extraAttributes = null)
	{
		$payload = array(
			'version' => $this->version,
			'friendly_name' => $this->friendlyName,
			'policies' => array(),
			'iss' => $this->accountSid,
			'exp' => time() + $ttl
		);
		if(isset($extraAttributes)) {
			foreach ($extraAttributes as $key => $value) {
				$payload[$key] = $value;
			}
		}
{'fraction_non_alphanumeric': 0.1474398519432449, 'fraction_numerical': 0.003701418877236274, 'mean_word_length': 4.668997668997669, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 46, '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': '4604879', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1527, 'n_words': 414}