本文整理匯總了PHP中factory::set方法的典型用法代碼示例。如果您正苦於以下問題:PHP factory::set方法的具體用法?PHP factory::set怎麽用?PHP factory::set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類factory
的用法示例。
在下文中一共展示了factory::set方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
/**
* 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!');
}
}
}
示例2: __construct
/**
* 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!');
}
}
}
示例3: __construct
/**
* 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!');
}
}
}