<commit_before><?php

namespace Sokil\Mongo;

class Client
{
    private $_connection;
    
    private $_databasePool = array();
    
    public function __construct($dsn, array $options = array("connect" => true)) {
        $this->_connection = new \MongoClient($dsn, $options);
    }
    
    /**
     * 
     * @param tstring $name database name
     * @return \Sokil\Mongo\Database
     */
    public function getDatabase($name) {
        if(!isset($this->_databasePool[$name])) {
            $this->_databasePool[$name] = new Database($this->_connection->selectDB($name));
        }
        
        return $this->_databasePool[$name];
    }
}<commit_msg>map database name to php class<commit_after><?php

namespace Sokil\Mongo;

class Client
{
    private $_connection;
    
    private $_databasePool = array();
    
    /**
     * @var array Database to class mapping
     */
    private $_mapping = array();
    
    public function __construct($dsn, array $options = array("connect" => true)) {
        $this->_connection = new \MongoClient($dsn, $options);
    }
    
    /**
     * Map database name to class
     * 
     * @param type $name
     * @param type $class
     * @return \Sokil\Mongo\Client
     */
    public function map($name, $class = null) {
        
        if(is_array($name)) {
            $this->_mapping = array_merge($this->_mapping, $name);
        }
        else {
            $this->_mapping[$name] = $class;
        }
        
        return $this;
    }
    
    /**
     * 
     * @param tstring $name database name
     * @return \Sokil\Mongo\Database
     */
    public function getDatabase($name) {
        if(!isset($this->_databasePool[$name])) {
            
            if(isset($this->_mapping[$name])) {
                $className = $this->_mapping[$name];
            }
            else {
                $className = '\Sokil\Mongo\Database';
            }
            
            $this->_databasePool[$name] = new $className($this->_connection->selectDB($name));
        }
        
        return $this->_databasePool[$name];
    }
}
{'fraction_non_alphanumeric': 0.14278869190225205, 'fraction_numerical': 0.0, 'mean_word_length': 1.9, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '1432104', 'n_tokens_mistral': 605, 'n_tokens_neox': 599, 'n_words': 121}