Skip to content

Commit f19a57a

Browse files
feat(php): differentiate null and omit
1 parent 585d282 commit f19a57a

16 files changed

+136
-122
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"$schema": "https://getcomposer.org/schema.json",
33
"autoload": {
44
"files": [
5+
"src/Core/Omit.php",
56
"src/Client.php"
67
],
78
"psr-4": {

src/Contracts/CrawlContract.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Scrapegraphai\Responses\Crawl\CrawlGetResultsResponse;
1010
use Scrapegraphai\Responses\Crawl\CrawlStartResponse;
1111

12+
use const Scrapegraphai\Core\OMIT as omit;
13+
1214
interface CrawlContract
1315
{
1416
public function retrieveResults(
@@ -29,14 +31,14 @@ public function retrieveResults(
2931
*/
3032
public function start(
3133
$url,
32-
$depth = null,
33-
$extractionMode = null,
34-
$maxPages = null,
35-
$prompt = null,
36-
$renderHeavyJs = null,
37-
$rules = null,
38-
$schema = null,
39-
$sitemap = null,
34+
$depth = omit,
35+
$extractionMode = omit,
36+
$maxPages = omit,
37+
$prompt = omit,
38+
$renderHeavyJs = omit,
39+
$rules = omit,
40+
$schema = omit,
41+
$sitemap = omit,
4042
?RequestOptions $requestOptions = null,
4143
): CrawlStartResponse;
4244
}

src/Contracts/FeedbackContract.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Scrapegraphai\RequestOptions;
88
use Scrapegraphai\Responses\Feedback\FeedbackSubmitResponse;
99

10+
use const Scrapegraphai\Core\OMIT as omit;
11+
1012
interface FeedbackContract
1113
{
1214
/**
@@ -17,7 +19,7 @@ interface FeedbackContract
1719
public function submit(
1820
$rating,
1921
$requestID,
20-
$feedbackText = null,
22+
$feedbackText = omit,
2123
?RequestOptions $requestOptions = null,
2224
): FeedbackSubmitResponse;
2325
}

src/Contracts/GenerateSchemaContract.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Scrapegraphai\Responses\GenerateSchema\GenerateSchemaGetResponse\FailedSchemaGenerationResponse;
1010
use Scrapegraphai\Responses\GenerateSchema\GenerateSchemaNewResponse;
1111

12+
use const Scrapegraphai\Core\OMIT as omit;
13+
1214
interface GenerateSchemaContract
1315
{
1416
/**
@@ -17,7 +19,7 @@ interface GenerateSchemaContract
1719
*/
1820
public function create(
1921
$userPrompt,
20-
$existingSchema = null,
22+
$existingSchema = omit,
2123
?RequestOptions $requestOptions = null,
2224
): GenerateSchemaNewResponse;
2325

src/Contracts/MarkdownifyContract.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Scrapegraphai\RequestOptions;
99
use Scrapegraphai\Responses\Markdownify\MarkdownifyGetStatusResponse\FailedMarkdownifyResponse;
1010

11+
use const Scrapegraphai\Core\OMIT as omit;
12+
1113
interface MarkdownifyContract
1214
{
1315
/**
@@ -17,8 +19,8 @@ interface MarkdownifyContract
1719
*/
1820
public function convert(
1921
$websiteURL,
20-
$headers = null,
21-
$steps = null,
22+
$headers = omit,
23+
$steps = omit,
2224
?RequestOptions $requestOptions = null,
2325
): CompletedMarkdownify;
2426

src/Contracts/SearchscraperContract.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Scrapegraphai\Responses\Searchscraper\SearchscraperGetStatusResponse\FailedSearchScraperResponse;
99
use Scrapegraphai\Searchscraper\CompletedSearchScraper;
1010

11+
use const Scrapegraphai\Core\OMIT as omit;
12+
1113
interface SearchscraperContract
1214
{
1315
/**
@@ -18,9 +20,9 @@ interface SearchscraperContract
1820
*/
1921
public function create(
2022
$userPrompt,
21-
$headers = null,
22-
$numResults = null,
23-
$outputSchema = null,
23+
$headers = omit,
24+
$numResults = omit,
25+
$outputSchema = omit,
2426
?RequestOptions $requestOptions = null,
2527
): CompletedSearchScraper;
2628

src/Contracts/SmartscraperContract.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Scrapegraphai\Smartscraper\CompletedSmartscraper;
99
use Scrapegraphai\Smartscraper\FailedSmartscraper;
1010

11+
use const Scrapegraphai\Core\OMIT as omit;
12+
1113
interface SmartscraperContract
1214
{
1315
/**
@@ -24,15 +26,15 @@ interface SmartscraperContract
2426
*/
2527
public function create(
2628
$userPrompt,
27-
$cookies = null,
28-
$headers = null,
29-
$numberOfScrolls = null,
30-
$outputSchema = null,
31-
$renderHeavyJs = null,
32-
$steps = null,
33-
$totalPages = null,
34-
$websiteHTML = null,
35-
$websiteURL = null,
29+
$cookies = omit,
30+
$headers = omit,
31+
$numberOfScrolls = omit,
32+
$outputSchema = omit,
33+
$renderHeavyJs = omit,
34+
$steps = omit,
35+
$totalPages = omit,
36+
$websiteHTML = omit,
37+
$websiteURL = omit,
3638
?RequestOptions $requestOptions = null,
3739
): CompletedSmartscraper;
3840

src/Core/Omit.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Scrapegraphai\Core;
6+
7+
const OMIT = Omittable::OMIT;

src/Core/Omittable.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Scrapegraphai\Core;
6+
7+
/**
8+
* @internal
9+
*/
10+
enum Omittable
11+
{
12+
case OMIT;
13+
}

src/Core/Util.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,19 +349,12 @@ public static function decodeContent(MessageInterface $rsp): mixed
349349

350350
/**
351351
* @param array<string, mixed> $arr
352-
* @param list<string> $keys
353352
*
354353
* @return array<string, mixed>
355354
*/
356-
public static function array_filter_null(array $arr, array $keys): array
355+
public static function array_filter_omit(array $arr): array
357356
{
358-
foreach ($keys as $key) {
359-
if (array_key_exists($key, $arr) && is_null($arr[$key])) {
360-
unset($arr[$key]);
361-
}
362-
}
363-
364-
return $arr;
357+
return array_filter($arr, fn ($v, $_) => OMIT !== $v, ARRAY_FILTER_USE_BOTH);
365358
}
366359

367360
/**

0 commit comments

Comments
 (0)