/** * Proxy methods over to the connection * @param string $method * @param array $args */ public function __call($method, $args) { foreach ($args as $arg) { if (is_array($arg)) { $vals = array(); foreach ($arg as $key => $value) { $vals[] = "{$key} => " . var_export($value, true); } $a[] = 'array(' . join(', ', $vals) . ')'; } else { $a[] = $arg; } } $this->say("{$method}(" . join(", ", $a) . ")"); // benchmark method call $t = new Horde_Support_Timer(); $t->push(); $connection = Mad_Model_Base::connection(); $result = call_user_func_array(array($connection, $method), $args); $time = $t->pop(); // print stats $this->say(sprintf("%.4fs", $time), 'subitem'); if (is_int($result)) { $this->say("{$result} rows", 'subitem'); } return $result; }
/** * Construct association object * * @param string $assocName * @param array $options * @param object $model */ public function __construct($assocName, $options, Mad_Model_Base $model) { $valid = array('className', 'foreignKey', 'primaryKey', 'include', 'order', 'dependent' => 'nullify'); $this->_options = Mad_Support_Base::assertValidKeys($options, $valid); $this->_assocName = $assocName; $this->_model = $model; $this->_conn = $model->connection(); // get inflections $toMethod = Mad_Support_Inflector::camelize($this->_assocName, 'lower'); $toMethod = str_replace('/', '_', $toMethod); $toClass = ucfirst($toMethod); $this->_methods = array($toMethod => 'getObject', $toMethod . '=' => 'setObject', 'build' . $toClass => 'buildObject', 'create' . $toClass => 'createObject'); }
/** * Construct association object * * @param string $assocName * @param array $options * @param object $model */ public function __construct($assocName, $options, Mad_Model_Base $model) { $valid = array('className', 'conditions', 'order', 'foreignKey', 'primaryKey', 'associationForeignKey', 'associationPrimaryKey', 'joinTable', 'uniq', 'include', 'finderSql', 'deleteSql', 'insertSql'); $this->_options = Mad_Support_Base::assertValidKeys($options, $valid); $this->_assocName = $assocName; $this->_model = $model; $this->_conn = $model->connection(); // get inflections $toMethod = Mad_Support_Inflector::camelize($this->_assocName, 'lower'); $toMethod = str_replace('/', '_', $toMethod); $singular = Mad_Support_Inflector::singularize($toMethod); $toClass = ucfirst($singular); $this->_methods = array($toMethod => 'getObjects', $toMethod . '=' => 'setObjects', $singular . 'Ids' => 'getObjectIds', $singular . 'Ids=' => 'setObjectIds', $singular . 'Count' => 'getObjectCount', 'add' . $toClass => 'addObject', Mad_Support_Inflector::pluralize('replace' . $toClass) => 'replaceObjects', Mad_Support_Inflector::pluralize('delete' . $toClass) => 'deleteObjects', Mad_Support_Inflector::pluralize('clear' . $toClass) => 'clearObjects', Mad_Support_Inflector::pluralize('find' . $toClass) => 'findObjects'); }
/** * Construct association object * * @param string $assocName * @param array $options */ public function __construct($assocName, $options, Mad_Model_Base $model) { $valid = array('className', 'foreignKey', 'associationForeignKey', 'primaryKey', 'associationPrimaryKey', 'include', 'select', 'conditions', 'order', 'finderSql', 'through', 'dependent' => 'nullify'); $this->_options = Mad_Support_Base::assertValidKeys($options, $valid); $this->_assocName = $assocName; $this->_model = $model; $this->_conn = $model->connection(); // throw fatal error if through option is invalid $this->_throughClass = Mad_Support_Inflector::classify($this->_options['through']); class_exists($this->_throughClass); // get inflections $toMethod = Mad_Support_Inflector::camelize($this->_assocName, 'lower'); $toMethod = str_replace('/', '_', $toMethod); $singular = Mad_Support_Inflector::singularize($toMethod); $toClass = ucfirst($singular); $this->_methods = array($toMethod => 'getObjects', $singular . 'Ids' => 'getObjectIds', $singular . 'Count' => 'getObjectCount', 'add' . $toClass => 'addObject', Mad_Support_Inflector::pluralize('delete' . $toClass) => 'deleteObjects', Mad_Support_Inflector::pluralize('clear' . $toClass) => 'clearObjects', Mad_Support_Inflector::pluralize('find' . $toClass) => 'findObjects'); }
/** * Connect to the database. * * @return object {@link Mad_Model_ConnectionAdapter_Abstract} */ protected function _connect() { if (!Mad_Model_Base::isConnected()) { Mad_Model_Base::setLogger(); // default logger Mad_Model_Base::establishConnection($this->_spec); } $this->_conn = Mad_Model_Base::connection(); }
/** * @param integer $version */ protected function _setSchemaVersion($version) { $version = $this->_isDown() ? $version - 1 : $version; $sql = "UPDATE schema_info SET version = " . (int) $version; Mad_Model_Base::connection()->update($sql); }
/** * Connect to the database. * * @return object {@link Mad_Model_ConnectionAdapter_Abstract} */ protected function _connect() { if (!Mad_Model_Base::isConnected()) { Mad_Model_Base::establishConnection(MAD_ENV); } return Mad_Model_Base::connection(); }