Forum

Thread tagged as: Suggestions

PerchSmartbar Class

Is there a reason all the methods and properties on the PerchSmartbar class have been marked as private? Defining them as protected would allow for the class to be extended.

The render method could also be updated to replace this:

            foreach($this->items as $item) {

                switch($item['type']) {

                    case 'submit':
                        $contents .= $this->render_submit($item);
                        break;

                    case 'breadcrumb':
                        $contents .= $this->render_breadcrumb($item);
                        break;

                    case 'filter':
                        $contents .= $this->render_filter($item);
                        break;

                    case 'toggle':
                        $contents .= $this->render_toggle($item);
                        break;

                    case 'search':
                        $contents .= $this->render_search($item);
                        break;

                    default:
                        $contents .= $this->render_tab($item);
                        break;
                }
            }

with this:

            foreach ($this->items as $item) {
                $render_function = "render_{$item['type']}"; //or "render_" . $item['type'];
                if (method_exists($this, $render_function)) {
                    $contents .= $this->$render_function($item);
                } else {
                    $contents .= $this->render_tab($item);
                }
            }

This would allow for new render_* methods on any extended class to be the only thing that needs to be defined.

Lachlan Heywood

Lachlan Heywood 0 points

  • 3 years ago