-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New blog post - scalar functions (#1174)
- Loading branch information
1 parent
c80bad9
commit 3faf80c
Showing
17 changed files
with
484 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/core/etl/tests/Flow/ETL/Tests/Unit/Function/PowerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Unit\Function; | ||
|
||
use function Flow\ETL\DSL\{int_entry, lit, ref, str_entry}; | ||
use Flow\ETL\Row; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class PowerTest extends TestCase | ||
{ | ||
public function test_power_non_numeric_values() : void | ||
{ | ||
self::assertNull( | ||
ref('int')->power(lit('non numeric'))->eval(Row::create(int_entry('int', 10))) | ||
); | ||
self::assertNull( | ||
ref('str')->power(lit(2))->eval(Row::create(str_entry('str', 'abc'))) | ||
); | ||
} | ||
|
||
public function test_power_two_numeric_values() : void | ||
{ | ||
self::assertSame( | ||
100, | ||
ref('int')->power(lit(2))->eval(Row::create(int_entry('int', 10))) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\Website\Blog; | ||
|
||
final class Post | ||
{ | ||
public function __construct( | ||
public readonly string $title, | ||
public readonly string $description, | ||
public readonly \DateTimeImmutable $date, | ||
public readonly string $slug | ||
) { | ||
} | ||
|
||
public static function fromArray(array $data) : self | ||
{ | ||
return new self( | ||
$data['title'], | ||
$data['description'], | ||
new \DateTimeImmutable($data['date']), | ||
$data['slug'] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\Website\Blog; | ||
|
||
final class Posts | ||
{ | ||
private array $posts = [ | ||
[ | ||
'title' => 'Building Custom Data Extractor - Flow PHP', | ||
'description' => 'Learn how to extract data from Google Analytics API using Flow PHP but also how to build a custom data extractor.', | ||
'date' => '2024-04-04', | ||
'slug' => 'building-custom-extractor-google-analytics', | ||
], | ||
[ | ||
'title' => 'Scalar Functions', | ||
'description' => 'Scalar functions are one of the most important building blocks of Flow. Learn how to build and use custom scalar functions in Flow PHP.', | ||
'date' => '2024-08-08', | ||
'slug' => 'scalar-functions', | ||
|
||
], | ||
]; | ||
|
||
/** | ||
* @return array<Post> | ||
*/ | ||
public function all() : array | ||
{ | ||
return \array_map( | ||
static fn (array $data) : Post => Post::fromArray($data), | ||
\array_reverse($this->posts) | ||
); | ||
} | ||
|
||
public function findByDateAndSlug(string $date, string $slug) : Post | ||
{ | ||
foreach ($this->posts as $post) { | ||
if ($post['date'] === $date && $post['slug'] === $slug) { | ||
return Post::fromArray($post); | ||
} | ||
} | ||
|
||
throw new \InvalidArgumentException('Post not found'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{%- block title -%} | ||
Article - {{ post.title }} | ||
{%- endblock -%} | ||
|
||
{%- block description -%} | ||
{{ post.description }} | ||
{%- endblock -%} | ||
|
||
{% block main %} | ||
{{ block('article') }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.