Skip to content

Commit 7f9b3b8

Browse files
committed
fix: failing website exmaples
1 parent 23a267c commit 7f9b3b8

26 files changed

Lines changed: 101 additions & 75 deletions

File tree

src/lib/types/src/Flow/Types/Type/Logical/HTMLType.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ public function assert(mixed $value) : HTMLDocument
3434

3535
public function cast(mixed $value) : HTMLDocument
3636
{
37-
if (!$this->isValid($value)) {
38-
throw new CastingException($value, $this);
37+
if ($this->isValid($value)) {
38+
return $value;
3939
}
4040

41-
/* @phpstan-ignore-next-line */
42-
if (\is_string($value)) {
41+
if (\is_string($value) && \class_exists('\Dom\HTMLDocument') && \preg_match(self::HTML_ALIKE_REGEX, $value) === 1) {
4342
return HTMLDocument::createFromString($value, \LIBXML_NOERROR);
4443
}
4544

46-
return $value;
45+
throw new CastingException($value, $this);
4746
}
4847

4948
public function isValid(mixed $value) : bool

src/lib/types/tests/Flow/Types/Tests/Unit/Type/Logical/HTMLTypeTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ public static function cast_data_provider() : \Generator
8080
];
8181

8282
yield 'valid HTML string' => [
83-
'value' => '<!DOCTYPE html><html lang="en"><head></head><body><div><span>1</span></div></body></html>',
84-
'expected' => null,
85-
'exceptionClass' => CastingException::class,
83+
'value' => $validHtml = '<!DOCTYPE html><html lang="en"><head></head><body><div><span>1</span></div></body></html>',
84+
'expected' => $validHtml,
85+
'exceptionClass' => null,
8686
];
8787

8888
yield 'valid HTML with spaces' => [
89-
'value' => '<!DOCTYPE html><html> <head><title></title></head> <body><p>invalid</p> </body> </html>',
90-
'expected' => null,
91-
'exceptionClass' => CastingException::class,
89+
'value' => $htmlWithSpaces = '<!DOCTYPE html><html> <head><title></title></head> <body><p>invalid</p> </body> </html>',
90+
'expected' => $htmlWithSpaces,
91+
'exceptionClass' => null,
9292
];
9393

9494
yield 'valid HTML with new lines' => [
95-
'value' => <<<'HTML'
95+
'value' => $htmlWithNewLines = <<<'HTML'
9696
<!DOCTYPE html>
9797
<html>
9898
<head><title></title></head>
@@ -101,8 +101,8 @@ public static function cast_data_provider() : \Generator
101101
</body>
102102
</html>
103103
HTML,
104-
'expected' => null,
105-
'exceptionClass' => CastingException::class,
104+
'expected' => $htmlWithNewLines,
105+
'exceptionClass' => null,
106106
];
107107

108108
yield 'missing doctype' => [
8.09 KB
Binary file not shown.

web/landing/content/examples/topics/data_frame/data_reading/elasticsearch/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$fs = fstab()->for('file');
1414

1515
if ($fs->status(path(__DIR__ . '/.env')) === null) {
16-
print 'Example skipped. Please create .env file with Azure Storage Account credentials.' . PHP_EOL;
16+
print 'Example skipped. Please create .env file with ELASTICSEARCH_URL.' . PHP_EOL;
1717

1818
return;
1919
}
Binary file not shown.

web/landing/content/examples/topics/data_frame/data_writing/database/code.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
declare(strict_types=1);
44

55
use function Flow\ETL\Adapter\Doctrine\to_dbal_table_insert;
6-
use function Flow\ETL\DSL\{data_frame, from_array, overwrite};
6+
use function Flow\ETL\DSL\{data_frame, from_csv, overwrite};
77
use Doctrine\DBAL\DriverManager;
88
use Doctrine\DBAL\Schema\{Column, Table};
99
use Doctrine\DBAL\Types\{Type, Types};
1010

1111
require __DIR__ . '/vendor/autoload.php';
1212

13-
require __DIR__ . '/generate_orders.php';
13+
if (!\extension_loaded('pdo_sqlite')) {
14+
print 'Example skipped. Requires PDO SQLite extension which is not available in this environment.' . PHP_EOL;
15+
16+
return;
17+
}
1418

1519
$connection = DriverManager::getConnection([
1620
'path' => __DIR__ . '/output/orders.db',
@@ -39,7 +43,9 @@
3943
));
4044

4145
data_frame()
42-
->read(from_array(generateOrders(10)))
46+
->read(from_csv(__DIR__ . '/data/orders.csv'))
47+
->select('order_id', 'created_at', 'updated_at', 'discount', 'email', 'customer', 'address', 'notes', 'items')
48+
->limit(10)
4349
->saveMode(overwrite())
4450
->write(
4551
to_dbal_table_insert(

web/landing/content/examples/topics/data_frame/data_writing/database_delete/code.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
sqlite_insert_options,
77
to_dbal_table_delete,
88
to_dbal_table_insert};
9-
use function Flow\ETL\DSL\{data_frame, from_array};
9+
use function Flow\ETL\DSL\{data_frame, from_array, from_csv};
1010
use Doctrine\DBAL\DriverManager;
1111
use Doctrine\DBAL\Schema\{Column, Table, UniqueConstraint};
1212
use Doctrine\DBAL\Types\{Type, Types};
1313

1414
require __DIR__ . '/vendor/autoload.php';
1515

16-
require __DIR__ . '/generate_static_orders.php';
16+
if (!\extension_loaded('pdo_sqlite')) {
17+
print 'Example skipped. Requires PDO SQLite extension which is not available in this environment.' . PHP_EOL;
18+
19+
return;
20+
}
1721

1822
$connection = DriverManager::getConnection([
1923
'path' => __DIR__ . '/output/orders.db',
@@ -42,21 +46,10 @@
4246
));
4347
}
4448

45-
$orderIds = [
46-
'c0a43894-0102-4a4e-9fcd-393ef9e4f16a',
47-
'83fd51a4-9bd1-4b40-8f6e-6a7cc940bb5a',
48-
'7c65db1a-410f-4e91-8aeb-66fb3f1665f7',
49-
'5af1d56c-a9f7-411e-8738-865942d6c40f',
50-
'3a3ae1a9-debd-425a-8f9d-63c3315bc483',
51-
'27d8ee4d-94cc-47fa-bc14-209a4ab2eb45',
52-
'cc4fd722-1407-4781-9ad4-fa53966060af',
53-
'718360e1-c4c9-40f4-84e2-6f7898788883',
54-
'ea7c731c-ce3b-40bb-bbf8-79f1c717b6ca',
55-
'17b0d6c5-dd8f-4d5a-ae06-1df15b67c82c',
56-
];
57-
5849
data_frame()
59-
->read(from_array(generateStaticOrders($orderIds)))
50+
->read(from_csv(__DIR__ . '/data/orders.csv'))
51+
->select('order_id', 'created_at', 'updated_at', 'discount', 'email', 'customer', 'address', 'notes', 'items')
52+
->limit(10)
6053
->write(
6154
to_dbal_table_insert(
6255
DriverManager::getConnection(['path' => __DIR__ . '/output/orders.db', 'driver' => 'pdo_sqlite']),
@@ -66,6 +59,11 @@
6659
)
6760
->run();
6861

62+
$orderIds = \array_column(
63+
$connection->fetchAllAssociative('SELECT order_id FROM orders'),
64+
'order_id'
65+
);
66+
6967
data_frame()
7068
->read(from_array(\array_map(static fn (string $id) => ['order_id' => $id], $orderIds)))
7169
->write(
@@ -76,6 +74,6 @@
7674
)
7775
->run();
7876

79-
$orders = $connection->fetchAllAssociative($connection->createQueryBuilder()->select('*')->from('orders')->orderBy('order_id')->getSQL());
77+
$orders = $connection->fetchAllAssociative('SELECT * FROM orders ORDER BY order_id');
8078

8179
assert(\count($orders) === 0, 'There should be no orders left in the database after deletion.');

web/landing/content/examples/topics/data_frame/data_writing/database_upsert/code.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
use function Flow\ETL\Adapter\Doctrine\{from_dbal_query,
66
sqlite_insert_options,
77
to_dbal_table_insert};
8-
use function Flow\ETL\DSL\{data_frame, from_array, to_output};
8+
use function Flow\ETL\DSL\{data_frame, from_csv, to_output};
99
use Doctrine\DBAL\DriverManager;
1010
use Doctrine\DBAL\Schema\{Column, Table, UniqueConstraint};
1111
use Doctrine\DBAL\Types\{Type, Types};
1212

1313
require __DIR__ . '/vendor/autoload.php';
1414

15-
require __DIR__ . '/generate_static_orders.php';
15+
if (!\extension_loaded('pdo_sqlite')) {
16+
print 'Example skipped. Requires PDO SQLite extension which is not available in this environment.' . PHP_EOL;
17+
18+
return;
19+
}
1620

1721
$connection = DriverManager::getConnection([
1822
'path' => __DIR__ . '/output/orders.db',
@@ -41,21 +45,10 @@
4145
));
4246
}
4347

44-
$orderIds = [
45-
'c0a43894-0102-4a4e-9fcd-393ef9e4f16a',
46-
'83fd51a4-9bd1-4b40-8f6e-6a7cc940bb5a',
47-
'7c65db1a-410f-4e91-8aeb-66fb3f1665f7',
48-
'5af1d56c-a9f7-411e-8738-865942d6c40f',
49-
'3a3ae1a9-debd-425a-8f9d-63c3315bc483',
50-
'27d8ee4d-94cc-47fa-bc14-209a4ab2eb45',
51-
'cc4fd722-1407-4781-9ad4-fa53966060af',
52-
'718360e1-c4c9-40f4-84e2-6f7898788883',
53-
'ea7c731c-ce3b-40bb-bbf8-79f1c717b6ca',
54-
'17b0d6c5-dd8f-4d5a-ae06-1df15b67c82c',
55-
];
56-
5748
data_frame()
58-
->read(from_array(generateStaticOrders($orderIds)))
49+
->read(from_csv(__DIR__ . '/data/orders.csv'))
50+
->select('order_id', 'created_at', 'updated_at', 'discount', 'email', 'customer', 'address', 'notes', 'items')
51+
->limit(10)
5952
->write(
6053
to_dbal_table_insert(
6154
DriverManager::getConnection([

web/landing/content/examples/topics/data_frame/data_writing/elasticsearch/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$fs = fstab()->for('file');
1414

1515
if ($fs->status(path(__DIR__ . '/.env')) === null) {
16-
print 'Example skipped. Please create .env file with Azure Storage Account credentials.' . PHP_EOL;
16+
print 'Example skipped. Please create .env file with ELASTICSEARCH_URL.' . PHP_EOL;
1717

1818
return;
1919
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
priority: 4
2+
hidden: false

0 commit comments

Comments
 (0)