HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Does storing config values in protected vars makes sense?

R_JR_J Ex-FanboyMunich Admin

I'm toying around with the recent discussion list and want to add content to each discussion, based on a config setting.
Getting values from the config needs accessing config-defaults.php as well as config.php - at least that's what I think is true when you are using DirtyCache - and so I hope there is a possibility to read that value only one time and store it for all usages on that page access.

I'm thinking of something like that in my plugin:

protected $_ConfigValue;

public function __construct() {
    $this->$_ConfigValue = Gdn::Config('Plugins.MyPlugin.ConfigValue', 250);
}

public function discussionsController_afterDiscussionContent_handler($Sender) {
    // Now using $this->$_ConfigValue instead of
    // Gdn::Config('Plugins.MyPlugin.ConfigValue', 250)
}

Would that have any advantages over simply using Gdn::Config()?

I do not have any knowledge about the "lifetime" of my class. And if my class is constructed more than one time when recent discussions is build up, it would make no sense at all, I think. But when my function __construct is only called once in recent discussions, it would be clever, wouldn't it?

Best Answer

Answers

  • R_JR_J Ex-Fanboy Munich Admin

    Thanks for that! I found it not being shorter, but bloated - but it made me feel like a genius for a few minutes... :D

  • hgtonighthgtonight ∞ · New Moderator

    @R_J said:
    ...it made me feel like a genius for a few minutes... :D

    I get that feeling every time I discover some core functionality, only to realize I used it in another plugin already!

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • @hgtonight said:
    @R_J said:

    ...it made me feel like a genius for a few minutes... :D
    

    I get that feeling every time I discover some core functionality, only to realize I used it in another plugin >already!

    both you guys @r_j and @hgtonight are genuises for well over an hour extending into days and weeks and beyond. Always interesting posts and solutions.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.