<commit_before><?php
/**
 * EMongoDB.php
 *
 * PHP version 5.2+
 *
 * @author		<NAME> <<EMAIL>>
 * @author		Invenzzia Group, open-source division of CleverIT company http://www.invenzzia.org
 * @copyright	2010 CleverIT http://www.cleverit.com.pl
 * @license		http://www.yiiframework.com/license/ BSD license
 * @version		1.3
 * @category	ext
 * @package		ext.YiiMongoDbSuite
 *
 */

/**
 * EMongoDB
 *
 * This is merge work of tyohan, <NAME> and mine
 */
class EMongoDB extends CApplicationComponent
{
	/**
     * @var string host:port
     *
     * Correct syntax is:
     * mongodb://[username:password@]host1[:port1][,host2[:port2:],...]
     *
     * @example mongodb://localhost:27017
     */
    public $connectionString;

    /**
	 * @var boolean $autoConnect whether the Mongo connection should be automatically established when
	 * the component is being initialized. Defaults to true. Note, this property is only
	 * effective when the EMongoDB object is used as an application component.
	 */
	public $autoConnect = true;

	/**
     * @var false|string $persistentConnection false for non-persistent connection, string for persistent connection id to use
     */
    public $persistentConnection = false;

    /**
     * @var string $dbName name of the Mongo database to use
     */
    public $dbName = null;

    /**
     * @var MongoDB $_mongoDb instance of MongoDB driver
     */
    private $_mongoDb;

    /**
     * @var Mongo $_mongoConnection instance of MongoDB driver
     */
	private $_mongoConnection;

	/**
	 * If set to TRUE all internal DB operations will use FSYNC flag with data modification requests
	 *
	 * Generally you should whant to have this set to TRUE, exception from this is when You do massive
	 * inserts/updates/deletes with this set to TRUE they will be horribly slow
	 *
	 * @var boolean $fsyncFlag state of FSYNC flag to use with internal connections
	 */
	public $fsyncFlag=true;

	/**
	 * If set to TRUE all internal DB operations will use SAFE flag with data modification requests
	 *
	 * Generally you should whant to have this set to TRUE if you want to
	 * check inserts/updates/deletes actions
	 *
	 * @var boolean $safeFlag state of SAFE flag
	 */
	public $safeFlag=true;

	/**
	 * If set to TRUE findAll* methods of models, will return {@see EMongoCursor} instead of
	 * raw array of models.
	 *
	 * Generally you should whant to have this set to TRUE as cursor use lazy-loading/instaninating of
	 * models, this is set to FALSE, by default to keep backwards compatibility.
	 *
	 * Note: {@see EMongoCursor} does not implement ArrayAccess interface and cannot be used like an array,
	 * because offset access to cursor is highly ineffective and pointless.
	 *
	 * @var boolean $useCursor state of Use Cursor flag
	 */
	public $useCursor=false;

	/**
	 * Connect to DB if connection is already connected this method doeas nothing
	 */
	public function connect()
	{
		if(!$this->getConnection()->connected)
			return $this->getConnection()->connect();
	}

