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; }
public static function GetInstance() { if (self::$instance == null) { self::$instance = new self(); } return self::$instance; }
public static function get_instance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
public static function GetInstance() { if (Singleton::$instance == null) { Singleton::$instance = new Singleton(); } return Singleton::$instance; }
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 }
public static function getInstance() { if (empty(self::$instance)) { self::$instance = new self(); } return self::$instance; }
public static function getInstance() { if (!self::$instance instanceof self) { self::$instance = new Singleton(); } return self::$instance; }
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"; } } }
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"); }
static function getInstance() { if (empty(self::$instance)) { self::$instance = new Singleton(); } return self::$instance; }
public static function getInstance() { if (empty(self::$object)) { return self::$object = new Singleton(); } return self::$object; }
protected final function initialize() { parent::initialize(); $this->container = new Pimple(); $config_parsed = Yaml::parse($this->getConfigDir() . "/" . self::CONFIG_FILE_NAME); foreach ($config_parsed as $section => &$section_config) { if ($section === "http_scrap") { $section_config['next_scrapping_agent'] = function () use(&$section_config) { // si existe entradas en el arreglo agents if (isset($section_config['agents']) && count($section_config['agents'] > 0)) { // si agent-swapping = TRUE if ($section_config['agent_swapping']) { // retorno uno aleatorio $r = mt_rand(0, (int) count($section_config['agents']) - 1); return $section_config['agents'][$r]; } // sino el primero es el default return $section_config['agents'][0]; } // sino devuelve la entrada ultradefaul return "WEB-BOT"; }; } $this->container[$section] = $section_config; $this->read_only_entries[] = $section; } }
public function __construct() { $this->id = rand(100000, 999999); if (is_null(self::$settings)) { self::$settings = Singleton::create("Settings"); } }
public function __construct() { $this->db = Singleton::create("DatabaseManager"); if (is_null(self::$dbCache)) { self::$dbCache = BeanLocator::get("DatabaseCache"); } }
public static function getInstance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
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); } }
/** * @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)); }
public static function getInstance() { if (self::$instance === NULL) { self::$instance = new self(); } return self::$instance; }
public static function get_instance() { if (!isset(self::$instance)) { self::$instance = new static(); } return self::$instance; }
/** * クラス変数として利用した場合の例 * @return Singleton */ public static function getInstance() { if (!isset(self::$_instance)) { self::$_instance = new Singleton(); } return self::$_instance; }
public static function getInstance() { if (self::$uniqueInstance === NULL) { self::$uniqueInstance = new Singleton(); } return self::$uniqueInstance; }
public static function getInstance() { if (!isset(self::$engine)) { self::$engine = new CoreEngine(); } return self::$engine; }
public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new Singleton(); } return self::$instance; }
public static function getInstance() { if (!self::$_instance instanceof self) { self::$_instance = new self(); } return self::$_instance; }
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 */ } }
/** * 获得控件值. * * @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}\"" : ''; }
public static function getInstence() { if (is_null(self::$singleton)) { self::$singleton = new Singleton(); } return self::$singleton; }
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"; }
public static function getInstance() { if (self::$uniqueInstance === null) { self::$uniqueInstance = new self(); } return self::$uniqueInstance; }
public static function init() { if (self::$_instance == null) { self::$_instance = new self(); } return self::$_instance; }