<commit_before><?php

namespace Adldap\Objects;

use Adldap\Interfaces\ConnectionInterface;

/**
 * Class LdapEntry
 * @package Adldap\Objects
 */
class LdapEntry extends AbstractObject
{
    /**
     * The current LDAP connection.
     *
     * @var ConnectionInterface
     */
    protected $connection;

    /**
     * Constructor.
     *
     * @param array $attributes
     * @param ConnectionInterface $connection
     */
    public function __construct(array $attributes = array(), ConnectionInterface $connection)
    {
        // Set the connection
        $this->connection = $connection;

        // Construct the entry
        $this->applyAttributes($attributes);
    }

    /**
     * Applies the proper object attributes if they exist
     * inside the specified attributes array.
     *
     * @param array $attributes
     */
    public function applyAttributes($attributes)
    {
        // Apply generic attributes
        $this->applyGenericAttributes($attributes);

        // Apply user attributes
        $this->applyUserAttributes($attributes);

        // Apply computer attributes
        $this->applyComputerAttributes($attributes);
    }

    /**
     * Applies the LDAP entry's generic attributes.
     *
     * @param array $attributes
     */
    public function applyGenericAttributes(array $attributes = array())
    {
        // Does the entry contain a common name?
        if(array_key_exists('cn', $attributes))
        {
            $this->setAttribute('cn', $attributes['cn'][0]);
        }

        // Does the entry contain a description?
        if(array_key_exists('description', $attributes))
        {
            $this->setAttribute('description', $attributes['description'][0]);
        }

        // Does the entry contain a distinguished name?
        if(array_key_exists('distinguishedname', $attributes))
        {
            $dn = $attributes['distinguishedname'][0];

            // We'll assign the string distinguished name
            $this->setAttribute('dn', $dn);

            // As well as parse it into a array
            $this->setAttribute('dn_array', $this->connection->explodeDn($dn, true));
        }

        // Does the entry contain an object category?
        if(array_key_exists('objectcategory', $attributes))
        {
            $this->setAttribute('objectcategory', $attributes['objectcategory'][0]);
        }

        if(array_key_exists('info', $attributes))
        {
            $this->setAttribute('info', $attributes['info'][0]);
        }
    }

    /**
     * Applies the entry's user attributes.
     *
     * @param array $attributes<commit_msg>Add possibility of 'dn' generic attribute for distinguished name<commit_after><?php

namespace Adldap\Objects;

use Adldap\Interfaces\ConnectionInterface;

/**
 * Class LdapEntry
 * @package Adldap\Objects
 */
class LdapEntry extends AbstractObject
{
    /**
     * The current LDAP connection.
     *
     * @var ConnectionInterface
     */
    protected $connection;

    /**
     * Constructor.
     *
     * @param array $attributes
     * @param ConnectionInterface $connection
     */
    public function __construct(array $attributes = array(), ConnectionInterface $connection)
    {
        // Set the connection
        $this->connection = $connection;

        // Construct the entry
        $this->applyAttributes($attributes);
    }

    /**
     * Applies the proper object attributes if they exist
     * inside the specified attributes array.
     *
     * @param array $attributes
     */
    public function applyAttributes($attributes)
    {
        // Apply generic attributes
        $this->applyGenericAttributes($attributes);

        // Apply user attributes
        $this->applyUserAttributes($attributes);

        // Apply computer attributes
        $this->applyComputerAttributes($attributes);
    }

    /**
     * Applies the LDAP entry's generic attributes.
     *
     * @param array $attributes
     */
    public function applyGenericAttributes(array $attributes = array())
    {
        // Does the entry contain a common name?
        if(array_key_exists('cn', $attributes))
        {
            $this->setAttribute('cn', $attributes['cn'][0]);
        }

        // Does the entry contain a description?
        if(array_key_exists('description', $attributes))
        {
            $this->setAttribute('description', $attributes['description'][0]);
        }

        // Does the entry contain a distinguished name?
        if(array_key_exists('dn', $attributes) || array_key_exists('distinguishedname', $attributes))
        {
            $dn = (array_key_exists('dn', $attributes)) ? $attributes['dn'] : $attributes['distinguishedname'][0];

            // We'll assign the string distinguished name
            $this->setAttribute('dn', $dn);

            // As well as parse it into a array
            $this->setAttribute('dn_array', $this->connection->explodeDn($dn, true));
        }

        // Does the entry contain an object category?
        if(array_key_exists('objectcategory', $attributes))
        {
            $this->setAttribute('objectcategory', $attributes['objectcategory'][0]);
        }

        if(array_key_exists('info', $attributes))
        {
            $this->setAttribute('info', $attributes['info'][0]);
        }
    }

    /**
     * Applies the entry's user attributes.
     *
     * @param array $attributes
{'fraction_non_alphanumeric': 0.12130723781388479, 'fraction_numerical': 0.001846381093057607, 'mean_word_length': 2.3376463339494764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '647091', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1365, 'n_words': 338}