You are here

class PartnerFactory in Lockr 8.2

Creates partner objects for Lockr clients as well as information about the currently detected partner.

Hierarchy

Expanded class hierarchy of PartnerFactory

1 file declares its use of PartnerFactory
LockrAdminController.php in src/Controller/LockrAdminController.php
1 string reference to 'PartnerFactory'
lockr.services.yml in ./lockr.services.yml
lockr.services.yml
1 service uses PartnerFactory
lockr.partner_factory in ./lockr.services.yml
Drupal\lockr\PartnerFactory

File

src/PartnerFactory.php, line 14

Namespace

Drupal\lockr
View source
class PartnerFactory {

  /** @var \Drupal\Core\State\StateInterface */
  protected $state;

  /**
   * Construct a new partner factory.
   *
   * @param \Drupal\Core\State\StateInterface
   */
  public function __construct(StateInterface $state) {
    $this->state = $state;
  }

  /**
   * Get a partner object for use with a Lockr client.
   *
   * @return \Lockr\PartnerInterface
   */
  public function getPartner() {
    $region = $this->state
      ->get('lockr.region', 'us');
    if ($this->state
      ->get('lockr.custom', FALSE)) {
      $cert_path = $this->state
        ->get('lockr.cert');
      if ($cert_path) {
        return new Partner($cert_path, 'custom', $region);
      }
      return new NullPartner($region);
    }
    $detected_partner = $this
      ->detectPartner();
    if (!$detected_partner) {
      return new NullPartner($region);
    }
    return new Partner($detected_partner['cert'], $detected_partner['name'], $region);
  }

  /**
   * Return information about the detected partner.
   *
   * @return array|null
   */
  public function detectPartner() {
    if (defined('PANTHEON_BINDING')) {
      return [
        'name' => 'pantheon',
        'title' => 'Pantheon',
        'description' => "The Pantheor is strong with this one.\n          We're detecting you 're on Pantheon and a friend of theirs is a friend of ours.\n          Welcome to Lockr.",
        'cert' => '/srv/bindings/' . PANTHEON_BINDING . '/certs/binding.pem',
      ];
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PartnerFactory::$state protected property @var \Drupal\Core\State\StateInterface
PartnerFactory::detectPartner public function Return information about the detected partner.
PartnerFactory::getPartner public function Get a partner object for use with a Lockr client.
PartnerFactory::__construct public function Construct a new partner factory.