<commit_before><?php

namespace Adldap\Connections;

use Adldap\Auth\Guard;
use Adldap\Contracts\Auth\GuardInterface;
use Adldap\Contracts\Connections\ConnectionInterface;
use Adldap\Contracts\Connections\ManagerInterface;
use Adldap\Exceptions\ConnectionException;
use Adldap\Models\Factory as ModelFactory;
use Adldap\Search\Factory as SearchFactory;

class Manager implements ManagerInterface
{
    /**
     * @var ConnectionInterface
     */
    protected $connection;

    /**
     * @var Configuration
     */
    protected $configuration;

    /**
     * @var GuardInterface
     */
    protected $guard;

    /**
     * {@inheritdoc}
     */
    public function __construct(ConnectionInterface $connection, Configuration $configuration)
    {
        $this->setConnection($connection);
        $this->setConfiguration($configuration);

        // Prepare the connection.
        $this->prepareConnection();
    }

    /**
     * {@inheritdoc}
     */
    public function __destruct()
    {
        if ($this->connection instanceof ConnectionInterface && $this->connection->isBound()) {
            $this->connection->close();
        }
    }

    /**
     * {@inheritdoc}
     */
    public function getConnection()
    {
        return $this->connection;
    }

    /**
     * {@inheritdoc}
     */
    public function getConfiguration()
    {
        return $this->configuration;
    }

    /**
     * {@inheritdoc}
     */
    public function getGuard()
    {
        if (!$this->guard instanceof GuardInterface) {
            $this->setGuard($this->getDefaultGuard($this->connection, $this->configuration));
        }

        return $this->guard;
    }

    /**
     * {@inheritdoc}
     */
    public function getDefaultGuard(ConnectionInterface $connection, Configuration $configuration)
    {
        return new Guard($connection, $configuration);
    }

    /**
     * {@inheritdoc}
     */
    public function setConnection(ConnectionInterface $connection)
    {
        $this->connection = $connection;
    }

    /**
     * {@inheritdoc}
     */
    public function setConfiguration(Configuration $configuration)
    {
        $this->configuration = $configuration;
    }

    /**
     * {@inheritdoc}
     */
    public function setGuard(GuardInterface $guard)
    {
        $this->guard = $guard;
    }

    /**
     * {@inheritdoc}
     */
    public function create()
    {
        return new ModelFactory($this->search()->getQueryBuilder());
    }

    /**
     * {@inheritdoc}
     */
    public function search()
    {
        return new SearchFactory($this->connection, $this->configuration->getBaseDn());
    }

    /**
     * {@inheritdoc}
     */
    public function connect($username = null, $password = null)
    {
        $controllers = $this->configuration->getDomainControllers();

        $port = $this->configuration->getPort();

        // Connect to the LDAP server.
        if ($this->connection->connect($controllers, $port)) {
            $protocol = 3;
            $followReferrals = $this->configuration->getFollowReferrals();<commit_msg>Added schema to connection manager<commit_after><?php

namespace Adldap\Connections;

use Adldap\Auth\Guard;
use Adldap\Contracts\Auth\GuardInterface;
use Adldap\Contracts\Connections\ConnectionInterface;
use Adldap\Contracts\Connections\ManagerInterface;
use Adldap\Contracts\Schemas\SchemaInterface;
use Adldap\Exceptions\ConnectionException;
use Adldap\Models\Factory as ModelFactory;
use Adldap\Search\Factory as SearchFactory;

class Manager implements ManagerInterface
{
    /**
     * @var ConnectionInterface
     */
    protected $connection;

    /**
     * @var Configuration
     */
    protected $configuration;

    /**
     * @var SchemaInterface
     */
    protected $schema;

    /**
     * @var GuardInterface
     */
    protected $guard;

    /**
     * {@inheritdoc}
     */
    public function __construct(ConnectionInterface $connection, Configuration $configuration, SchemaInterface $schema)
    {
        $this->setConnection($connection);
        $this->setConfiguration($configuration);
        $this->setSchema($schema);

        // Prepare the connection.
        $this->prepareConnection();
    }

    /**
     * {@inheritdoc}
     */
    public function __destruct()
    {
        if ($this->connection instanceof ConnectionInterface && $this->connection->isBound()) {
            $this->connection->close();
        }
    }

    /**
     * {@inheritdoc}
     */
    public function getConnection()
    {
        return $this->connection;
    }

    /**
     * {@inheritdoc}
     */
    public function getConfiguration()
    {
        return $this->configuration;
    }

    /**
     * {@inheritdoc}
     */
    public function getGuard()
    {
        if (!$this->guard instanceof GuardInterface) {
            $this->setGuard($this->getDefaultGuard($this->connection, $this->configuration));
        }

        return $this->guard;
    }

    /**
     * {@inheritdoc}
     */
    public function getDefaultGuard(ConnectionInterface $connection, Configuration $configuration)
    {
        return new Guard($connection, $configuration);
    }

    /**
     * {@inheritdoc}
     */
    public function setConnection(ConnectionInterface $connection)
    {
        $this->connection = $connection;
    }

    /**
     * {@inheritdoc}
     */
    public function setConfiguration(Configuration $configuration)
    {
        $this->configuration = $configuration;
    }

    /**
     * {@inheritdoc}
     */
    public function setSchema(SchemaInterface $schema)
    {
        $this->schema = $schema;
    }

    /**
     * {@inheritdoc}
     */
    public function setGuard(GuardInterface $guard)
    {
        $this->guard = $guard;
    }

    /**
     * {@inheritdoc}
     */
    public function create()
    {
        return new ModelFactory($this->search()->getQueryBuilder(), $this->schema);
    }

    /**
     * {@inheritdoc}
     */
    public function search()
    {
        return new SearchFactory($this->connection, $this->schema, $this->configuration->getBaseDn());
    }

    /**
     * {@inheritdoc}
     */
    public function connect($username = null, $password = <PASSWORD>)
    {
        $controllers = $this->configuration->getDomainControllers();

        $port = $this->configuration->getPort();

        // Connect to the LDAP server.
        if ($this->connection->connect($controllers, $port)) {
            $protocol = 3;
            $followReferrals = $this->configuration->getFollowReferrals();
{'fraction_non_alphanumeric': 0.13404743687834736, 'fraction_numerical': 0.000306044376434583, 'mean_word_length': 2.346646185355863, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 72, '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': '4198842', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1736, 'n_words': 329}