You are here

public function Kitchen::ship in Bakery Single Sign-On System 8.2

Ship a cookie to child sites.

Parameters

\Drupal\bakery\Cookies\RemoteCookieInterface $cookie: The cookie data.

Return value

\Psr\Http\Message\ResponseInterface|bool

File

src/Kitchen.php, line 215

Class

Kitchen

Namespace

Drupal\bakery

Code

public function ship(RemoteCookieInterface $cookie) {
  $path = $cookie
    ->getPath();
  $data = $this
    ->bakeData($cookie);
  if ($this->config
    ->get('bakery_is_master')) {
    $children = $this->config
      ->get('bakery_slaves') ?: [];
    foreach ($children as $child) {
      $result = $this
        ->shipItGood($child . $path, $cookie::getName(), $data);
      if (!$result) {
        if ($this->currentUser
          ->hasPermission('administer bakery')) {
          $this
            ->messenger()
            ->addError(t('Error occurred talking to the site at %url', [
            '%url' => $child,
          ]));
        }
      }
      else {
        if ($this->currentUser
          ->hasPermission('administer bakery')) {
          $this
            ->messenger()
            ->addMessage((string) $result
            ->getBody());
        }
      }
    }
    return TRUE;
  }

  // From child site, send to master.
  $master = $this->config
    ->get('bakery_master');
  return $this
    ->shipItGood($master . $path, $cookie::getName(), $data);
}