XF 2.2 What is XF::options()

\XF::options() is a static method in class XF

PHP:
/**
 * @return \ArrayObject
 */
public static function options()
{
    return self::app()->options();
}

As you can see, it returns an ArrayObject by calling method options() on the app object:
PHP:
/**
 * @return \ArrayObject
 */
public function options()
{
    return $this->container['options'];
}

As you can see, the method returns options form the (dependency injection) container.

PHP:
$container['options'] = $this->fromRegistry('options',
    function(Container $c) { return $c['em']->getRepository('XF:Option')->rebuildOptionCache(); },
    function(array $options)
    {
        return new \ArrayObject($options, \ArrayObject::ARRAY_AS_PROPS);
    }
);

Here you can see that the ArrayObject is constructed by reading registry key options or by calling method rebuildOptionCache() from the option repository (if the registry entry is not available for whatever reason).

So let's see what rebuildOptionCache() does:
PHP:
public function getOptionCacheData()
{
    $options = $this->finder('XF:Option')->fetch();
    $optionArray = [];

    foreach ($options AS $option)
    {
        $optionArray[$option['option_id']] = $option['option_value'];
    }

    return $optionArray;
}

public function rebuildOptionCache()
{
    $cache = $this->getOptionCacheData();
    \XF::registry()->set('options', $cache);

    $this->app()->options = new \ArrayObject($cache, \ArrayObject::ARRAY_AS_PROPS);

    return $cache;
}

Is this clear now?

Tl;Dr
\XF::options() returns an ArrayObject that represents all XenForo options (cached data from table xf_option, all options that can be configured via ACP > Setup > Options).

... and all that could have been discovered quite easily by just looking at the source code and following the call chain ;)
 
Last edited:
Back
Top Bottom