# give/4.15.3/src/DonorDashboards/Tabs/TabsRegister.php

GiveWP – Donation Plugin and Fundraising Platform, version 4.15.3. 130 lines.

- Page: https://pluginprobe.com/plugins/give/4.15.3/code/src/DonorDashboards/Tabs/TabsRegister.php
- Raw: https://pluginprobe.com/plugins/give/4.15.3/raw/src/DonorDashboards/Tabs/TabsRegister.php
- Modified: 2021-11-23T23:55:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.15.3/code/src/DonorDashboards/Tabs/TabsRegister.php#L10-L20`.

```php
<?php

namespace Give\DonorDashboards\Tabs;

use Give\DonorDashboards\Exceptions\DuplicateTabException;
use Give\DonorDashboards\Exceptions\MissingTabException;
use Give\DonorDashboards\Tabs\Contracts\Tab;

/**
 * @since 2.10.0
 */
class TabsRegister
{
    /**
     * FQCN of Tab classes
     *
     * @since 2.10.0
     *
     * @var string[]
     */
    private $tabs = [];

    /**
     * Returns all of the registered tabs
     *
     * @since 2.10.0
     *
     * @return string[]
     */
    public function getTabs()
    {
        return $this->tabs;
    }

    /**
     * Checks to see if a tab is registered with the given ID
     *
     * @since 2.10.0
     *
     * @param string $id
     *
     * @return bool
     */
    public function hasTab($id)
    {
        return isset($this->tabs[$id]);
    }

    /**
     * Returns a tab with the given ID
     *
     * @since 2.10.0
     *
     * @param string $id
     *
     * @return string
     */
    public function getTab($id)
    {
        if ( ! $this->hasTab($id)) {
            throw new MissingTabException($id);
        }

        return $this->tabs[$id];
    }

    /**
     * Returns all of the registered tab ids
     *
     * @since 2.10.0
     *
     * @return string[]
     */
    public function getRegisteredIds()
    {
        return array_keys($this->tabs);
    }

    /**
     * Add a tab to the list of tabs
     *
     * @since 2.10.0
     *
     * @param string $tabClass FQCN of the Tab Class
     */
    public function addTab($tabClass)
    {
        if ( ! is_subclass_of($tabClass, Tab::class)) {
            throw new \InvalidArgumentException('Class must extend the ' . Tab::class . ' class');
        }

        $tabId = $tabClass::id();

        if ($this->hasTab($tabId)) {
            throw new DuplicateTabException();
        }

        $this->tabs[$tabId] = $tabClass;
    }

    /**
     * Helper for adding a bunch of tabs at once
     *
     * @since 2.10.0
     *
     * @param string[] $tabClasses
     */
    public function addTabs(array $tabClasses)
    {
        foreach ($tabClasses as $tabClass) {
            $this->addTab($tabClass);
        }
    }

    public function registerTabRoutes()
    {
        foreach (give()->donorDashboardTabs->tabs as $tabClass) {
            $tab = new $tabClass;
            $tab->registerRoutes();
        }
    }

    public function enqueueTabAssets()
    {
        foreach (give()->donorDashboardTabs->tabs as $tabClass) {
            (new $tabClass)->enqueueAssets();
        }
    }
}

```
