<commit_before><?php

/*
  +------------------------------------------------------------------------+
  | Phalcon Framework                                                      |
  +------------------------------------------------------------------------+
  | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file docs/LICENSE.txt.                        |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to <EMAIL> so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Authors: <NAME> <<EMAIL>>                      |
  |          <NAME> <<EMAIL>>                         |
  +------------------------------------------------------------------------+
*/

namespace Phalcon\Translate\Adapter;

use Phalcon\Translate\Adapter,
	Phalcon\Translate\AdapterInterface,
	Phalcon\Translate\Exception;

class Database extends Adapter implements AdapterInterface
{

	protected $_options;

	/**
	 * Phalcon\Translate\Adapter\Database constructor
	 *
	 * @param array $options
	 */
	public function __construct($options)
	{

		if (!isset($options['db'])) {
			throw new Exception("Parameter 'db' is required");
		}

		if (!isset($options['table'])) {
			throw new Exception("Parameter 'table' is required");
		}
		
                if (!isset($options['language'])) {
                    throw new Exception("Parameter 'language' is required");
                }

		$this->_options = $options;
	}

	/**
	 * Returns the translation related to the given key
	 *
	 * @param	string $index
	 * @param	array $placeholders
	 * @return	string
	 */
	public function query($index, $placeholders=null)
	{

		$options = $this->_options;

		$translation = $options['db']->fetchOne("SELECT value FROM " . $options['table'] . " WHERE language = '" . $options['language'] . "' AND key_name = ?", null, array($index));
		if (!$translation) {
			return $index;
		}

		if ($placeholders == null) {
			return $translation['value'];
		}

		if (is_array($placeholders)) {
			foreach ($placeholders as $key => $value) {
				$translation['value'] = str_replace('%' . $key . '%', $value, $translation['value']);
			}
		}

		return $translation['value'];
	}

	/**
	 * Check whether is defined a translation key in the database
	 *
	 * @param 	string $index
	 * @return	bool
	 */
	public function exists($index)
	{
		$exists = $options['db']->fetchOne("SELECT COUNT(*) FROM " . $options['table'] . " WHERE key_name = ?0", null, array($index));
		return $exists[0] > 0;
	}

}<commit_msg>fix for undefined variable<commit_after><?php

/*
  +------------------------------------------------------------------------+
  | Phalcon Framework                                                      |
  +------------------------------------------------------------------------+
  | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com)       |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file docs/LICENSE.txt.                        |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to <EMAIL> so we can send you a copy immediately.       |
  +------------------------------------------------------------------------+
  | Authors: <NAME> <<EMAIL>>                      |
  |          <NAME> <<EMAIL>>                         |
  +------------------------------------------------------------------------+
*/

namespace Phalcon\Translate\Adapter;

use Phalcon\Translate\Adapter,
	Phalcon\Translate\AdapterInterface,
	Phalcon\Translate\Exception;

class Database extends Adapter implements AdapterInterface
{

	protected $_options;

	/**
	 * Phalcon\Translate\Adapter\Database constructor
	 *
	 * @param array $options
	 */
	public function __construct($options)
	{

		if (!isset($options['db'])) {
			throw new Exception("Parameter 'db' is required");
		}

		if (!isset($options['table'])) {
			throw new Exception("Parameter 'table' is required");
		}
		
                if (!isset($options['language'])) {
                    throw new Exception("Parameter 'language' is required");
                }

		$this->_options = $options;
	}

	/**
	 * Returns the translation related to the given key
	 *
	 * @param	string $index
	 * @param	array $placeholders
	 * @return	string
	 */
	public function query($index, $placeholders=null)
	{

		$options = $this->_options;

		$translation = $options['db']->fetchOne("SELECT value FROM " . $options['table'] . " WHERE language = '" . $options['language'] . "' AND key_name = ?", null, array($index));
		if (!$translation) {
			return $index;
		}

		if ($placeholders == null) {
			return $translation['value'];
		}

		if (is_array($placeholders)) {
			foreach ($placeholders as $key => $value) {
				$translation['value'] = str_replace('%' . $key . '%', $value, $translation['value']);
			}
		}

		return $translation['value'];
	}

	/**
	 * Check whether is defined a translation key in the database
	 *
	 * @param 	string $index
	 * @return	bool
	 */
	public function exists($index)
	{
		$options = $this->_options;

		$exists = $options['db']->fetchOne("SELECT COUNT(*) FROM " . $options['table'] . " WHERE key_name = ?0", null, array($index));
		return $exists[0] > 0;
	}

}
{'fraction_non_alphanumeric': 0.24735945485519592, 'fraction_numerical': 0.003747870528109029, 'mean_word_length': 1.5693654266958426, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1780774', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1460, 'n_words': 411}