Checks if the client instance satisfies the required conditions needed to
initialize a PUB/SUB consumer.

@param ClientInterface $client Client instance used by the consumer.

@throws NotSupportedException
427250
private function checkCapabilities(ClientInterface $client)
    {
        if ($client->getConnection() instanceof AggregateConnectionInterface) {
            throw new NotSupportedException(
                'Cannot initialize a PUB/SUB consumer over aggregate connections.'
            );
        }

        $commands = array('publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe');

        if ($client->getProfile()->supportsCommands($commands) === false) {
            throw new NotSupportedException(
                'The current profile does not support PUB/SUB related commands.'
            );
        }
    }
343154
public static function create(ApiClientInterface $client, UserInterface $user = null)
    {
        $accessToken = new self();
        $accessToken->setUser($user);
        $accessToken->setClient($client);

        return $accessToken;
    }
346692
public function isEligible(PromotionSubjectInterface $subject, array $configuration): bool
    {
        if (!$subject instanceof OrderInterface) {
            throw new UnsupportedTypeException($subject, OrderInterface::class);
        }

        if (null === $address = $subject->getShippingAddress()) {
            return false;
        }

        $country = $this->countryRepository->findOneBy(['code' => $address->getCountryCode()]);

        if (!$country instanceof CountryInterface) {
            return false;
        }

        return $country->getCode() === $configuration['country'];
    }
1196473
protected function destoryClient($client)
    {
        if ($client != null && $this->client->isConnected()) {
            $client->close();
        }
        $this->client = null;
    }
835300
public function isEligible(PromotionSubjectInterface $subject, array $configuration): bool
    {
        if (!$subject instanceof OrderInterface) {
            throw new UnsupportedTypeException($subject, OrderInterface::class);
        }

        if (!isset($configuration['nth']) || !is_int($configuration['nth'])) {
            return false;
        }

        $customer = $subject->getCustomer();
        if (null === $customer) {
            return false;
        }

        //eligible if it is first order of guest and the promotion is on first order
        if (null === $customer->getId()) {
            return 1 === $configuration['nth'];
        }

        return $this->orderRepository->countByCustomer($customer) === ($configuration['nth'] - 1);
    }
1017513
public void register(Client client) {
        Exceptions.checkNotClosed(this.closed.get(), this);
        Preconditions.checkNotNull(client, "client");
        synchronized (this.clients) {
            if (!this.clients.contains(client)) {
                this.clients.add(client);
                client.updateGenerations(this.currentGeneration.get(), this.oldestGeneration.get());
            }
        }

        log.info("{} Registered {}.", TRACE_OBJECT_ID, client);
    }
591216
public function setClient(Client $client)
    {
        // Assign the client.
        $this->client = $client;
        $this->client->setDefaultOption('headers', ['Content-Type' => 'application/json']);

        // Allow chaining.
        return $this;
    }
320786
public function client($alias)
    {
        if (is_int($alias) && isset($this->clients[$alias])) {
            return $this->clients[$alias];
        } elseif (isset($this->aliases[$alias])) {
            return $this->aliases[$alias];
        }
        throw new Exception("Client $alias does not exist.");
    }
812141
public boolean hasRequiredClientProps() {
    boolean valid = true;
    valid &= verifyStringPropSet(CONNECTION_APPLICATION_NAME_PROP, CLIENT_APPLICATION_NAME_PROP);
    valid &= verifyStringPropSet(ACCUMULO_USER_PROP, CLIENT_ACCUMULO_USER_PROP);
    valid &= verifyStringPropSet(ACCUMULO_PASSWORD_PROP, CLIENT_ACCUMULO_PASSWORD_PROP);
    valid &= verifyStringPropSet(ACCUMULO_INSTANCE_PROP, CLIENT_ACCUMULO_INSTANCE_PROP);
    return valid;
  }
57723
public void initialize(IClient client) {
        if (log.isDebugEnabled()) {
            log.debug("initialize - client: {}", client);
        }
        if (this.client != null && this.client instanceof Client && !this.client.equals(client)) {
            // unregister old client
            if (log.isTraceEnabled()) {
                log.trace("Unregistering previous client: {}", this.client);
            }
            ((Client) this.client).unregister(this, false);
        }
        this.client = client;
        if (this.client instanceof Client && !((Client) this.client).isRegistered(this)) {
            // register new client
            if (log.isTraceEnabled()) {
                log.trace("Registering client: {}", this.client);
            }
            ((Client) this.client).register(this);
        }
    }
83234
private function initializeClient($url, ClientInterface $client = null)
    {
        if ($client) {
            $this->client = $client;
        } else {
            $this->client = new LocalClient($url);
        }
    }
662675
public function isAllowed(RolesAwareInterface $client)
    {
        return ($this->acl) ? $this->acl->isAllowed($client) : false;
    }
1262632
protected function registerClientSubscribers(ClientInterface $client)
    {
        $client->on('irc.received', function ($message, $write, $connection) {
            $this->processClientEvent('irc.received', $message, $connection, $write);
        });

        $client->on('irc.sent', function ($message, $write, $connection) {
            $parsed = $this->getParser()->parse($message);
            if (!$parsed) {
                return;
            }
            $this->processClientEvent('irc.sent', $parsed, $connection, $write);
        });

        $client->on('irc.tick', function ($write, $connection) {
            $this->processOutgoingEvents($connection, $write);
        });
    }
305353
public function validateSslCertificate($client) {
        $response = $client->request('GET', 'https://api.twilio.com:8443');

        if ($response->getStatusCode() < 200 || $response->getStatusCode() > 300) {
            throw new TwilioException("Failed to validate SSL certificate");
        }
    }
122553
public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
    {
        $this->controlPacketIdentifiers($originalRequest);
        $pubRel = new PubRel($this->logger);
        $pubRel->setPacketIdentifier($this->packetIdentifier);
        $pubComp = $client->processObject($pubRel);
        $this->logger->debug('Created PubRel as response, got PubComp back', ['PubComp' => $pubComp]);
        return true;
    }
166854
public function setRemoteUser(ClientInterface $client, IdentityInterface $user)
    {
        $model = $this->getRemoteUser($client);
        $model->client_id = $user->getId();
        $model->save();

        return $user;
    }
1046824
public function validateRequest(RequestInterface $request, ResponseInterface $response)
    {
        if (!$clientData = $this->getClientCredentials($request, $response)) {
            return false;
        }

        if (!isset($clientData['client_id'])) {
            throw new LogicException('the clientData array must have "client_id" set');
        }

        if (!isset($clientData['client_secret']) || $clientData['client_secret'] == '') {
            if (!$this->config['allow_public_clients']) {
                $response->setError(400, 'invalid_client', 'client credentials are required');

                return false;
            }

            if (!$this->storage->isPublicClient($clientData['client_id'])) {
                $response->setError(400, 'invalid_client', 'This client is invalid or must authenticate using a client secret');

                return false;
            }
        } elseif ($this->storage->checkClientCredentials($clientData['client_id'], $clientData['client_secret']) === false) {
            $response->setError(400, 'invalid_client', 'The client credentials are invalid');

            return false;
        }

        $this->clientData = $clientData;

        return true;
    }