# wp-optimize/4.7.0/vendor/intervention/httpauth/src/Environment.php

WP-Optimize – Cache, Compress images, Minify &amp; Clean database to boost page speed &amp; performance, version 4.7.0. 56 lines.

- Page: https://pluginprobe.com/plugins/wp-optimize/4.7.0/code/vendor/intervention/httpauth/src/Environment.php
- Raw: https://pluginprobe.com/plugins/wp-optimize/4.7.0/raw/vendor/intervention/httpauth/src/Environment.php
- Modified: 2021-06-07T22:42:16+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/wp-optimize/4.7.0/code/vendor/intervention/httpauth/src/Environment.php#L10-L20`.

```php
<?php

namespace Intervention\HttpAuth;

use Exception;

class Environment
{
    /**
     * Available auth tokens
     *
     * @var array
     */
    protected $tokenClassnames = [
        Token\PhpAuthUser::class,
        Token\HttpAuthentification::class,
        Token\RedirectHttpAuthorization::class,
        Token\PhpAuthDigest::class,
        Token\HttpAuthorization::class,
    ];

    /**
     * Get first active auth token from all available tokens
     *
     * @return TokenInterface
     */
    public function getToken(): TokenInterface
    {
        foreach ($this->tokenClassnames as $classname) {
            if ($auth = $this->getActiveTokenOrNull($classname)) {
                return $auth;
            }
        }

        return new Token\NullToken();
    }

    /**
     * Try to parse auth token from given classname. Returns token object
     * if token is active and could be parsed or null.
     *
     * @param  string $classname
     * @return TokenInterface|null
     */
    private function getActiveTokenOrNull($classname)
    {
        try {
            $auth = new $classname();
        } catch (Exception $e) {
            $auth = null;
        }

        return $auth;
    }
}

```
