本文整理汇总了PHP中Singleton类的典型用法代码示例。如果您正苦于以下问题:PHP Singleton类的具体用法?PHP Singleton怎么用?PHP Singleton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Singleton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exceptionHandle
public static function exceptionHandle(Exception $exception)
{
if (DEBUG_MODE) {
//直接输出调试信息
echo nl2br($exception->__toString());
echo '<hr /><p>Router:</p><pre>';
print_r(Singleton::getInstance('Router'));
echo '</pre>';
} else {
$code = $exception->getCode();
$message = nl2br($exception->getMessage());
/*
如果错误码"可能为"合法的http状态码则尝试设置,
setStatus()方法会忽略非法的http状态码. */
if ($code >= 400 && $code <= 505 && !headers_sent()) {
ResponseModule::setStatus($code);
}
$var_list = array('message' => $message, 'code' => $code, 'file' => $exception->getFile(), 'url' => Singleton::getInstance('Router')->getUrl());
if ($error_file = self::_getErrorFilePath($code)) {
Lugit::$view = new View($var_list);
Lugit::$view->render($error_file);
} else {
echo 'No error page is found.<pre>';
print_r($var_list);
echo '</pre>';
}
}
exit;
}
示例2: GetInstance
public static function GetInstance()
{
if (Singleton::$instance == null) {
Singleton::$instance = new Singleton();
}
return Singleton::$instance;
}
示例3: transform
public function transform()
{
// get transformed document
$doc = $this->__Document->transform();
// set content of body
$this->__Layout->__Body()->write($doc);
// Verbrauchter PHP Speicher (RAM)
$memory = fbytes(memory_get_usage());
// Skriptlaufzeit
$runtime = round(microtime(true) - RUNTIME, 5);
$req = Singleton::getInstance('HTTP_Request');
if (substr_count($req->getRequestUri(), 'ajax.') > 0) {
return $this->__Layout->getAJAX();
}
$this->__Layout->__Body()->write('<!-- runtime: ' . $runtime . ' // memory usage: ' . $memory . ' -->');
// check logfiles
$sys_logs = scandir(LOG_PATH);
if (count($sys_logs) > 2) {
jgrowl(count($sys_logs) - 2 . ' Log(s) verfügbar', 'Systemfehler', 'warning');
}
$app_logs = scandir(RESOURCE_PATH . '/logs');
if (count($app_logs) > 2) {
jgrowl(count($app_logs) - 2 . ' Log(s) verfügbar', 'Anwendungsfehler', 'warning');
}
$notes = Singleton::getInstance('Watchdog')->getNotifications();
$this->__Layout->__Body()->write($notes);
return $this->__Layout->getLayout();
// end function
}
示例4: getInstance
public static function getInstance()
{
if (!self::$instance instanceof self) {
self::$instance = new Singleton();
}
return self::$instance;
}
示例5: bRegisterUser
public function bRegisterUser($reg_email, $reg_fname, $reg_aname)
{
# get the connection
$mysqli = Parent::connect();
# get password generator
$oPassword = Singleton::getInstance('Password');
# get a random password
$random_password = $oPassword->encryptPassword();
# check if succeed otherwise try again
if (!$random_password) {
$random_password = $oPassword->randomPassword();
}
#lowercase email
$slEmail = strtolower($reg_email);
if ($sStmt = $mysqli->prepare("INSERT INTO `users`(`username`, `password`, `voornaam`, `achternaam`, `email`) VALUES (?,?,?,?,?)")) {
# bind
$sStmt->bind_param('sssss', $reg_fname, $random_password, $reg_fname, $reg_aname, $reg_email);
# execute
if ($sStmt->execute()) {
User::sendRegistrationMail($reg_email, $random_password);
} else {
echo "een paar fouten";
}
}
}
示例6: test_sti_field_is_saved_and_used_correctly
function test_sti_field_is_saved_and_used_correctly()
{
setup_sqlite_test_db();
# Create a dummy test entries
$dummy = Test::create(array("dummy" => "TestDummy"));
$this->assertEqual($dummy->type, NULL);
$stest = new SuperTest(array("dummy" => "SuperDummy"));
$stest->save();
$this->assertEqual(strtolower($stest->type), "supertest");
$utest = new UltraTest(array("dummy" => "UltraDummy"));
$utest->save();
$this->assertEqual(strtolower($utest->type), "ultratest");
$atest = new AutoTest(array("dummy" => "AutoDummy"));
$atest->save();
$this->assertEqual(strtolower($atest->type), "autotest");
# PHP 5.3 needed to call magic methods statically, so
# work around by instanciating the class as singleton
$Test = Singleton::instance("Test");
# Load and check test entries
$dummy2 = $Test->find_by_dummy("TestDummy");
$this->assertEqual($dummy2->type, NULL);
$this->assertEqual(strtolower(get_class($dummy2)), "test");
$stest2 = $Test->find_by_dummy("SuperDummy");
$this->assertEqual(strtolower($stest2->type), "supertest");
$this->assertEqual(strtolower(get_class($stest2)), "supertest");
$utest2 = $Test->find_by_dummy("UltraDummy");
$this->assertEqual(strtolower($utest2->type), "ultratest");
$this->assertEqual(strtolower(get_class($utest2)), "ultratest");
$atest2 = $Test->find_by_dummy("AutoDummy");
$this->assertEqual(strtolower($atest2->type), "autotest");
$this->assertEqual(strtolower(get_class($atest2)), "autotest");
}
示例7: getInstance
static function getInstance()
{
if (empty(self::$instance)) {
self::$instance = new Singleton();
}
return self::$instance;
}
示例8: getInstance
public static function getInstance()
{
if (empty(self::$object)) {
return self::$object = new Singleton();
}
return self::$object;
}
示例9: __construct
public function __construct()
{
$this->id = rand(100000, 999999);
if (is_null(self::$settings)) {
self::$settings = Singleton::create("Settings");
}
}
示例10: __construct
public function __construct()
{
$this->db = Singleton::create("DatabaseManager");
if (is_null(self::$dbCache)) {
self::$dbCache = BeanLocator::get("DatabaseCache");
}
}
示例11: __construct
public function __construct()
{
session_start();
$this->view = new View(Singleton::getInstance()->r->getController());
$menu = array();
if ($this->sesionIniciada()) {
$this->view->setMsgBienvenida($this->getSesionVar("ROL") . " : " . $this->getSesionVar("NOMBRE") . " " . $this->getSesionVar("APELLIDO"));
switch ($this->getRol()) {
case ROL_ADMINISTRADOR:
$this->crearMenu($menu, "usuario/consultarUsuarios", 'Usuarios');
$this->crearMenu($menu, "preguntas/crearPreguntas", 'Preguntas');
$this->crearMenu($menu, "tipoMedicamento/consultarTipoMedicamentos", 'Tipos de Medicamentos');
$this->crearMenu($menu, "bodega/consultarBodegas", 'Bodega');
$this->crearMenu($menu, "medicamento/consultarMedicamentos", 'Medicamentos');
$this->crearMenu($menu, "empresa/consultarEmpresas", 'Empresas');
$this->crearMenu($menu, "pedido/consultarPedidos", 'PEDIDOS');
break;
case ROL_REPARTIDOR:
$this->crearMenu($menu, "repartidor/consultarPedidosAsignados", 'Pedidos asignados');
break;
case ROL_CLIENTE:
$this->crearMenu($menu, "cliente/consultarPedidos", 'PEDIDOS');
break;
default:
break;
}
$this->crearMenu($menu, "usuario/consultar", 'Consulta de datos');
$this->crearMenu($menu, "usuario/modificar", 'Modificar datos');
$this->crearMenu($menu, "usuario/eliminar", 'Eliminar cuenta');
$this->crearMenu($menu, "usuario/cerrarSesion", 'Cerrar sesión ');
$this->view->setMenu($menu);
}
}
示例12: of
/**
* @throws WrongArgumentException
* @return PrimitiveForm
*
* @deprecated You should use ofProto() instead
**/
public function of($className)
{
Assert::classExists($className);
$protoClass = EntityProto::PROTO_CLASS_PREFIX . $className;
Assert::classExists($protoClass);
return $this->ofProto(Singleton::getInstance($protoClass));
}
示例13: getInstance
/**
* クラス変数として利用した場合の例
* @return Singleton
*/
public static function getInstance()
{
if (!isset(self::$_instance)) {
self::$_instance = new Singleton();
}
return self::$_instance;
}
示例14: GetInstance
public static function GetInstance()
{
if (self::$instance == null) {
self::$instance = new self();
}
return self::$instance;
}
示例15: get_instance
public static function get_instance()
{
if (!self::$instance) {
self::$instance = new self();
}
return self::$instance;
}