protected function componentAttributes()
    {
        $function = function ($widget) {
            $classname = array_get($widget['attributes'], 'attributes.classname');
            if (is_null($classname)) {
                return '';
            }
            $instance = null;
            $widgets  = Registry::get('ui-components');
            if (empty($widgets)) {
                return '';
            }
            foreach ($widgets as $widget) {
                if (get_class($widget) == $classname) {
                    $instance = $widget;
                    break;
                }
            }
            if (is_null($instance)) {
                return '';
            }
            return serialize($instance->getShared());
        };
        return new Twig_SimpleFunction(
                'component_attributes', $function
        );
    }