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 = ......
ÈÎÎñÐèÇó£ºÒ»¸ö»áÒéͶ¸åϵͳ£¬ÔÚ×÷ÕßÌá½»ÂÛÎÄժҪʱ×Ô¶¯Ïò×÷Õß·¢ËÍÒ»·âÈ·ÈÏÓʼþ¡£
(×¢£ºÍ¶¸åϵͳʹÓõÄÊÇmyreview
)
×Ðϸ¿¼ÂÇһϣ¬Õâ¸öÈÎÎñ¿ÉÒÔÓÐÒÔϼ¸ÖÖ·½Ê½Íê³É£º
ÔÚ·þÎñÆ÷ÉÏÅäÖÃsendmail·þÎñ£¬Ê¹ÓÃphpÖеĵÄmailº¯Êý·¢ËÍÓʼþ£»
ÔÚ·þÎñÆ÷Éϰ²×°mutt + msmtp£¬»òÕßÔÚ·þÎñÆ÷Éϰ²×°ÆäËüµÄsmtp¿Í»§¶Ë³ÌÐò£¬Ê¹ÓÃsmtp¿Í» ......
ÔËÐл·¾³£ºwindows xp sp2
IIS v5.1
PHP 5.3.1-Win32-VC9-x86
Mysql 5.0
°²×°²½Ö裺
°²×°IIS5.1
ÔÚ ......