<?php

/*
 * This file is part of the Hierarchy package.
 *
 * (c) Giuseppe Mazzapica <giuseppe.mazzapica@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Brain\Hierarchy\Finder;

/**
 * A wrapper around a callback. Useful for tests and quick and dirty customizations.
 *
 * @author  Giuseppe Mazzapica <giuseppe.mazzapica@gmail.com>
 * @license http://opensource.org/licenses/MIT MIT
 */
class ByCallback implements TemplateFinder
{
    use FindFirstTrait;

    /**
     * @var callable
     */
    private $finder;

    /**
     * @param callable $finder
     */
    public function __construct(callable $finder)
    {
        $this->finder = $finder;
    }

    /**
     * @param string $template
     * @param string $type
     * @return string
     */
    public function find(string $template, string $type): string
    {
        $callback = $this->finder;

        return (string)$callback($template, $type);
    }
}
