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. ......
代码
//第一种方式
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 = ......
运行环境:windows xp sp2
IIS v5.1
PHP 5.3.1-Win32-VC9-x86
Mysql 5.0
安装步骤:
安装IIS5.1
在 ......
我的gentoo系统flash无法显示中文字体,而且无法睡眠和待机,有功夫再研究一下如何解决吧
因为要开发一个富文本过滤的php扩展,因此研究了一下php扩展的开发技术。
php.net上的文档写的不全。还要到处找。
关于富文本过滤,就是说给一段混杂了html,js,css的文本,过滤出安全的部分,因此要做html,css解析,黑白名单设计 ......