init() public static method

Initialise Shanty_Mongo. In particular all the requirements.
public static init ( )
Example #1
0
 public function __construct($data = array(), $config = array())
 {
     // Make sure mongo is initialised
     Shanty_Mongo::init();
     $this->_config = array_merge($this->_config, $config);
     $this->_references = new SplObjectStorage();
     // If not connected and this is a new root document, figure out the db and collection
     if ($this->isNewDocument() && $this->isRootDocument() && !$this->isConnected()) {
         $this->setConfigAttribute('connectionGroup', static::getConnectionGroupName());
         $this->setConfigAttribute('db', static::getDbName());
         $this->setConfigAttribute('collection', static::getCollectionName());
     }
     // Get collection requirements
     $this->_docRequirements = static::getCollectionRequirements();
     // apply requirements requirement modifiers
     $this->applyRequirements($this->_config['requirementModifiers'], false);
     // Store data
     $this->_cleanData = $data;
     // Initialize input data
     if ($this->isNewDocument() && is_array($data)) {
         foreach ($data as $key => $value) {
             $this->getProperty($key);
         }
     }
     // Create document id if one is required
     if ($this->isNewDocument() && ($this->hasKey() || isset($this->_config['hasId']) && $this->_config['hasId'])) {
         $this->_data['_id'] = new MongoId();
         $this->_data['_type'] = static::getCollectionInheritance();
     }
     // If has key then add it to the update criteria
     if ($this->hasKey()) {
         $this->setCriteria($this->getPathToProperty('_id'), $this->getId());
     }
     $this->init();
 }
Example #2
0
 public function __construct($connectionString = null, array $options = array())
 {
     Shanty_Mongo::init();
     // Set the server to local host if one was not provided
     if (is_null($connectionString)) {
         $connectionString = '127.0.0.1';
     }
     $options['connect'] = false;
     $this->_connectionInfo = $options;
     $this->_connectionInfo['connectionString'] = $connectionString;
     return parent::__construct($connectionString, $options);
 }
Example #3
0
 public function __construct($connectionString = null, array $options = array())
 {
     Shanty_Mongo::init();
     // Set the server to local host if one was not provided
     if (is_null($connectionString)) {
         $connectionString = '127.0.0.1';
     }
     // Force mongo to connect only when we need to
     $options['connect'] = false;
     $connectionInfo = self::parseConnectionString($connectionString);
     $this->_connectionInfo = array_merge($options, $connectionInfo);
     return parent::__construct($connectionString, $options);
 }
Example #4
0
 public function setUp()
 {
     parent::setUp();
     Shanty_Mongo::makeClean();
     Shanty_Mongo::init();
 }
Example #5
0
     * Get a read connection
     * 
     * @param string $connectionGroupName The connection group name
     * @return Shanty_Mongo_Connection
     */
    public static function getReadConnection($connectionGroupName = 'default')
    {
        $connectionGroup = static::getConnectionGroup($connectionGroupName);
        if ($connectionGroupName == 'default' && count($connectionGroup->getSlaves()) === 0 && count($connectionGroup->getMasters()) === 0) {
            // Add a connection to localhost if no connections currently exist for the default connection group
            $connectionGroup->addMaster(new Shanty_Mongo_Connection('127.0.0.1'));
        }
        if (!($connection = $connectionGroup->getReadConnection($connectionGroupName))) {
            require_once 'Shanty/Mongo/Exception.php';
            throw new Shanty_Mongo_Exception("No read connection available for the '{$connectionGroupName}' connection group");
        }
        return $connection;
    }
    /**
     * Return Shanty_Mongo to pre-init status
     */
    public static function makeClean()
    {
        static::removeConnectionGroups();
        static::removeRequirements();
        static::removeRequirementCreators();
        static::$_initialised = false;
    }
}
Shanty_Mongo::init();