Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Oct 3, 2023
1 parent 63a8596 commit f4fe5d7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
10 changes: 0 additions & 10 deletions src/Drivers/Driver.php

This file was deleted.

27 changes: 27 additions & 0 deletions src/Drivers/Json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Orbit\Drivers;

use Orbit\Contracts\Driver;

class Json implements Driver
{
public function parse(string $fileContents): array
{
return json_decode($fileContents, associative: true);
}

public function compile(array $attributes): string
{
// There's no way to represent `null` in JSON, so we filter them out and
// then they will get added back in when necessary.
$attributes = array_filter($attributes, fn ($value) => $value !== null);

return json_encode($attributes, JSON_PRETTY_PRINT);
}

public function extension(): string
{
return 'json';
}
}
3 changes: 2 additions & 1 deletion src/Drivers/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Orbit\Drivers;

use Orbit\Contracts\Driver;
use Spatie\YamlFrontMatter\YamlFrontMatter;
use Symfony\Component\Yaml\Yaml;

class Markdown extends Driver
class Markdown implements Driver
{
public function parse(string $fileContents): array
{
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/Drivers/JsonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Orbit\Drivers\Json;

it('can parse a json file into an array of attributes', function () {
$json = <<<'JSON'
{
"name": "Ryan",
"email": "[email protected]"
}
JSON;

$driver = new Json();

expect($driver->parse($json))
->toBe([
'name' => 'Ryan',
'email' => '[email protected]'
]);
});

0 comments on commit f4fe5d7

Please sign in to comment.