File size: 7,766 Bytes
097eaf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php

declare(strict_types=1);

namespace Firecrawl\Models;

final class ScrapeOptions
{
    /**
     * @param list<string|JsonFormat|ScreenshotFormat|QuestionFormat|HighlightsFormat|QueryFormat>|null $formats Supports strings like "markdown", "audio", and "video".
     * @param array<string, string>|null   $headers
     * @param list<string>|null            $includeTags
     * @param list<string>|null            $excludeTags
     * @param list<mixed>|null             $parsers
     * @param list<array<string, mixed>>|null $actions
     */
    private function __construct(
        private readonly ?array $formats = null,
        private readonly ?array $headers = null,
        private readonly ?array $includeTags = null,
        private readonly ?array $excludeTags = null,
        private readonly ?bool $onlyMainContent = null,
        private readonly ?int $timeout = null,
        private readonly ?int $waitFor = null,
        private readonly ?bool $mobile = null,
        private readonly ?array $parsers = null,
        private readonly ?array $actions = null,
        private readonly ?LocationConfig $location = null,
        private readonly ?bool $skipTlsVerification = null,
        private readonly ?bool $removeBase64Images = null,
        private readonly ?bool $blockAds = null,
        private readonly ?string $proxy = null,
        private readonly ?int $maxAge = null,
        private readonly ?int $minAge = null,
        private readonly ?bool $storeInCache = null,
        private readonly ?bool $lockdown = null,
        private readonly ?string $integration = null,
        /** @var array<string, string>|null */
        private readonly ?array $profile = null,
        private readonly ?bool $changeTracking = null,
    ) {}

    /**
     * @param list<string|JsonFormat|ScreenshotFormat|QuestionFormat|HighlightsFormat|QueryFormat>|null $formats Supports strings like "markdown", "audio", and "video".
     * @param array<string, string>|null                    $headers
     * @param list<string>|null                             $includeTags
     * @param list<string>|null                             $excludeTags
     * @param list<mixed>|null                              $parsers
     * @param list<array<string, mixed>>|null               $actions
     * @param array<string, string>|null                    $profile
     */
    public static function with(
        ?array $formats = null,
        ?array $headers = null,
        ?array $includeTags = null,
        ?array $excludeTags = null,
        ?bool $onlyMainContent = null,
        ?int $timeout = null,
        ?int $waitFor = null,
        ?bool $mobile = null,
        ?array $parsers = null,
        ?array $actions = null,
        ?LocationConfig $location = null,
        ?bool $skipTlsVerification = null,
        ?bool $removeBase64Images = null,
        ?bool $blockAds = null,
        ?string $proxy = null,
        ?int $maxAge = null,
        ?bool $storeInCache = null,
        ?string $integration = null,
        ?bool $lockdown = null,
        ?int $minAge = null,
        ?array $profile = null,
        ?bool $changeTracking = null,
    ): self {
        return new self(
            $formats, $headers, $includeTags, $excludeTags, $onlyMainContent,
            $timeout, $waitFor, $mobile, $parsers, $actions, $location,
            $skipTlsVerification, $removeBase64Images, $blockAds, $proxy,
            $maxAge, $minAge, $storeInCache, $lockdown, $integration, $profile,
            $changeTracking,
        );
    }

    /** @return array<string, mixed> */
    public function toArray(): array
    {
        $data = [];

        if ($this->formats !== null) {
            $data['formats'] = array_map(
                fn (string|JsonFormat|ScreenshotFormat|QuestionFormat|HighlightsFormat|QueryFormat $f): string|array =>
                    (
                        $f instanceof JsonFormat
                        || $f instanceof ScreenshotFormat
                        || $f instanceof QuestionFormat
                        || $f instanceof HighlightsFormat
                        || $f instanceof QueryFormat
                    ) ? $f->toArray() : $f,
                $this->formats,
            );
        }

        $fields = [
            'headers' => $this->headers,
            'includeTags' => $this->includeTags,
            'excludeTags' => $this->excludeTags,
            'onlyMainContent' => $this->onlyMainContent,
            'timeout' => $this->timeout,
            'waitFor' => $this->waitFor,
            'mobile' => $this->mobile,
            'parsers' => $this->parsers,
            'actions' => $this->actions,
            'location' => $this->location?->toArray(),
            'skipTlsVerification' => $this->skipTlsVerification,
            'removeBase64Images' => $this->removeBase64Images,
            'blockAds' => $this->blockAds,
            'proxy' => $this->proxy,
            'maxAge' => $this->maxAge,
            'minAge' => $this->minAge,
            'storeInCache' => $this->storeInCache,
            'lockdown' => $this->lockdown,
            'integration' => $this->integration,
            'profile' => $this->profile,
            'changeTracking' => $this->changeTracking,
        ];

        foreach ($fields as $key => $value) {
            if ($value !== null) {
                $data[$key] = $value;
            }
        }

        return $data;
    }

    /** @return list<string|JsonFormat|ScreenshotFormat|QuestionFormat|HighlightsFormat|QueryFormat>|null */
    public function getFormats(): ?array
    {
        return $this->formats;
    }

    /** @return array<string, string>|null */
    public function getHeaders(): ?array
    {
        return $this->headers;
    }

    /** @return list<string>|null */
    public function getIncludeTags(): ?array
    {
        return $this->includeTags;
    }

    /** @return list<string>|null */
    public function getExcludeTags(): ?array
    {
        return $this->excludeTags;
    }

    public function getOnlyMainContent(): ?bool
    {
        return $this->onlyMainContent;
    }

    public function getTimeout(): ?int
    {
        return $this->timeout;
    }

    public function getWaitFor(): ?int
    {
        return $this->waitFor;
    }

    public function getMobile(): ?bool
    {
        return $this->mobile;
    }

    /** @return list<mixed>|null */
    public function getParsers(): ?array
    {
        return $this->parsers;
    }

    /** @return list<array<string, mixed>>|null */
    public function getActions(): ?array
    {
        return $this->actions;
    }

    public function getLocation(): ?LocationConfig
    {
        return $this->location;
    }

    public function getSkipTlsVerification(): ?bool
    {
        return $this->skipTlsVerification;
    }

    public function getRemoveBase64Images(): ?bool
    {
        return $this->removeBase64Images;
    }

    public function getBlockAds(): ?bool
    {
        return $this->blockAds;
    }

    public function getProxy(): ?string
    {
        return $this->proxy;
    }

    public function getMaxAge(): ?int
    {
        return $this->maxAge;
    }

    public function getStoreInCache(): ?bool
    {
        return $this->storeInCache;
    }

    public function getLockdown(): ?bool
    {
        return $this->lockdown;
    }

    public function getIntegration(): ?string
    {
        return $this->integration;
    }

    public function getMinAge(): ?int
    {
        return $this->minAge;
    }

    /** @return array<string, string>|null */
    public function getProfile(): ?array
    {
        return $this->profile;
    }

    public function getChangeTracking(): ?bool
    {
        return $this->changeTracking;
    }
}