|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +require_once dirname(__DIR__).'/bootstrap.php'; |
| 13 | + |
| 14 | +use Symfony\AI\Chat\Bridge\HttpFoundation\SessionStore; |
| 15 | +use Symfony\AI\Chat\Bridge\Local\CacheStore; |
| 16 | +use Symfony\AI\Chat\Bridge\Local\InMemoryStore; |
| 17 | +use Symfony\AI\Chat\Command\DropStoreCommand; |
| 18 | +use Symfony\AI\Chat\Command\SetupStoreCommand; |
| 19 | +use Symfony\Component\Cache\Adapter\ArrayAdapter; |
| 20 | +use Symfony\Component\Console\Application; |
| 21 | +use Symfony\Component\Console\Input\ArrayInput; |
| 22 | +use Symfony\Component\Console\Output\ConsoleOutput; |
| 23 | +use Symfony\Component\DependencyInjection\ServiceLocator; |
| 24 | +use Symfony\Component\HttpFoundation\Request; |
| 25 | +use Symfony\Component\HttpFoundation\RequestStack; |
| 26 | +use Symfony\Component\HttpFoundation\Session\Session; |
| 27 | +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; |
| 28 | + |
| 29 | +$factories = [ |
| 30 | + 'cache' => static fn (): CacheStore => new CacheStore(new ArrayAdapter(), cacheKey: 'symfony'), |
| 31 | + 'memory' => static fn (): InMemoryStore => new InMemoryStore('symfony'), |
| 32 | + 'session' => static function (): SessionStore { |
| 33 | + $request = Request::create('/'); |
| 34 | + $request->setSession(new Session(new MockArraySessionStorage())); |
| 35 | + |
| 36 | + $requestStack = new RequestStack(); |
| 37 | + $requestStack->push($request); |
| 38 | + |
| 39 | + return new SessionStore($requestStack, 'symfony'); |
| 40 | + } |
| 41 | +]; |
| 42 | + |
| 43 | +$storesIds = array_keys($factories); |
| 44 | + |
| 45 | +$application = new Application(); |
| 46 | +$application->setAutoExit(false); |
| 47 | +$application->setCatchExceptions(false); |
| 48 | +$application->addCommands([ |
| 49 | + new SetupStoreCommand(new ServiceLocator($factories)), |
| 50 | + new DropStoreCommand(new ServiceLocator($factories)), |
| 51 | +]); |
| 52 | + |
| 53 | +foreach ($storesIds as $store) { |
| 54 | + $setupOutputCode = $application->run(new ArrayInput([ |
| 55 | + 'command' => 'ai:message-store:setup', |
| 56 | + 'store' => $store, |
| 57 | + ]), new ConsoleOutput()); |
| 58 | + |
| 59 | + $dropOutputCode = $application->run(new ArrayInput([ |
| 60 | + 'command' => 'ai:message-store:drop', |
| 61 | + 'store' => $store, |
| 62 | + '--force' => true, |
| 63 | + ]), new ConsoleOutput()); |
| 64 | +} |
0 commit comments