Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1294 lars 1
<?php
2
 
3
namespace Spatie\Ignition\Solutions\OpenAi;
4
 
5
use Psr\SimpleCache\CacheInterface;
6
use Spatie\Ignition\Contracts\HasSolutionsForThrowable;
7
use Throwable;
8
 
9
class OpenAiSolutionProvider implements HasSolutionsForThrowable
10
{
11
    public function __construct(
12
        protected string $openAiKey,
13
        protected ?CacheInterface $cache = null,
14
        protected int $cacheTtlInSeconds = 60 * 60,
15
        protected string|null $applicationType = null,
16
        protected string|null $applicationPath = null,
17
    ) {
18
        $this->cache ??= new DummyCache();
19
    }
20
 
21
    public function applicationType(string $applicationType): self
22
    {
23
        $this->applicationType = $applicationType;
24
 
25
        return $this;
26
    }
27
 
28
    public function applicationPath(string $applicationPath): self
29
    {
30
        $this->applicationPath = $applicationPath;
31
 
32
        return $this;
33
    }
34
 
35
    public function useCache(CacheInterface $cache, int $cacheTtlInSeconds = 60 * 60): self
36
    {
37
        $this->cache = $cache;
38
 
39
        $this->cacheTtlInSeconds = $cacheTtlInSeconds;
40
 
41
        return $this;
42
    }
43
 
44
    public function canSolve(Throwable $throwable): bool
45
    {
46
        return true;
47
    }
48
 
49
    public function getSolutions(Throwable $throwable): array
50
    {
51
        return [
52
            new OpenAiSolution(
53
                $throwable,
54
                $this->openAiKey,
55
                $this->cache,
56
                $this->cacheTtlInSeconds,
57
                $this->applicationType,
58
                $this->applicationPath,
59
            ),
60
        ];
61
    }
62
}