找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 185|回复: 0
打印 上一主题 下一主题

php中注册器模式类用法实例分析

[复制链接]

2560

主题

2560

帖子

7622

积分

论坛元老

Rank: 8Rank: 8

积分
7622
跳转到指定楼层
楼主
发表于 2018-2-14 05:41:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            本文实例讲述了php中注册器模式类用法。分享给大家供大家参考,具体如下:
注册器读写类
Registry.class.php
offsetSet($name, $value);
  }
  /**
   * 取得注册表中某项内容的值
   *
   * @param string $name 索引
   *
   * @return mixed
   */
  public static function get($name)
  {
    $instance = self::getInstance();
    if (!$instance->offsetExists($name)) {
      return null;
    }
    return $instance->offsetGet($name);
  }
  /**
   * 检查一个索引是否存在
   *
   * @param string $name 索引
   *
   * @return boolean
   */
  public static function isRegistered($name)
  {
    return self::getInstance()->offsetExists($name);
  }
  /**
   * 删除注册表中的指定项
   *
   * @param string $name 索引
   *
   * @return void
   */
  public static function remove($name)
  {
    self::getInstance()->offsetUnset($name);
  }
}
需要注册的类

test.class.php
测试 test.php
hello();
//注册对象
Registry::set('testclass',$test);
//取出对象
$t = Registry::get('testclass');
//调用对象方法
$t->hello();
?>
希望本文所述对大家php程序设计有所帮助。
            
            
您可能感兴趣的文章:
  • php单例模式示例分享
  • php设计模式之单例模式实例分析
  • php单例模式实现方法分析
  • 解决ThinkPHP关闭调试模式时报错的问题汇总
  • PHP设计模式之装饰者模式代码实例
  • PHP设计模式之适配器模式代码实例
  • PHP单例模式详细介绍
  • PHP基于工厂模式实现的计算器实例
  • 简单介绍PHP的责任链编程模式
  • 详解PHP中的状态模式编程
  • php基础设计模式大全(注册树模式、工厂模式、单列模式)
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端