<commit_before><?php

// Include the kaltura client
require_once(  dirname( __FILE__ ) . '/kaltura_client_v3/KalturaClient.php' );
// Include the kaltura named multi request helper class: 
require_once(  dirname( __FILE__ ) . '/KalturaNamedMultiRequest.php');

class KalturaClientHelper extends KalturaClient {

	private $cacheString = 'cached-dispatcher';

	// Check if the server cached the result by search for "cached-dispatcher" in the request headers
	public function isCacheable() 
	{
		foreach( $this->getResponseHeaders() as $value ) {
			if( strpos($value, $this->cacheString) !== false ) {
				return true;
			}
		}
		$this->log('Cache key: ' . $this->cacheString . ' was not found in request headers: ' . print_r($this->getResponseHeaders(), true));
		return false;
	}
}<commit_msg>Kaltura Client helper will now be responsible to initiate our client<commit_after><?php

// Include the kaltura client
require_once(  dirname( __FILE__ ) . '/kaltura_client_v3/KalturaClient.php' );
// Include the kaltura named multi request helper class: 
require_once(  dirname( __FILE__ ) . '/KalturaNamedMultiRequest.php');

class KalturaClientHelper {

	private $options = array();

	function __construct( $options ) {
		$this->options = $options;
	}

	private function getOption( $key ) {
		if( isset($this->options[ $key ] ) ) {
			return $this->options[ $key ];
		}
		return null;
	}

	function getClient() {

		// Check if client already exists
		if( ! $this->client ) {
			$conf = new KalturaConfiguration( null );

			$conf->serviceUrl = $this->getOption('ServiceUrl');
			$conf->serviceBase = $this->getOption( 'ServiceBase' );
			$conf->clientTag = $this->getOption('ClientTag');
			$conf->curlTimeout = $this->getOption('ServiceTimeout');
			$conf->userAgent = $this->getOption('UserAgent');
			$conf->verifySSL = false;
			$conf->requestHeaders = $this->getOption('RequestHeaders');

			if( $this->getOption('Logger') ) {
				$conf->setLogger( $this->getOption('Logger') );
			}
			
			$this->client = new KalturaClient( $conf );

			if( $this->getOption('KS') ) {
				$this->getKS( $this->getOption('KS') );
			} else if( $this->getOption('WidgetId') ) {
				$this->generateKS( $this->getOption('WidgetId') );
			}
		}

		return $this->client;		
	}

	public function generateKS( $widgetId ) {
		try{
			$session = $this->getClient()->session->startWidgetSession( $widgetId );
			$this->ks = $session->ks;
			$this->partnerId = $session->partnerId;
		} catch ( Exception $e ){
			throw new Exception( KALTURA_GENERIC_SERVER_ERROR . "\n" . $e->getMessage() );
		}
		// Save KS to the client
		$this->getClient()->setKS( $this->ks );
		return $session;
	}

	public function setKS( $ks ) {
		if( isset($ks) ) {
			$this->ks = $ks;
		}
		$this->getClient()->setKS( $ks ) ;
	}

	public function getKS() {
		return ($this->ks) ? $this->ks : null;
	}
}
{'fraction_non_alphanumeric': 0.1650893796004206, 'fraction_numerical': 0.0007010164738871364, 'mean_word_length': 3.886986301369863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '7482791', 'n_tokens_mistral': 1047, 'n_tokens_neox': 941, 'n_words': 216}