<commit_before><?php
namespace Hashid\Model\Behavior;

use ArrayObject;
use Cake\Collection\Collection;
use Cake\Core\Configure;
use Cake\Database\ExpressionInterface;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
use Cake\ORM\Behavior;
use Cake\ORM\Query;
use Cake\ORM\Table;
use Hashid\Model\HashidTrait;

/**
 * @author <NAME>
 * @license MIT
 */
class HashidBehavior extends Behavior {

	use HashidTrait;

	const HID = 'hid';

	/**
	 * @var \Hashids\Hashids
	 */
	protected $_hashids;

	/**
	 * @var \Cake\ORM\Table
	 */
	protected $_table;

	/**
	 * @var array|string
	 */
	protected $_primaryKey;

	/**
	 * @var array
	 */
	protected $_defaultConfig = [
		'salt' => null, // Please provide your own salt via Configure key 'Hashid.salt'
		'field' => null, // To populate upon find() and save(), false to deactivate
		'debug' => null, // Auto-detect from Configure::read('debug')
		'minHashLength' => 0, // You can overwrite the Hashid defaults
		'alphabet' => null, // You can overwrite the Hashid defaults
		'recursive' => false, // Also transform nested entities
		'findFirst' => false, // Either true or 'first' or 'firstOrFail'
		'implementedFinders' => [
			'hashed' => 'findHashed',
		]
	];

	/**
	 * Constructor
	 *
	 * Merges config with the default and store in the config property
	 *
	 * Does not retain a reference to the Table object. If you need this
	 * you should override the constructor.
	 *
	 * @param \Cake\ORM\Table $table The table this behavior is attached to.
	 * @param array $config The config for this behavior.
	 */
	public function __construct(Table $table, array $config = []) {
		$defaults = (array)Configure::read('Hashid');
		parent::__construct($table, $config + $defaults);

		$this->_table = $table;
		$this->_primaryKey = $table->getPrimaryKey();

		if ($this->_config['salt'] === null) {
			$this->_config['salt'] = Configure::read('Security.salt') ? sha1(Configure::read('Security.salt')) : null;
		}
		if ($this->_config['debug'] === null) {
			$this->_config['debug'] = Configure::read('debug');
		}
		if ($this->_config['field'] === null) {
			$this->_config['field'] = $this->_primaryKey;
		}
	}

	/**
	 * @param \Cake\Event\Event $event
	 * @param \Cake\ORM\Query $query
	 * @param \ArrayObject $options
	 * @param bool $primary
	 * @return void
	 */
	public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) {
		if (!$primary && !$this->_config['recursive']) {<commit_msg>Dont allow array primary keys.<commit_after><?php
namespace Hashid\Model\Behavior;

use ArrayObject;
use Cake\Collection\Collection;
use Cake\Core\Configure;
use Cake\Database\ExpressionInterface;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
use Cake\ORM\Behavior;
use Cake\ORM\Query;
use Cake\ORM\Table;
use Hashid\Model\HashidTrait;
use RuntimeException;

/**
 * @author <NAME>
 * @license MIT
 */
class HashidBehavior extends Behavior {

	use HashidTrait;

	const HID = 'hid';

	/**
	 * @var \Hashids\Hashids
	 */
	protected $_hashids;

	/**
	 * @var \Cake\ORM\Table
	 */
	protected $_table;

	/**
	 * @var string
	 */
	protected $_primaryKey;

	/**
	 * @var array
	 */
	protected $_defaultConfig = [
		'salt' => null, // Please provide your own salt via Configure key 'Hashid.salt'
		'field' => null, // To populate upon find() and save(), false to deactivate
		'debug' => null, // Auto-detect from Configure::read('debug')
		'minHashLength' => 0, // You can overwrite the Hashid defaults
		'alphabet' => null, // You can overwrite the Hashid defaults
		'recursive' => false, // Also transform nested entities
		'findFirst' => false, // Either true or 'first' or 'firstOrFail'
		'implementedFinders' => [
			'hashed' => 'findHashed',
		]
	];

	/**
	 * Constructor
	 *
	 * Merges config with the default and store in the config property
	 *
	 * Does not retain a reference to the Table object. If you need this
	 * you should override the constructor.
	 *
	 * @param \Cake\ORM\Table $table The table this behavior is attached to.
	 * @param array $config The config for this behavior.
	 */
	public function __construct(Table $table, array $config = []) {
		$defaults = (array)Configure::read('Hashid');
		parent::__construct($table, $config + $defaults);

		$this->_table = $table;
		$primaryKey = $table->getPrimaryKey();
		if (is_array($primaryKey)) {
			throw new RuntimeException('Array primary keys are not supported yet for hash IDs.');
		}
		$this->_primaryKey = $primaryKey;

		if ($this->_config['salt'] === null) {
			$this->_config['salt'] = Configure::read('Security.salt') ? sha1(Configure::read('Security.salt')) : null;
		}
		if ($this->_config['debug'] === null) {
			$this->_config['debug'] = Configure::read('debug');
		}
		if ($this->_config['field'] === null) {
			$this->_config['field'] = $this->_primaryKey;
		}
	}

	/**
	 * @param \Cake\Event\Event $event
	 * @param \Cake\ORM\Query $query
	 * @param \ArrayObject $options
	 * @param bool $primary
	 * @return void
	 */
	public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) {
		if (!$primary && !$this->_config['recursive']) {
{'fraction_non_alphanumeric': 0.15910867865519937, 'fraction_numerical': 0.0007818608287724785, 'mean_word_length': 3.822808671065033, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, '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': '2961981', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1596, 'n_words': 458}