Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Conversation

OskarStark
Copy link
Contributor

@OskarStark OskarStark commented Jan 2, 2025

This is just an idea.
The @final that we don't cover BC and you extend on your own risk, that's how Symfony is doing such things.

I could then end up with just this to achieve my goals:

<?php

declare(strict_types=1);

namespace App\Bridge\PhpLlm;

use PhpLlm\LlmChain\Model\Message\MessageBag;
use PhpLlm\LlmChain\Model\Message\MessageInterface;

final class EnhancedMessageBag extends MessageBag
{
    public function __construct(MessageInterface ...$messages)
    {
        parent::__construct(...array_map([$this, 'wrap'], array_values($messages)));
    }

    public function add(MessageInterface $message): void
    {
        parent::add($this->wrap($message));
    }

    private function wrap(MessageInterface $message): MessageInterface
    {
        if ($message instanceof EnhancedMessage) {
            return $message;
        }

        return new EnhancedMessage($message);
    }
}

@OskarStark OskarStark self-assigned this Jan 2, 2025
@OskarStark OskarStark added enhancement New feature or request idea 💡 labels Jan 2, 2025
@OskarStark OskarStark changed the title Unfinalize Unfinalize MessageBag Jan 2, 2025
Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty

@chr-hertel chr-hertel merged commit b60816a into main Jan 2, 2025
7 checks passed
@chr-hertel chr-hertel deleted the feature/unfinalize branch January 2, 2025 07:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request idea 💡
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants