<commit_before><?php

/*
 * This file is part of the json-pointer library.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ChiliLabs\JsonPointer\Access;

use ChiliLabs\JsonPointer\Access\Accessor\AccessorInterface;
use ChiliLabs\JsonPointer\Exception\NoMatchingAccessorException;

/**
 * @author <NAME> <<EMAIL>>
 */
class AccessorFactory
{
    /**
     * @var AccessorInterface[]
     */
    private $accessorList;

    /**
     * @param AccessorInterface[] $accessorList
     */
    public function __construct(array $accessorList = array())
    {
        $this->accessorList = $accessorList;
    }

    /**
     * @param AccessorInterface $accessor
     */
    public function registerAccessor(AccessorInterface $accessor)
    {
        $this->accessorList[] = $accessor;
        array_unique($this->accessorList);
    }

    /**
     * @param mixed $node
     *
     * @return AccessorInterface
     *
     * @throws NoMatchingAccessorException
     */
    public function findAccessorForNode($node)
    {
        foreach ($this->accessorList as $accessor) {
            if ($accessor->supports($node)) {
                return $accessor;
            }
        }

        throw new NoMatchingAccessorException(
            sprintf('Could not find a matching Accessor for node of type %s.', gettype($node))
        );
    }
}<commit_msg>allow registering of accessors multiple times<commit_after><?php

/*
 * This file is part of the json-pointer library.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ChiliLabs\JsonPointer\Access;

use ChiliLabs\JsonPointer\Access\Accessor\AccessorInterface;
use ChiliLabs\JsonPointer\Exception\NoMatchingAccessorException;

/**
 * @author <NAME> <<EMAIL>>
 */
class AccessorFactory
{
    /**
     * @var AccessorInterface[]
     */
    private $accessorList = array();

    /**
     * @param AccessorInterface[] $accessorList
     */
    public function __construct(array $accessorList = array())
    {
        $this->accessorList = $accessorList;
    }

    /**
     * @param AccessorInterface $accessor
     */
    public function registerAccessor(AccessorInterface $accessor)
    {
        $this->accessorList[] = $accessor;
    }

    /**
     * @param mixed $node
     *
     * @return AccessorInterface
     *
     * @throws NoMatchingAccessorException
     */
    public function findAccessorForNode($node)
    {
        foreach ($this->accessorList as $accessor) {
            if ($accessor->supports($node)) {
                return $accessor;
            }
        }

        throw new NoMatchingAccessorException(
            sprintf('Could not find a matching Accessor for node of type %s.', gettype($node))
        );
    }
}
{'fraction_non_alphanumeric': 0.11179910560715514, 'fraction_numerical': 0.0, 'mean_word_length': 2.546341463414634, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, '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': '6621602', 'n_tokens_mistral': 826, 'n_tokens_neox': 817, 'n_words': 201}