ZFDebug icon indicating copy to clipboard operation
ZFDebug copied to clipboard

Blacklist things from Registry

Open LiamKarlMitchell opened this issue 2 years ago • 0 comments

Wanted to hide things from Registry I'm still using an older 1.5 version but thought I'de share here. Also good to not show it if user is not logged in, but I can do that in Bootstrap.php already.

    /**
     * Contains a blacklist of Registry keys not to show.
     *
     * @var array
     */
    protected $_blacklist = array(
        'config',
        'db',
        'multidb',
        'Zend_Locale',
        'Zend_View_Helper_Doctype',
        'Zend_View_Helper_Placeholder_Registry',
    );
    
    /**
     * Create ZFDebug_Controller_Plugin_Debug_Plugin_Registry
     *
     * @param  array  $options
     */
    public function __construct(array $options = array())
    {
        $this->_registry = Zend_Registry::getInstance();

        if(isset($options['blacklist'])) {
            $this->_blacklist = $options['blacklist'];
        }
    }

// Further down in getPanel I put this.

     // Can use array_filter.
      $this->_registry = new ArrayObject(
            array_filter( (array) $this->_registry, array($this, 'filter'),ARRAY_FILTER_USE_KEY)
        );

    private function filter($k) {
        return !in_array($k, $this->_blacklist, true);
    }

LiamKarlMitchell avatar Sep 24 '21 10:09 LiamKarlMitchell