本文共 4128 字,大约阅读时间需要 13 分钟。
************************************************************
/**
* Retrieve application root absolute path
*
* @return string
*/
public static function getRoot()
{
return self::$_appRoot;
}
/**
* Retrieve Events Collection
*
* @return Varien_Event_Collection $collection
*/
public static function getEvents()
{
return self::$_events;
}
得到mage的静态变量值,一般都是执行了set函数之后执行的。getRoot() getEvents
************************************************************
1
public static function getVersion()
{
$i = self::getVersionInfo();
return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "") . "-{$i['stability']}{$i['number']}", '.-');
}
2
public static function getVersionInfo()
{
return array(
'major' => '1',
'minor' => '4',
'revision' => '1',
'patch' => '1',
'stability' => '',
'number' => '',
);
}
3字符的叠加,加字符处理函数:
trim
截去字符串首尾的空格。
************************************************************
1.
/**
* Register a new variable
*
* @param string $key
* @param mixed $value
* @param bool $graceful
* @throws Mage_Core_Exception
*/
public static function register($key, $value, $graceful = false)
{
if (isset(self::$_registry[$key])) {
if ($graceful) {
return;
}
self::throwException('Mage registry key "'.$key.'" already exists');
}
self::$_registry[$key] = $value;
}
2.
此函数,该key存在的时候, $graceful为true,则return,否则,则抛出异常。
key值不存在,则,将其写入$_registry[]函数。
************************************************************
/**
* Retrieve a value from registry by a key
*
* @param string $key
* @return mixed
*/
public static function registry($key)
{
if (isset(self::$_registry[$key])) {
return self::$_registry[$key];
}
return null;
}
************************************************************
1.
/**
* Set all my static data to defaults
*
*/
public static function reset()
{
self::$_registry = array();
self::$_app = null;
self::$_config = null;
self::$_events = null;
self::$_objects = null;
self::$_isDownloader = false;
self::$_isDeveloperMode = false;
// do not reset $headersSentThrowsException
}
注意:注释--- do not reset $headersSentThrowsException
************************************************************
1
public static function setRoot($appRoot = '')
{
if (self::$_appRoot) {
return ;
}
if ('' === $appRoot) {
// automagically find application root by dirname of Mage.php
$appRoot = dirname(__FILE__);
}
$appRoot = realpath($appRoot);
if (is_dir($appRoot) and is_readable($appRoot)) {
self::$_appRoot = $appRoot;
} else {
self::throwException($appRoot . ' is not a directory or not readable by this user');
}
}
1
if ('' === $appRoot) {
// automagically find application root by dirname of Mage.php
$appRoot = dirname(__FILE__);
dirname(__FILE__) 返回当前相对目录。
2
realpath
realpath() 函数返回绝对路径。
该函数删除所有符号连接(比如 '/./', '/../' 以及多余的 '/'),返回绝对路径名。
若失败,则返回 false。比如说文件不存在的话。
3
is_dir()
is_dir
测试文件是否为目录。
语法: boolean is_dir(string filename);
返回值: 布尔值
函数种类: 文件存取
4
is_readable
The is_readable() function checks whether the specified file is readable.
is_readable()函数的作用是:判断给定文件名是否可读
判断:1.得到绝对地址,2是否是目录,3是否可读(文件权限)
相对地址-->绝对地址--->是否为目录---->目录是否可读。。
realpath() 函数返回绝对路径。
该函数删除所有符号连接(比如 '/./', '/../' 以及多余的 '/'),返回绝对路径名。
若失败,则返回 false。比如说文件不存在的话。
*************************************************************
1.
/**
* Unregister a variable from register by key
*
* @param string $key
*/
public static function unregister($key)
{
if (isset(self::$_registry[$key])) {
if (is_object(self::$_registry[$key]) && (method_exists(self::$_registry[$key], '__destruct'))) {
self::$_registry[$key]->__destruct();
}
unset(self::$_registry[$key]);
}
}
2.
当在$_registery[key]对应value是字符串,则直接使用unset()方法,将其从$_registery[]数组中删除
如果$_registery[key]对应的value是对象,而且存在__destruct()方法,则先执行__destruct()方法。此处要注意,先通过对象自己删除,然后再将其从$_registery[]中删除。
*************************************************************
/**
* Varien Objects Cache
*
* @param string $key optional, if specified will load this key
* @return Varien_Object_Cache
*/
public static function objects($key = null)
{
if (!self::$_objects) {
self::$_objects = new Varien_Object_Cache;
}
if (is_null($key)) {
return self::$_objects;
} else {
return self::$_objects->load($key);
}
}
转载地址:http://igdli.baihongyu.com/