<commit_before><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2011, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\data\source\mongo_db;

use lithium\util\Set;

class Exporter extends \lithium\core\StaticObject {

	protected static $_map = array(
		'MongoId'      => 'id',
		'MongoDate'    => 'date',
		'MongoCode'    => 'code',
		'MongoBinData' => 'binary',
		'datetime'     => 'date',
		'timestamp'    => 'date',
		'int'          => 'integer'
	);

	public static function get($type, $export, array $options = array()) {
		$defaults = array('whitelist' => array());
		$options += $defaults;

		if (!method_exists(get_called_class(), $method = "_{$type}") || !$export) {
			return;
		}
		return static::$method($export, array('finalize' => true) + $options);
	}

	public static function cast($data, $schema, $database, array $options = array()) {
		$defaults = array(
			'handlers' => array(), 'model' => null, 'arrays' => true
		);
		$options += $defaults;

		foreach ($data as $key => $value) {
			$pathKey = isset($options['pathKey']) ? "{$options['pathKey']}.{$key}" : $key;
			$field = (isset($schema[$pathKey]) ? $schema[$pathKey] : array());
			$field += array('type' => null, 'array' => null);
			$data[$key] = static::_cast($value, $field, $database, compact('pathKey') + $options);
		}
		return $data;
	}

	protected static function _cast($value, $def, $database, $options) {
		if (is_object($value)) {
			return $value;<commit_msg>Fixing a minor condition when receiving an empty key, Exporter::cast would add it to the pathkey,  this behavior is improper and would be technically unfetchable via object return.<commit_after><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2011, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\data\source\mongo_db;

use lithium\util\Set;

class Exporter extends \lithium\core\StaticObject {

	protected static $_map = array(
		'MongoId'      => 'id',
		'MongoDate'    => 'date',
		'MongoCode'    => 'code',
		'MongoBinData' => 'binary',
		'datetime'     => 'date',
		'timestamp'    => 'date',
		'int'          => 'integer'
	);

	public static function get($type, $export, array $options = array()) {
		$defaults = array('whitelist' => array());
		$options += $defaults;

		if (!method_exists(get_called_class(), $method = "_{$type}") || !$export) {
			return;
		}
		return static::$method($export, array('finalize' => true) + $options);
	}

	public static function cast($data, $schema, $database, array $options = array()) {
		$defaults = array(
			'handlers' => array(), 'model' => null, 'arrays' => true
		);
		$options += $defaults;

		foreach ($data as $key => $value) {
			$pathKey = !empty($options['pathKey']) ? "{$options['pathKey']}.{$key}" : $key;
			$field = (isset($schema[$pathKey]) ? $schema[$pathKey] : array());
			$field += array('type' => null, 'array' => null);
			$data[$key] = static::_cast($value, $field, $database, compact('pathKey') + $options);
		}
		return $data;
	}

	protected static function _cast($value, $def, $database, $options) {
		if (is_object($value)) {
			return $value;
{'fraction_non_alphanumeric': 0.19214501510574017, 'fraction_numerical': 0.002416918429003021, 'mean_word_length': 3.98644578313253, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '6254035', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1088, 'n_words': 276}