PHPÖеÄʵÏÖRegistryģʽ¹ý³ÌÖеÄÁìÎò
<?php
/*
Singleton && Registry Design Pattern Implementation
*/
class Registry {
private $_store = array();
public function getInstance() {
static $instance = array();
if (!$instance) {
$instance[0] = new Registry;
}
return $instance[0];
}
public function &get($key){
if($this->isValid($key)){
return $this->_store[$key];
}
}
public function set($key, $object){
$this->_store[$key] = &$object;
}
public function isValid($key){
return array_key_exists($key,$this->_store);
}
}
?>
Test Case:
<?php
require_once 'simpletest/unit_tester.php';
require_once 'simpletest/reporter.php';
require_once 'Registry.php';
class RegistryTestCase extends UnitTestCase{
function testRegistryIsSingleton(){
$this->assertIsA($reg = Registry::getInstance(), 'Registry');
$this->assertReference($reg, Registry::getInstance());
}
function testEmptyRegistryKeyIsReturnNull(){
$reg = Registry::getInstance();
$this->assertNull($reg->get('key'));
}
function testEmptyRegistryKeyIsInvalid(){
$reg = Registry::getInstance();
$this->assertFalse($reg->get('key'));
}
function testSetRegistryKeyBecomesValid(){
$reg = Registry::getInstance();
$test_value = 'something';
settype($test_value, 'Object');
$reg->set('key', $test_value);
$this->assertTrue($reg->isValid('key'));
}
function testRegistryValueIsReference(){
$reg = Registry::getInstance();
$test_value = 'something';
$reg->set('key', $test_value);
Ïà¹ØÎĵµ£º
¡¡¡¡ÎÒ¿ª·¢µÄСվ£ºhttp://www.asprain.com£¬»¶Ó¹ÛĦ¡¢ÌåÑ飡
¡¡¡¡°¡£¬½ñÌì¿´µ½ºÜ¶àÈË˵ÎÒÂîPHP³ÌÐòÔ±ÊÇÔÚ³´×÷£¬Ä¿µÄÊÇÍƹãÎÒµÄÂÛ̳³ÌÐò¡£»°Ëµ£¬ËäÈ»ÎÒ֮ǰһֱºÜÏëÏë°ì·¨Ìá¸ß×Ô¼ºÐ´µÄÄǸö³ÌÐòµÄÖªÃû¶È¡£ÎÒ°ÑÎÒµÄСվ½éÉܸøÎÒµÄËùÓеĺÃÓÑ£¬ÇëËûÃÇ¿Ú¿ÚÏà´«¡£µ«ÊÇÎÒȷʵдÕâƪÎÄÕÂÊÇûÓг´×÷Ä¿µÄµÄ¡£ÔÒòºÜ¼òµ¥£ºÎÒÐ ......
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
php´úÂë:
<?php
class ChineseSpell {
/**
* @var array $chineseSpellList Æ´Òô±àÂë¶ÔÓ¦±í
* @access private
*/
private $chineseSpellList = array(
'a'=>-20319,
'ai'=>-20317,
&nbs ......
ÎÒµÄgentooϵͳflashÎÞ·¨ÏÔʾÖÐÎÄ×ÖÌ壬¶øÇÒÎÞ·¨Ë¯Ãߺʹý»ú£¬Óй¦·òÔÙÑо¿Ò»ÏÂÈçºÎ½â¾ö°É
ÒòΪҪ¿ª·¢Ò»¸ö¸»Îı¾¹ýÂ˵ÄphpÀ©Õ¹£¬Òò´ËÑо¿ÁËÒ»ÏÂphpÀ©Õ¹µÄ¿ª·¢¼¼Êõ¡£
php.netÉϵÄÎĵµÐ´µÄ²»È«¡£»¹Òªµ½´¦ÕÒ¡£
¹ØÓÚ¸»Îı¾¹ýÂË£¬¾ÍÊÇ˵¸øÒ»¶Î»ìÔÓÁËhtml,js,cssµÄÎı¾£¬¹ýÂ˳ö°²È«µÄ²¿·Ö£¬Òò´ËÒª×öhtml,css½âÎö£¬ºÚ°×Ãûµ¥Éè¼Æ ......
0¡¢Óõ¥ÒýºÅ´úÌæË«ÒýºÅÀ´°üº¬×Ö·û´®£¬ÕâÑù×ö»á¸ü¿ìһЩ¡£ÒòΪPHP»áÔÚË«ÒýºÅ°üΧµÄ×Ö·û´®ÖÐËÑÑ°±äÁ¿£¬µ¥ÒýºÅÔò²»»á£¬×¢Ò⣺ֻÓÐechoÄÜÕâô×ö£¬ËüÊÇÒ»ÖÖ¿ÉÒ԰Ѷà¸ö×Ö·û´®µ±×÷²ÎÊýµÄ“º¯Êý”£¨Òë×¢£ºPHPÊÖ²áÖÐ˵echoÊÇÓïÑԽṹ£¬²»ÊÇÕæÕýµÄº¯Êý£¬¹Ê°Ñº¯Êý¼ÓÉÏÁËË«ÒýºÅ£©¡£
1¡¢Èç¹ûÄܽ«ÀàµÄ·½·¨¶¨Òå³Éstatic£¬¾Í¾¡ ......
<?
function GetIP() { //»ñÈ¡IP
if ($_SERVER["HTTP_X_FORWARDED_FOR"])
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if ($_SERVER["HTTP_CLIENT_IP"])
$ip = $_SERVER["HTTP_CLIENT_IP"];
else if ($_SERVER["REMOTE_ADDR"])
$ip = $_SERVER["REMOTE_ADDR"];
......