drau89457 2016-03-03 14:40
浏览 34
已采纳

Silverstripe的配置API是单身人士吗?

According to the Documentation,

The Configuration API can be seen as separate from other forms of variables in the SilverStripe system due to three properties API:

Configuration is per class, not per instance.
Configuration is normally set once during initialization and then not changed.
Configuration is normally set by a knowledgeable technical user, such as a developer, not the end user.

Question is the configuration API a Singleton?

  • 写回答

1条回答 默认 最新

  • duancaiyi7567 2016-03-03 16:01
    关注

    It behaves like a Singleton, since most access to the Config API goes through Config::inst() which will always return the currently active Config instance. This instance will remain the same, until you decide to change it with Config::set_instance($myNewConfigInstance).

    So yes, there's a Singleton pattern implemented there, but you can still have multiple instances of Config (you can use this to isolate environments, like tests or whatever).

    Here's an example of how you could switch Config during code-execution:

    // preserve old config
    $defaultConfig = Config::inst();
    // create a new config
    Config::set_instance(new Config());
    
    // … do stuff that will use the new config
    
    // switch back to the default config once you're done
    Config::set_instance($defaultConfig);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址