<commit_before><?php

/**
 * Fetch item from a remote site using the file_get_contents php builtin.
 *
 * Not really a cache, unless the url points to a caching proxy.  This is more the backend of feed, made available through the cache interface.
 *
 * PHP version 5.3
 *
 * @category   Wordpress plugin
 * @package    Data Feed
 * @author     <NAME> <<EMAIL>>
 * @copyright  2015 <NAME>
 * @license    GNU AFFERO GENERAL PUBLIC LICENSE version 3 http://www.gnu.org/licenses/agpl.html
 * @version    Git: $Id$
 * @link       https://github.com/akvo/akvo-json-data-plugin
 * @since      File available since Release 1.0
 */

namespace DataFeed\Cache;

/**
 * Curl implementation of feed cache interface.
 */
class FileGetContentsFeedCache implements FeedCache
{

	/**
	 * @override FeedCache::getCurrentItem
	 */
	public function getCurrentItem($feedName, $url, $interval)
	{
		$parts = \parse_url( $url );

		if ( $parts === false ) {
			throw new FeedCacheException( 'The url of data feed ' . $feedName . ' cannot be parsed: "' . $url . '"' );
		}

		if ( empty($parts['scheme']) ) {
			$parts['scheme'] = 'http';
		}

		if ( $parts['scheme'] !== 'http' && $parts['scheme'] !== 'https' ) {
			throw new FeedCacheException( 'Unsupported URL scheme for data feed ' . $feedName . ': "' . $parts['scheme'] . '"' );
		}

		$u = $parts['scheme'] . '://' . $parts['host'];

		if ( ! empty( $parts['port'] ) ) {
			$u .= ':' . $parts['port'];
		}

		$u .= $parts['path'];

		if ( ! empty($parts['query']) ) {
			$u .= '?' . $parts['query'];
		}

		if ( ! empty($parts['fragment']) ) {
			$u .= '#' . $parts['fragment'];
		}

		error_log('file get contents on ' . $u );

		$contents = file_get_contents( $u );

		$data = \json_decode( $contents );

		if ( $data === null ) {
			throw new FeedCacheException( 'The current data item in data feed ' . $feedName . ' could not be parsed.' );
		}

		return $data;
	}

	public function flush( $feedName )
	{
	}
}<commit_msg>[#9] Set assoc=true in json_decode call of FileGetContentsFeedCache->getCurrentItem to get an associative array back<commit_after><?php

/**
 * Fetch item from a remote site using the file_get_contents php builtin.
 *
 * Not really a cache, unless the url points to a caching proxy.  This is more the backend of feed, made available through the cache interface.
 *
 * PHP version 5.3
 *
 * @category   Wordpress plugin
 * @package    Data Feed
 * @author     <NAME> <<EMAIL>>
 * @copyright  2015 <NAME>
 * @license    GNU AFFERO GENERAL PUBLIC LICENSE version 3 http://www.gnu.org/licenses/agpl.html
 * @version    Git: $Id$
 * @link       https://github.com/akvo/akvo-json-data-plugin
 * @since      File available since Release 1.0
 */

namespace DataFeed\Cache;

/**
 * Curl implementation of feed cache interface.
 */
class FileGetContentsFeedCache implements FeedCache
{

	/**
	 * @override FeedCache::getCurrentItem
	 */
	public function getCurrentItem($feedName, $url, $interval)
	{
		$parts = \parse_url( $url );

		if ( $parts === false ) {
			throw new FeedCacheException( 'The url of data feed ' . $feedName . ' cannot be parsed: "' . $url . '"' );
		}

		if ( empty($parts['scheme']) ) {
			$parts['scheme'] = 'http';
		}

		if ( $parts['scheme'] !== 'http' && $parts['scheme'] !== 'https' ) {
			throw new FeedCacheException( 'Unsupported URL scheme for data feed ' . $feedName . ': "' . $parts['scheme'] . '"' );
		}

		$u = $parts['scheme'] . '://' . $parts['host'];

		if ( ! empty( $parts['port'] ) ) {
			$u .= ':' . $parts['port'];
		}

		$u .= $parts['path'];

		if ( ! empty($parts['query']) ) {
			$u .= '?' . $parts['query'];
		}

		if ( ! empty($parts['fragment']) ) {
			$u .= '#' . $parts['fragment'];
		}

		error_log('file get contents on ' . $u );

		$contents = file_get_contents( $u );

		$data = \json_decode( $contents, true );

		if ( $data === null ) {
			throw new FeedCacheException( 'The current data item in data feed ' . $feedName . ' could not be parsed.' );
		}

		return $data;
	}

	public function flush( $feedName )
	{
	}
}
{'fraction_non_alphanumeric': 0.17407499379190464, 'fraction_numerical': 0.0047181524708219515, 'mean_word_length': 3.0851926977687625, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4145438', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1303, 'n_words': 382}