<commit_before><?php
/**
 * Class Client | Sajari/Client/Client.php
 *
 * @package     sajari-sdk-php
 */

namespace Sajari;

Internal\Utils::_require_all(__DIR__.'/proto', 10);

/**
 * Class Client
 */
class Client
{
    /** @var string $project */
    private $project = '';
    /** @var string $collection */
    private $collection = '';

    /** @var string $endpoint */
    private $endpoint = 'api.sajari.com:443';
    /** @var string $credentials */
    private $credentials = "";
    private $channelCredentials = NULL;

    /** @var Engine\Store\Record\StoreClient $storeClient */
    private $storeClient;
    /** @var Api\Query\V1\QueryClient $queryClient */
    private $queryClient;
    /** @var Engine\Schema\SchemaClient $schemaClient */
    private $schemaClient;

    /**
     * Client constructor creates a new client to make calls to a
     * Collection.
     *
     * @param string $project The project.
     * @param string $collection The collection.
     * @param Opt[] $opts Options to configure dialing behaviour.
     */
    public function __construct($project, $collection, $opts = [])
    {
        $this->project = $project;
        $this->collection = $collection;

        $this->channelCredentials = \Grpc\ChannelCredentials::createSsl(
            file_get_contents(dirname(__FILE__) . "/roots.pem")
        );

        /** @var $opt Opt */
        foreach ($opts as $opt) {
            $opt->Apply($this);
        }
    }

    private function getQueryClient() {
        if ($this->queryClient === NULL) {
            $this->queryClient = new Api\Query\V1\QueryClient(
                $this->endpoint,
                ['credentials' => $this->channelCredentials]
            );
        }
        return $this->queryClient;
    }

    private function getStoreClient() {
        if ($this->storeClient === NULL) {
            $this->storeClient = new Engine\Store\Record\StoreClient(
                $this->endpoint,
                ['credentials' => $this->channelCredentials]
            );
        }
        return $this->storeClient;
    }

    private function getSchemaClient() {
        if ($this->schemaClient === NULL) {
            $this->schemaClient = new Engine\Schema\SchemaClient(
                $this->endpoint,
                ['credentials' => $this->channelCredentials]
            );
        }
        return $this->schemaClient;
    }

    /**
     * Schema returns a handler to a Schema client.
     * @return Schema
     */
    public function schema() {
        return new Schema($this->getSchemaClient(), $this->getCallMeta());
    }

    /**
     * Sets the channel credentials used on each connection.
     *
     * @param \Grpc\ChannelCredentials $channelCredentials
     */
    public function setChannelCredentials($channelCredentials) {
        $this->channelCredentials = $channelCredentials;
    }

    /**
     * Sets the credentials used in every RPC call.
     *
     * @param string $credentials
     */
    public function setCredentials($credentials) {
        $this->credentials = $credentials;
    }

    /**
     * Set the endpoint used on each connection.
     *
     * @param string $credentials
     */
    public function setEndpoint($endpoint) {
        $this->endpoint = $endpoint;
    }

    /**
     * @return array
     */
    private function getCallMeta()
    {
        return array(
            'project' => [$this->project],
            'collection' => [$this->collection],
            'authorization' => [$this->credentials],
        );
    }

    /**
     * A key is a unique identifier for a Record in a Collection.
     *
     * @param string $field The field.
     * @param string $value The value of the identifier.
     * @return Key The key.
     */
    public function key($field, $value) {
        return new Key($field, $value);
    }

    /**
     * Get returns a record corresponding to a unique key.
     *
     * This method is equivalent to GetMulti([$key]) except that any
     * errors returned will be thrown as exceptions.
     *
     * @param Key $key The
     * @return array Field-value pairs.
     * @throws Error\RecordNotFoundException
     */
    public function get(Key $key)<commit_msg>client: add keys method to create multiple keys<commit_after><?php
/**
 * Class Client | Sajari/Client/Client.php
 *
 * @package     sajari-sdk-php
 */

namespace Sajari;

Internal\Utils::_require_all(__DIR__.'/proto', 10);

/**
 * Class Client
 */
class Client
{
    /** @var string $project */
    private $project = '';
    /** @var string $collection */
    private $collection = '';

