• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Singleton类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Singleton的典型用法代码示例。如果您正苦于以下问题:PHP Singleton类的具体用法?PHP Singleton怎么用?PHP Singleton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Singleton类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
 }
开发者ID:sujinw,项目名称:php-lugit-framework,代码行数:29,代码来源:Basic.php


示例2: GetInstance

 public static function GetInstance()
 {
     if (Singleton::$instance == null) {
         Singleton::$instance = new Singleton();
     }
     return Singleton::$instance;
 }
开发者ID:sparrow41,项目名称:training,代码行数:7,代码来源:sing.php


示例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
 }
开发者ID:dlehmann,项目名称:DevCE,代码行数:29,代码来源:Page.php


示例4: getInstance

 public static function getInstance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new Singleton();
     }
     return self::$instance;
 }
开发者ID:stevenyeahhh,项目名称:distrapp,代码行数:7,代码来源:Singleton.php


示例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";
         }
     }
 }
开发者ID:RhenusoneRosalia,项目名称:portfolio,代码行数:25,代码来源:Query.php


示例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");
 }
开发者ID:kakra,项目名称:adodbrecord,代码行数:32,代码来源:TestSTI.class.php


示例7: getInstance

 static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new Singleton();
     }
     return self::$instance;
 }
开发者ID:SandyS1,项目名称:presentations,代码行数:7,代码来源:static.php


示例8: getInstance

 public static function getInstance()
 {
     if (empty(self::$object)) {
         return self::$object = new Singleton();
     }
     return self::$object;
 }
开发者ID:VitaliiSestrenskyi,项目名称:sest,代码行数:7,代码来源:Singleton.php


示例9: __construct

 public function __construct()
 {
     $this->id = rand(100000, 999999);
     if (is_null(self::$settings)) {
         self::$settings = Singleton::create("Settings");
     }
 }
开发者ID:aeberh,项目名称:php-movico,代码行数:7,代码来源:Component.php


示例10: __construct

 public function __construct()
 {
     $this->db = Singleton::create("DatabaseManager");
     if (is_null(self::$dbCache)) {
         self::$dbCache = BeanLocator::get("DatabaseCache");
     }
 }
开发者ID:aeberh,项目名称:php-movico,代码行数:7,代码来源:Persistence.php


示例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);
     }
 }
开发者ID:stevenyeahhh,项目名称:distrapp,代码行数:33,代码来源:Controller.php


示例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));
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:13,代码来源:PrimitiveForm.class.php


示例13: getInstance

 /**
  * クラス変数として利用した場合の例
  * @return Singleton
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new Singleton();
     }
     return self::$_instance;
 }
开发者ID:kjkoma,项目名称:HelloPHPWorld,代码行数:11,代码来源:singleton.php


示例14: getInstance

 public static function getInstance()
 {
     if (self::$uniqueInstance === NULL) {
         self::$uniqueInstance = new Singleton();
     }
     return self::$uniqueInstance;
 }
开发者ID:DaveNascimento,项目名称:civicrm-packages,代码行数:7,代码来源:Singleton.php


示例15: getInstance

 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new Singleton();
     }
     return self::$instance;
 }
开发者ID:nazart,项目名称:isil-web-2015,代码行数:7,代码来源:Singleton.php


示例16: testStaticMethodCalling

 public function testStaticMethodCalling()
 {
     $this->assertEquals(ClassUtils::callStaticMethod('Singleton::getInstance', 'UrlEncodeFilter'), Singleton::getInstance('UrlEncodeFilter'));
     $this->assertEquals(ClassUtils::callStaticMethod('ImaginaryDialect::me'), ImaginaryDialect::me());
     try {
         ClassUtils::callStaticMethod('InexistantClass::InSaNeMeThOd');
         $this->fail();
     } catch (ClassNotFoundException $e) {
         /* first pass */
     } catch (WrongArgumentException $e) {
         /* and all others */
     }
     try {
         ClassUtils::callStaticMethod('complete nonsense');
         $this->fail();
     } catch (WrongArgumentException $e) {
         /* pass */
     }
     try {
         ClassUtils::callStaticMethod('Identifier::comp::lete::non::sense');
         $this->fail();
     } catch (WrongArgumentException $e) {
         /* pass */
     }
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:25,代码来源:ClassUtilsTest.class.php


示例17: _getValue

 /**
  * 获得控件值.
  * 
  * @access private
  * @param mixed $name
  * @return void
  */
 private function _getValue($name, $defaultValue)
 {
     if (!($value = Singleton::getInstance('ResponseModule')->request->filter('htmlspecialchars')->{$name})) {
         $value = $defaultValue;
     }
     $value = $value ? " value=\"{$value}\"" : '';
 }
开发者ID:sujinw,项目名称:php-lugit-framework,代码行数:14,代码来源:FormHelper.php


示例18: getInstence

 public static function getInstence()
 {
     if (is_null(self::$singleton)) {
         self::$singleton = new Singleton();
     }
     return self::$singleton;
 }
开发者ID:ViolaMiki,项目名称:DesignPattern,代码行数:7,代码来源:singleton.php


示例19: generateManyToManySetter

 private function generateManyToManySetter(ManyToManyProperty $property)
 {
     $containerProp = $property->getEntity()->getPrimaryKey()->getName();
     $containedProp = Singleton::create("ServiceBuilder")->getEntity($property->getEntityName())->getPrimaryKey()->getName();
     $signature = "set" . ucfirst($property->getName()) . "(\${$containerProp}, \${$containedProp}s)";
     return "\tpublic function {$signature} {\n\t\t\$this->getPersistence()->{$signature};\n\t}\n\n";
 }
开发者ID:aeberh,项目名称:php-movico,代码行数:7,代码来源:EntityServiceBaseGenerator.php


示例20: GetInstance

 public static function GetInstance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
开发者ID:nolka,项目名称:k5,代码行数:7,代码来源:class.Singleton.php



注:本文中的Singleton类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Site类代码示例发布时间:2022-05-23
下一篇:
PHP SinglePage类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap