/** * Constructing cache object * * @param string $cache_link * @param string $class */ public function __construct($cache_link = null, $class = null) { // if we need to use default link from application if (empty($cache_link)) { $cache_link = application::get(['flag', 'global', 'cache', 'default_cache_link']); if (empty($cache_link)) { throw new Exception('You must specify cache link and/or class!'); } } // get object from factory $temp = factory::get(['cache', $cache_link]); // if we have class if (!empty($class) && !empty($cache_link)) { // replaces in case we have it as submodule $class = str_replace('.', '_', trim($class)); // if we are replacing database connection with the same link we // need to manually close connection if (!empty($temp['object']) && $temp['class'] != $class) { $object = $temp['object']; $object->close(); unset($this->object); } $this->object = new $class($cache_link); // putting every thing into factory factory::set(['cache', $cache_link], ['object' => $this->object, 'class' => $class]); } else { if (!empty($temp['object'])) { $this->object = $temp['object']; } else { throw new Exception('You must specify cache link and/or class!'); } } }
/** * Constructing crypt object * * @param string $db_link * @param string $class */ public function __construct($crypt_link = null, $class = null, $options = []) { // if we need to use default link from application if ($crypt_link == null) { $crypt_link = application::get(['flag', 'global', 'crypt', 'default_crypt_link']); if (empty($crypt_link)) { throw new Exception('You must specify crypt link!'); } } // get object from factory $temp = factory::get(['crypt', $crypt_link]); // if we have class if (!empty($class) && !empty($crypt_link)) { // replaces in case we have it as submodule $class = str_replace('.', '_', trim($class)); // creating new class unset($this->object); $this->object = new $class($crypt_link, $options); factory::set(['crypt', $crypt_link], ['object' => $this->object, 'class' => $class]); } else { if (!empty($temp['object'])) { $this->object = $temp['object']; } else { throw new Exception('You must specify crypt link and/or class!'); } } }
/** * Constructing database object * * @param string $db_link * @param string $class */ public function __construct($db_link = null, $class = null) { // if we need to use default link from application if (empty($db_link)) { $db_link = application::get(['flag', 'global', 'db', 'default_db_link']); if (empty($db_link)) { throw new Exception('You must specify database link and/or class!'); } } // get object from factory $temp = factory::get(['db', $db_link]); // if we have class if (!empty($class) && !empty($db_link)) { // replaces in case we have it as submodule $class = str_replace('.', '_', trim($class)); // if we are replacing database connection with the same link we // need to manually close database connection if (!empty($temp['object']) && $temp['class'] != $class) { $object = $temp['object']; $object->close(); unset($this->object); } // creating new class $this->object = new $class($db_link); // determining ddl class & object $ddl_class = str_replace('_base_abc123', '_ddl', $class . '_abc123'); $ddl_object = new $ddl_class(); // backend $this->backend = str_replace(['numbers_backend_db_', '_base'], '', $class); // putting every thing into factory factory::set(['db', $db_link], ['object' => $this->object, 'class' => $class, 'backend' => $this->backend, 'ddl_class' => $ddl_class, 'ddl_object' => $ddl_object]); } else { if (!empty($temp['object'])) { $this->object =& $temp['object']; $this->backend = $temp['backend']; } else { throw new Exception('You must specify database link and/or class!'); } } }