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);
Ïà¹ØÎĵµ£º
//ת»»ÎªUNIXʱ¼ä´Á
function strtotimestamp(datestr)
{
var new_str = datestr.replace(/:/g,"-");
new_str = new_str.replace(/ /g,"-");
var arr = new_str.split("-");
var datum = new Date(Date. ......
ÏÖÔÚÖ÷Á÷µÄÍøÕ¾¿ª·¢ÓïÑÔÎÞÍâºõasp¡¢php¡¢asp.net¡¢jspµÈ¡£
ÍøÒ³´Ó¿ªÊ¼¼òµ¥µÄhmtlµ½¸´ÔӵķþÎñÓïÑÔ£¬×ß¹ýÁË10¶à¸öÄêÍ·£¬¸÷ÖÖ¼¼Êõ²ã³ö²»Çµ¥¸öµÄÖ÷Á÷¼¼ÊõÒ²ÔÚ²»¶Ï·Ðµİ汾£¬ÏÖÔÚ·ÖÎöϸ÷ÖÖÓïÑÔµÄÇø±ð¡¢ÓÅÊÆ¡¢ÁÓÊÆ¡¢¿ª·¢×¢ÒâÊÂÏ
......
´úÂë
//µÚÒ»ÖÖ·½Ê½
exec($cmd,$str,$result);
echo "result = $result <br/>";
if ($result != 0) {
echo "failed";
}
print_r($str);
#ûÓÐÊä³ö½á¹û
//µÚ¶þÖÖ·½Ê½
$output = shell_exec("/usr/bin/sudo /usr/bin/whoami 2>&1);
echo "output = ......
ǰһÕóÊÔÓà tokyo tyrant Åöµ½Ò»¸öÂé·³£¬
ÔÚphpÉÏÓÃmemcache½Ó¿Ú£¬È¡³öÊý¾ÝµÄʱºò£¬²»»á×Ô¶¯·´ÐòÁл¯¡£±ÈÈçÁËÒ»¸ö array(1,2,3,4,5)£¬³öÀ´¾ÍÊÇ 'a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;}' ÁË¡£
ÓÃ
Wireshark ¸ú×ÙÁËһϣ¬·¢Ïֺͱê×¼memcached·µ»ØµÄÊý¾ÝÀï²îÒ»¸ö×Ö½Ú¡£È¥¿´ÁËÏ memcached
ÐÒ飬·¢ÏÖÕâ¸ö×Ö½ÚÊǸ ......