<commit_before><?php

/*
 * This file is part of madewithlove/definitions
 *
 * (c) madewithlove <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 */

namespace Madewithlove\Definitions\Definitions\CommandBus;

use Assembly\ObjectDefinition;
use Assembly\Reference;
use League\Container\ImmutableContainerAwareInterface;
use League\Container\ImmutableContainerAwareTrait;
use League\Tactician\CommandBus;
use League\Tactician\Handler\CommandHandlerMiddleware;
use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor;
use League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor;
use League\Tactician\Handler\Locator\HandlerLocator;
use League\Tactician\Handler\Locator\InMemoryLocator;
use League\Tactician\Handler\MethodNameInflector\HandleInflector;
use League\Tactician\Handler\MethodNameInflector\MethodNameInflector;
use League\Tactician\Middleware;
use League\Tactician\Plugins\LockingMiddleware;
use Madewithlove\Definitions\Definitions\AbstractDefinitionProvider;

class TacticianDefinition extends AbstractDefinitionProvider implements ImmutableContainerAwareInterface
{
    use ImmutableContainerAwareTrait;

    /**
     * @var CommandNameExtractor
     */
    protected $extractor;

    /**
     * @var MethodNameInflector
     */
    protected $inflector;

    /**
     * @var HandlerLocator
     */
    protected $locator;

    /**
     * @param string $extractor
     * @param string $locator
     * @param string $inflector
     */
    public function __construct(
        $extractor = ClassNameExtractor::class,
        $locator = InMemoryLocator::class,
        $inflector = HandleInflector::class
    ) {
        $this->extractor = $extractor;
        $this->locator = $locator;
        $this->inflector = $inflector;
    }

    /**
     * {@inheritdoc}
     */
    public function getDefinitions()
    {
        return [
            CommandNameExtractor::class => new ObjectDefinition($this->extractor),
            HandlerLocator::class => new ObjectDefinition($this->locator),
            MethodNameInflector::class => new ObjectDefinition($this->inflector),
            Middleware::class => $this->getHandlerMiddleware(),
            CommandBus::class => $this->getCommandBus(),
            'bus' => new Reference(CommandBus::class),
        ];
    }

    /**
     * @return ObjectDefinition
     */
    protected function getCommandBus()
    {
        $bus = new ObjectDefinition(CommandBus::class);
        $bus->setConstructorArguments([
            new LockingMiddleware(),
            new Reference(Middleware::class),
        ]);

        return $bus;
    }

    /**
     * @return ObjectDefinition
     */
    protected function getHandlerMiddleware()
    {
        $middleware = new ObjectDefinition(CommandHandlerMiddleware::class);
        $middleware->setConstructorArguments(
            new Reference(CommandNameExtractor::class),<commit_msg>Remove LockingMiddleware by default in Tactician<commit_after><?php

/*
 * This file is part of madewithlove/definitions
 *
 * (c) madewithlove <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 */

namespace Madewithlove\Definitions\Definitions\CommandBus;

use Assembly\ObjectDefinition;
use Assembly\Reference;
use League\Container\ImmutableContainerAwareInterface;
use League\Container\ImmutableContainerAwareTrait;
use League\Tactician\CommandBus;
use League\Tactician\Handler\CommandHandlerMiddleware;
use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor;
use League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor;
use League\Tactician\Handler\Locator\HandlerLocator;
use League\Tactician\Handler\Locator\InMemoryLocator;
use League\Tactician\Handler\MethodNameInflector\HandleInflector;
use League\Tactician\Handler\MethodNameInflector\MethodNameInflector;
use League\Tactician\Middleware;
use League\Tactician\Plugins\LockingMiddleware;
use Madewithlove\Definitions\Definitions\AbstractDefinitionProvider;

class TacticianDefinition extends AbstractDefinitionProvider implements ImmutableContainerAwareInterface
{
    use ImmutableContainerAwareTrait;

    /**
     * @var CommandNameExtractor
     */
    protected $extractor;

    /**
     * @var MethodNameInflector
     */
    protected $inflector;

    /**
     * @var HandlerLocator
     */
    protected $locator;

    /**
     * @param string $extractor
     * @param string $locator
     * @param string $inflector
     */
    public function __construct(
        $extractor = ClassNameExtractor::class,
        $locator = InMemoryLocator::class,
        $inflector = HandleInflector::class
    ) {
        $this->extractor = $extractor;
        $this->locator = $locator;
        $this->inflector = $inflector;
    }

    /**
     * {@inheritdoc}
     */
    public function getDefinitions()
    {
        return [
            CommandNameExtractor::class => new ObjectDefinition($this->extractor),
            HandlerLocator::class => new ObjectDefinition($this->locator),
            MethodNameInflector::class => new ObjectDefinition($this->inflector),
            Middleware::class => $this->getHandlerMiddleware(),
            CommandBus::class => $this->getCommandBus(),
            'bus' => new Reference(CommandBus::class),
        ];
    }

    /**
     * @return ObjectDefinition
     */
    protected function getCommandBus()
    {
        $bus = new ObjectDefinition(CommandBus::class);
        $bus->setConstructorArguments([new Reference(Middleware::class)]);

        return $bus;
    }

    /**
     * @return ObjectDefinition
     */
    protected function getHandlerMiddleware()
    {
        $middleware = new ObjectDefinition(CommandHandlerMiddleware::class);
        $middleware->setConstructorArguments(
            new Reference(CommandNameExtractor::class),
{'fraction_non_alphanumeric': 0.1017933390264731, 'fraction_numerical': 0.0, 'mean_word_length': 3.416289592760181, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 39, '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': '2396811', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1582, 'n_words': 289}