class MyObject
{
static function parse($str)
{
$obj = new MyObject();
// some parsing/setting happens here
return $obj;
}
}
// you create an object "MyObject" from a string, so it's more obvious
// to read it this way :
$new_obj = MyObject::parse("This a description of a super cool object");
/**
* Returns true if the user is logged in through shibboleth
*
* @return boolean true on success, else false
*/
protected function is_logged_in() {
//Check shibboleth headers
if (!empty($_SERVER['HTTP_SHIB_IDENTITY_PROVIDER']) || !empty($_SERVER['Shib-Identity-Provider'])) {
if (!empty($_SERVER[$this->core->dbconfig("shib_auth", self::SHIB_AUTH_CONFIG_UID)])) {
return true;
}
}
return false;
}
这个方法将在我的框架中经常调用,并且在那里它将为每次调用都为我的配置 $_ SERVER 键进行数据库查找
因此,当页面被处理时,我可能在一个页面加载中调用10次,它将有10个数据库调用,但我将其更改为:
/**
* Returns true if the user is logged in through shibboleth
*
* @return boolean true on success, else false
*/
protected function is_logged_in() {
static $logged_in = null;
if($logged_in != null) {
return $logged_in;
}
//Check shibboleth headers
if (!empty($_SERVER['HTTP_SHIB_IDENTITY_PROVIDER']) || !empty($_SERVER['Shib-Identity-Provider'])) {
if (!empty($_SERVER[$this->core->dbconfig("shib_auth", self::SHIB_AUTH_CONFIG_UID)])) {
$logged_in = true;
return true;
}
}
$logged_in = false;
return false;
}