Habari\Comments::__get PHP Method

__get() public method

Implements custom object properties
public __get ( string $name ) : mixed
$name string Name of property to return
return mixed The requested field value
    public function __get($name)
    {
        static $moderated = null;
        switch ($name) {
            case 'count':
                return count($this);
            case 'moderated':
                if (empty($moderated)) {
                    $moderated_statuses = Plugins::filter('moderated_statuses', array('approved'));
                    $moderated_statuses = array_map(function ($value) {
                        return Comment::status($value);
                    }, $moderated_statuses);
                    $moderated = array();
                    foreach ($this as $comment) {
                        if (in_array($comment->status, $moderated_statuses)) {
                            $moderated[$comment->id] = $comment;
                        }
                        if (isset($_COOKIE['comment_' . Options::get('GUID')])) {
                            list($commenter, $email, $url) = explode('#', $_COOKIE['comment_' . Options::get('GUID')]);
                            if ($comment->ip == Utils::get_ip() && $comment->name == $commenter && $comment->email == $email && $comment->url == $url) {
                                $moderated[$comment->id] = $comment;
                            }
                        }
                    }
                    $moderated = new Comments($moderated);
                }
                return $moderated;
            default:
                if ($index = array_search($name, Comment::list_comment_statuses())) {
                    return $this->only('status', $index);
                }
                if ($index = array_search($name, Comment::list_comment_types())) {
                    return $this->only('type', $index);
                }
                // Dumb check for plurals
                $pluralize = function ($s) {
                    return $s . 's';
                };
                if ($index = array_search($name, array_map($pluralize, Comment::list_comment_statuses()))) {
                    return $this->only('status', $index);
                }
                if ($index = array_search($name, array_map($pluralize, Comment::list_comment_types()))) {
                    return $this->only('type', $index);
                }
        }
        trigger_error('Property "@name" does not exist.', E_NOTICE);
        return null;
    }