WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Самая быстрая Тема-конструктор для WordPress
класс не описан

YoastSEO_Vendor\League\OAuth2\Client\Grant

GrantFactory{} Yoast 1.0

Represents a factory used when retrieving an authorization grant type.

Хуков нет.

Возвращает

Null. Ничего.

Использование

$GrantFactory = new GrantFactory();
// use class methods

Методы

  1. checkGrant($class)
  2. getGrant($name)
  3. isGrant($class)
  4. registerDefaultGrant($name)
  5. setGrant($name, \YoastSEO_Vendor\League\OAuth2\Client\Grant\AbstractGrant $grant)

Код GrantFactory{} Yoast 15.2

<?php
class GrantFactory
{
    /**
     * @var array
     */
    protected $registry = [];
    /**
     * Defines a grant singleton in the registry.
     *
     * @param  string $name
     * @param  AbstractGrant $grant
     * @return self
     */
    public function setGrant($name, \YoastSEO_Vendor\League\OAuth2\Client\Grant\AbstractGrant $grant)
    {
        $this->registry[$name] = $grant;
        return $this;
    }
    /**
     * Returns a grant singleton by name.
     *
     * If the grant has not be registered, a default grant will be loaded.
     *
     * @param  string $name
     * @return AbstractGrant
     */
    public function getGrant($name)
    {
        if (empty($this->registry[$name])) {
            $this->registerDefaultGrant($name);
        }
        return $this->registry[$name];
    }
    /**
     * Registers a default grant singleton by name.
     *
     * @param  string $name
     * @return self
     */
    protected function registerDefaultGrant($name)
    {
        // PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode'
        $class = \str_replace(' ', '', \ucwords(\str_replace(['-', '_'], ' ', $name)));
        $class = 'YoastSEO_Vendor\\League\\OAuth2\\Client\\Grant\\' . $class;
        $this->checkGrant($class);
        return $this->setGrant($name, new $class());
    }
    /**
     * Determines if a variable is a valid grant.
     *
     * @param  mixed $class
     * @return boolean
     */
    public function isGrant($class)
    {
        return \is_subclass_of($class, \YoastSEO_Vendor\League\OAuth2\Client\Grant\AbstractGrant::class);
    }
    /**
     * Checks if a variable is a valid grant.
     *
     * @throws InvalidGrantException
     * @param  mixed $class
     * @return void
     */
    public function checkGrant($class)
    {
        if (!$this->isGrant($class)) {
            throw new \YoastSEO_Vendor\League\OAuth2\Client\Grant\Exception\InvalidGrantException(\sprintf('Grant "%s" must extend AbstractGrant', \is_object($class) ? \get_class($class) : $class));
        }
    }
}