    /** @var string $endpoint */
    private $endpoint = 'api.sajari.com:443';
    /** @var string $credentials */
    private $credentials = "";
    private $channelCredentials = NULL;

    /** @var Engine\Store\Record\StoreClient $storeClient */
    private $storeClient;
    /** @var Api\Query\V1\QueryClient $queryClient */
    private $queryClient;
    /** @var Engine\Schema\SchemaClient $schemaClient */
    private $schemaClient;

    /**
     * Client constructor creates a new client to make calls to a
     * Collection.
     *
     * @param string $project The project.
     * @param string $collection The collection.
     * @param Opt[] $opts Options to configure dialing behaviour.
     */
    public function __construct($project, $collection, $opts = [])
    {
        $this->project = $project;
        $this->collection = $collection;

        $this->channelCredentials = \Grpc\ChannelCredentials::createSsl(
            file_get_contents(dirname(__FILE__) . "/roots.pem")
        );

        /** @var $opt Opt */
        foreach ($opts as $opt) {
            $opt->Apply($this);
        }
    }

    private function getQueryClient() {
        if ($this->queryClient === NULL) {
            $this->queryClient = new Api\Query\V1\QueryClient(
                $this->endpoint,
                ['credentials' => $this->channelCredentials]
            );
        }
        return $this->queryClient;
    }

    private function getStoreClient() {
        if ($this->storeClient === NULL) {
            $this->storeClient = new Engine\Store\Record\StoreClient(
                $this->endpoint,
                ['credentials' => $this->channelCredentials]
            );
        }
        return $this->storeClient;
    }

    private function getSchemaClient() {
        if ($this->schemaClient === NULL) {
            $this->schemaClient = new Engine\Schema\SchemaClient(
                $this->endpoint,
                ['credentials' => $this->channelCredentials]
            );
        }
        return $this->schemaClient;
    }

    /**
     * Schema returns a handler to a Schema client.
     * @return Schema
     */
    public function schema() {
        return new Schema($this->getSchemaClient(), $this->getCallMeta());
    }

    /**
     * Sets the channel credentials used on each connection.
     *
     * @param \Grpc\ChannelCredentials $channelCredentials
     */
    public function setChannelCredentials($channelCredentials) {
        $this->channelCredentials = $channelCredentials;
    }

    /**
     * Sets the credentials used in every RPC call.
     *
     * @param string $credentials
     */
    public function setCredentials($credentials) {
        $this->credentials = $credentials;
    }

    /**
     * Set the endpoint used on each connection.
     *
     * @param string $credentials
     */
    public function setEndpoint($endpoint) {
        $this->endpoint = $endpoint;
    }

    /**
     * @return array
     */
    private function getCallMeta()
    {
        return array(
            'project' => [$this->project],
            'collection' => [$this->collection],
            'authorization' => [$this->credentials],
        );
    }

    /**
     * A key is a unique identifier for a Record in a Collection.
     *
     * @param string $field The field.
     * @param string $value The value of the identifier.
     * @return Key The key.
     */
    public function key($field, $value) {
        return new Key($field, $value);
    }

    /**
     * Create multiple keys with the same field.
     *
     * @param string $field The field.
     * @param array $values Values to create into keys.
     * @return Key[] The keys.
     */
    public function keys($field, array $values) {
        $keys = [];
        foreach($values as $value) {
            $keys[] = new Key($field, $value);
        }
        return $keys;
    }

    /**
     * Get returns a record corresponding to a unique key.
     *
     * This method is equivalent to GetMulti([$key]) except that any
     * errors returned will be thrown as exceptions.
     *
     * @param Key $key The
     * @return array Field-value pairs.
     * @throws Error\RecordNotFoundException
     */
    public function get(Key $key)
{'fraction_non_alphanumeric': 0.12764512843725245, 'fraction_numerical': 0.0015842480479800838, 'mean_word_length': 2.064493758668516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3703928', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2387, 'n_words': 643}