	/**
	 * Returns Mongo connection instance if not exists will create new
	 *
	 * @return Mongo
	 * @throws EMongoException
	 */
	public function getConnection()
	{
		if($this->_mongoConnection === null)
		{
			try
			{
				Yii::trace('Opening MongoDB connection', 'ext.MongoDb.EMongoDB');
				if(empty($this->connectionString))
					throw new EMongoException(Yii::t('yii', 'EMongoDB.connectionString cannot be empty.'));

				if($this->persistentConnection !== false)
					$this->_mongoConnection = new Mongo($this->connectionString, array(
						'connect'=>$this->autoConnect,
						'persist'=>$this->persistentConnection
					));<commit_msg>Change the default state of FSync and Safe flags to MongoDB default<commit_after><?php
/**
 * EMongoDB.php
 *
 * PHP version 5.2+
 *
 * @author		<NAME> <<EMAIL>>
 * @author		Invenzzia Group, open-source division of CleverIT company http://www.invenzzia.org
 * @copyright	2010 CleverIT http://www.cleverit.com.pl
 * @license		http://www.yiiframework.com/license/ BSD license
 * @version		1.3
 * @category	ext
 * @package		ext.YiiMongoDbSuite
 *
 */

/**
 * EMongoDB
 *
 * This is merge work of tyohan, <NAME> and mine
 */
class EMongoDB extends CApplicationComponent
{
	/**
     * @var string host:port
     *
     * Correct syntax is:
     * mongodb://[username:password@]host1[:port1][,host2[:port2:],...]
     *
     * @example mongodb://localhost:27017
     */
    public $connectionString;

    /**
	 * @var boolean $autoConnect whether the Mongo connection should be automatically established when
	 * the component is being initialized. Defaults to true. Note, this property is only
	 * effective when the EMongoDB object is used as an application component.
	 */
	public $autoConnect = true;

	/**
     * @var false|string $persistentConnection false for non-persistent connection, string for persistent connection id to use
     */
    public $persistentConnection = false;

    /**
     * @var string $dbName name of the Mongo database to use
     */
    public $dbName = null;

    /**
     * @var MongoDB $_mongoDb instance of MongoDB driver
     */
    private $_mongoDb;

    /**
     * @var Mongo $_mongoConnection instance of MongoDB driver
     */
	private $_mongoConnection;

	/**
	 * If set to TRUE all internal DB operations will use FSYNC flag with data modification requests,
	 * in other words, all write operations will have to wait for a disc sync!
	 *
	 * MongoDB default value for this flag is: FALSE.
	 *
	 * @var boolean $fsyncFlag state of FSYNC flag to use with internal connections (global scope)
	 */
	public $fsyncFlag = false;

	/**
	 * If set to TRUE all internal DB operations will use SAFE flag with data modification requests.
	 *
	 * When SAFE flag is set to TRUE driver will wait for the response from DB, and throw an exception
	 * if something went wrong, is fet to false, driver will only send operation to DB but will not wait
	 * for response from DB.
	 *
	 * MongoDB default value for this flag is: FALSE.
	 *
	 * @var boolean $safeFlag state of SAFE flag (global scope)
	 */
	public $safeFlag = false;

	/**
	 * If set to TRUE findAll* methods of models, will return {@see EMongoCursor} instead of
	 * raw array of models.
	 *
	 * Generally you should want to have this set to TRUE as cursor use lazy-loading/instaninating of
	 * models, this is set to FALSE, by default to keep backwards compatibility.
	 *
	 * Note: {@see EMongoCursor} does not implement ArrayAccess interface and cannot be used like an array,
	 * because offset access to cursor is highly ineffective and pointless.
	 *
	 * @var boolean $useCursor state of Use Cursor flag (global scope)
	 */
	public $useCursor = false;

	/**
	 * Connect to DB if connection is already connected this method doeas nothing
	 */
	public function connect()
	{
		if(!$this->getConnection()->connected)
			return $this->getConnection()->connect();
	}

	/**
	 * Returns Mongo connection instance if not exists will create new
	 *
	 * @return Mongo
	 * @throws EMongoException
	 */
	public function getConnection()
	{
		if($this->_mongoConnection === null)
		{
			try
			{
				Yii::trace('Opening MongoDB connection', 'ext.MongoDb.EMongoDB');
				if(empty($this->connectionString))
					throw new EMongoException(Yii::t('yii', 'EMongoDB.connectionString cannot be empty.'));

				if($this->persistentConnection !== false)
					$this->_mongoConnection = new Mongo($this->connectionString, array(
						'connect'=>$this->autoConnect,
						'persist'=>$this->persistentConnection
					));
{'fraction_non_alphanumeric': 0.10119521912350597, 'fraction_numerical': 0.0045152722443559095, 'mean_word_length': 3.330649798734905, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '4457568', 'n_tokens_mistral': 2326, 'n_tokens_neox': 2094, 'n_words': 814}