-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from jolicode/feat/yaml
Add a yaml parse function
- Loading branch information
Showing
13 changed files
with
189 additions
and
3 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
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,18 @@ | ||
# YAML | ||
|
||
Castor provides a `yaml_parse()` and `yaml_dump()` functions that will parse or | ||
dump YAML content and returns an array using the [symfony/yaml](https://symfony.com/doc/current/components/yaml.html) component: | ||
|
||
```php | ||
use Castor\Attribute\AsTask; | ||
|
||
use function Castor\{yaml_parse, yaml_dump}; | ||
|
||
#[AsTask()] | ||
function yaml_parse_and_dump(): void | ||
{ | ||
$content = yaml_parse(file_get_contents('file.yaml')); | ||
|
||
file_put_contents('file.yaml', yaml_dump($content)); | ||
} | ||
``` |
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,24 @@ | ||
<?php | ||
|
||
namespace yaml; | ||
|
||
use Castor\Attribute\AsTask; | ||
|
||
use function Castor\yaml_dump; | ||
use function Castor\yaml_parse; | ||
|
||
#[AsTask(description: 'Parse a YAML content')] | ||
function parse(): void | ||
{ | ||
$data = yaml_parse(<<<'YAML' | ||
foo: bar | ||
YAML); | ||
echo $data['foo'] . "\n"; | ||
} | ||
|
||
#[AsTask(description: 'Dump a YAML content')] | ||
function dump(): void | ||
{ | ||
$data = ['foo' => 'bar']; | ||
echo yaml_dump($data) . "\n"; | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
Number of PHP files: 27 | ||
Number of PHP files: 28 |
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,22 @@ | ||
<?php | ||
|
||
namespace Castor\Tests\Examples\Generated; | ||
|
||
use Castor\Tests\TaskTestCase; | ||
|
||
class YamlDumpTest extends TaskTestCase | ||
{ | ||
// yaml:dump | ||
public function test(): void | ||
{ | ||
$process = $this->runTask(['yaml:dump']); | ||
|
||
$this->assertSame(0, $process->getExitCode()); | ||
$this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); | ||
if (file_exists(__FILE__ . '.err.txt')) { | ||
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); | ||
} else { | ||
$this->assertSame('', $process->getErrorOutput()); | ||
} | ||
} | ||
} |
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,2 @@ | ||
foo: bar | ||
|
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,22 @@ | ||
<?php | ||
|
||
namespace Castor\Tests\Examples\Generated; | ||
|
||
use Castor\Tests\TaskTestCase; | ||
|
||
class YamlParseTest extends TaskTestCase | ||
{ | ||
// yaml:parse | ||
public function test(): void | ||
{ | ||
$process = $this->runTask(['yaml:parse']); | ||
|
||
$this->assertSame(0, $process->getExitCode()); | ||
$this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); | ||
if (file_exists(__FILE__ . '.err.txt')) { | ||
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); | ||
} else { | ||
$this->assertSame('', $process->getErrorOutput()); | ||
} | ||
} | ||
} |
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 @@ | ||
bar |