当前位置: 首页>>代码示例>>PHP>>正文


PHP Singleton::instance方法代码示例

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


在下文中一共展示了Singleton::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: singleton

 public static function singleton($classname)
 {
     if (!isset(self::$instance)) {
         self::$instance = new $classname();
     }
     return self::$instance;
 }
开发者ID:bfpi,项目名称:klarschiff-frontend-mit-mapbender,代码行数:7,代码来源:class_Singleton.php

示例2: test_find_by

 function test_find_by()
 {
     setup_sqlite_test_db();
     # PHP 5.3 needed to call magic methods statically, so
     # work around by instanciating the class as singleton
     $Test = Singleton::instance("Test");
     # create two test entries to be found
     Test::create(array("dummy" => "Test 1"), array("dummy" => "Test 2"));
     # Test find_by single id
     $dummy = $Test->find_by_id(1);
     $this->assertEqual(strtolower(get_class($dummy)), "test");
     $this->assertEqual($dummy->dummy, "Test 1");
     # Test find_by id array
     $dummies = $Test->find_by_id(array(1, 2), array("order" => "id"));
     $this->assertEqual(count($dummies), 2);
     $this->assertEqual($dummies[0]->dummy, "Test 1");
     $this->assertEqual($dummies[1]->dummy, "Test 2");
     # Test it works with strings, too
     $dummy = $Test->find_by_dummy("Test 2");
     $this->assertEqual($dummy->id, 2);
     # Test their combination
     $dummy = $Test->find_by_id_and_dummy(1, "Test 1");
     $this->assertEqual($dummy->id, 1);
     $this->assertEqual($dummies[0]->dummy, "Test 1");
     # Test their array'ed combination
     $dummies = $Test->find_by_id_and_dummy(array(1, 2), array("Test 1", "Test 2"), array("order" => "id"));
     $this->assertEqual(count($dummies), 2);
     $this->assertEqual($dummies[0]->dummy, "Test 1");
     $this->assertEqual($dummies[1]->dummy, "Test 2");
 }
开发者ID:kakra,项目名称:adodbrecord,代码行数:30,代码来源:TestMagicFinders.class.php

示例3: 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

示例4: get_instance

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

示例5: getInstance

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

示例6: get_instance

 public static function get_instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
开发者ID:tfrommen,项目名称:testable-code,代码行数:7,代码来源:using-unresettable-singletons.php

示例7: getInstance

 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
开发者ID:popovdenis,项目名称:lessons-1,代码行数:7,代码来源:singleton.php

示例8: getInstance

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

示例9: getInstance

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

示例10: 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

示例11: GetInstance

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

示例12: getInstance

 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
开发者ID:huailiang,项目名称:langhuo_server,代码行数:8,代码来源:Singleton.php

示例13: getInstance

 public static function getInstance()
 {
     if (empty($instance)) {
         self::$instance = new Singleton();
         self::$instance->loadValues();
     }
     return self::$instance;
 }
开发者ID:vrach141801,项目名称:Study,代码行数:8,代码来源:Singleton.php

示例14: instance

 static function instance()
 {
     if (!isset(self::$instance)) {
         $c = get_called_class();
         self::$instance = new $c();
     }
     return self::$instance;
 }
开发者ID:revned,项目名称:orangephp,代码行数:8,代码来源:Singleton.php

示例15: getInstance

 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new self();
         echo 1;
         return self::$instance;
     }
 }
开发者ID:sydorenkovd,项目名称:test-items,代码行数:8,代码来源:Singelton.php


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