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


PHP Singleton::getInstance方法代码示例

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


在下文中一共展示了Singleton::getInstance方法的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;
 }
开发者ID:sujinw,项目名称:php-lugit-framework,代码行数:29,代码来源:Basic.php

示例2: __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

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

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

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

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

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

示例8: setupDataBaseConnection

 private function setupDataBaseConnection()
 {
     $this->db = Singleton::getInstance(DataBase::class);
     if (!$this->db->isConnected()) {
         $this->db->setType(DataBaseConfig::TYPE);
         $this->db->connect(DataBaseConfig::HOST, DataBaseConfig::USER, DataBaseConfig::PWD, DataBaseConfig::DB);
     }
 }
开发者ID:jankovacs,项目名称:php-legs,代码行数:8,代码来源:BaseDataBaseService.php

示例9: run

 public static function run()
 {
     self::initConst();
     date_default_timezone_set('Etc/GMT-8');
     error_reporting(DEBUG_MODE ? E_ALL : E_ALL ^ E_NOTICE ^ E_WARNING);
     set_exception_handler(array('Basic', 'exceptionHandle'));
     Singleton::getInstance('Router')->dispatch();
 }
开发者ID:sujinw,项目名称:php-lugit-framework,代码行数:8,代码来源:lugit.php

示例10: __construct

 public function __construct()
 {
     # set table name
     parent::__construct('users');
     # get the database and mysqli instance since this is the model
     $oDatabase = Singleton::getInstance('Database');
     $this->mysqli = $oDatabase->connect();
 }
开发者ID:RhenusoneRosalia,项目名称:portfolio,代码行数:8,代码来源:Email.php

示例11: testSingleton

 public function testSingleton()
 {
     $obj = Singleton::getInstance();
     try {
         $demo = clone $obj;
     } catch (\Exception $e) {
         $this->assertEquals('fuck you', $e->getMessage());
     }
 }
开发者ID:RunnerLee,项目名称:pattern-learning,代码行数:9,代码来源:SingletonTest.php

示例12: getKmz

 public static function getKmz()
 {
     $sql = "SELECT * FROM species_tree_nominal where class='Aves'";
     $_SQL = Singleton::getInstance(SQL_DRIVER);
     $res = $_SQL->sql_query($sql);
     while ($ob = $_SQL->sql_fetch_object($res)) {
         shell_exec("cd /home/www/species/tmp/kmz/; wget http://www.xeno-canto.org/ranges/" . str_replace(" ", "_", $ob->nominal) . ".kmz");
     }
 }
开发者ID:glial,项目名称:glial,代码行数:9,代码来源:XenoCanto.php

示例13: __get

 public function __get($key)
 {
     $key = ucfirst(strtolower($key));
     if (class_exists($key . 'Module')) {
         return Singleton::getInstance($key . 'Module');
     } else {
         return null;
     }
 }
开发者ID:sujinw,项目名称:php-lugit-framework,代码行数:9,代码来源:Controller.php

示例14: __construct

 public function __construct()
 {
     # set table name
     parent::__construct('files');
     # get the database and mysqli instance since this is the model
     $oDatabase = Singleton::getInstance('Database');
     $this->mysqli = $oDatabase->connect();
     $oUser = Singleton::getInstance('User');
     $iUserid = $oUser->getUserId();
     $this->userid = $iUserid;
 }
开发者ID:RhenusoneRosalia,项目名称:portfolio,代码行数:11,代码来源:FileModel.php

示例15: applyValidator

 /**
  * 应用验证器并返回过滤后的结果.
  * 用法:
  * Singleton->getInstance('ValidatorModule')->applyValidator('not_empty', '');
  * //返回false
  *
  * Singleton->getInstance('ValidatorModule')->applyValidator('not_empty', array('', 'abc'));
  * //返回false
  *
  * 支持静态方法
  * Singleton->getInstance('ValidatorModule')->applyValidator('YourClass::yourMethod', 'abc');
  *
  * @access public
  * @param string $validator 验证器名称
  * @param mixed $data 要处理的数据
  * @return bool 验证结果
  */
 public function applyValidator($validator, $data)
 {
     $result = Singleton::getInstance('FilterModule')->applyFilter($validator, $data);
     if (is_array($result)) {
         foreach ($result as $v) {
             if (!$v) {
                 return false;
             }
         }
         return true;
     }
     return (bool) $result;
 }
开发者ID:sujinw,项目名称:php-lugit-framework,代码行数:30,代码来源:ValidatorModule.php


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