-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
868 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Writer\Builder; | ||
|
||
use Closure; | ||
use Generator; | ||
use XMLWriter; | ||
|
||
/** | ||
* @param list<(callable(XMLWriter): Generator<bool>)> $configurators | ||
* | ||
* @return Closure(XMLWriter): Generator<bool> | ||
*/ | ||
function cdata(callable ...$configurators): Closure | ||
{ | ||
return | ||
/** | ||
* @return Generator<bool> | ||
*/ | ||
static function (XMLWriter $writer) use ($configurators): Generator { | ||
yield $writer->startCdata(); | ||
foreach ($configurators as $configurator) { | ||
yield from $configurator($writer); | ||
} | ||
|
||
yield $writer->endCdata(); | ||
}; | ||
} |
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 VeeWee\Xml\Writer\Builder; | ||
|
||
use Closure; | ||
use Generator; | ||
use XMLWriter; | ||
|
||
/** | ||
* @param list<(callable(XMLWriter): Generator<bool>)> $configurators | ||
* | ||
* @return Closure(XMLWriter): Generator<bool> | ||
*/ | ||
function comment(callable ...$configurators): Closure | ||
{ | ||
return | ||
/** | ||
* @return Generator<bool> | ||
*/ | ||
static function (XMLWriter $writer) use ($configurators): Generator { | ||
yield $writer->startComment(); | ||
foreach ($configurators as $configurator) { | ||
yield from $configurator($writer); | ||
} | ||
|
||
yield $writer->endComment(); | ||
}; | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Writer\Builder; | ||
|
||
use Closure; | ||
use Generator; | ||
use XMLWriter; | ||
|
||
/** | ||
* @return Closure(XMLWriter): Generator<bool> | ||
*/ | ||
function namespaced_attribute(string $namespace, ?string $prefix, string $name, string $value): Closure | ||
{ | ||
return | ||
/** | ||
* @return Generator<bool> | ||
*/ | ||
static function (XMLWriter $writer) use ($namespace, $prefix, $name, $value): Generator { | ||
yield $writer->startAttributeNs($prefix, $name, $namespace); | ||
yield $writer->text($value); | ||
yield $writer->endAttribute(); | ||
}; | ||
} |
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 VeeWee\Xml\Writer\Builder; | ||
|
||
use Closure; | ||
use Generator; | ||
use XMLWriter; | ||
|
||
/** | ||
* @param array<string, string> $attributes | ||
* @return Closure(XMLWriter): Generator<bool> | ||
*/ | ||
function namespaced_attributes(string $namespace, array $attributes): Closure | ||
{ | ||
return | ||
/** | ||
* @return Generator<bool> | ||
*/ | ||
static function (XMLWriter $writer) use ($namespace, $attributes): Generator { | ||
foreach ($attributes as $key => $value) { | ||
$parts = explode(':', $key, 2); | ||
$name = array_pop($parts); | ||
$prefix = $parts ? $parts[0] : null; | ||
|
||
yield from namespaced_attribute($namespace, $prefix, $name, $value)($writer); | ||
} | ||
}; | ||
} |
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 VeeWee\Xml\Writer\Builder; | ||
|
||
use Closure; | ||
use Generator; | ||
use XMLWriter; | ||
|
||
/** | ||
* @param list<(callable(XMLWriter): Generator<bool>)> $configurators | ||
* | ||
* @return Closure(XMLWriter): Generator<bool> | ||
*/ | ||
function namespaced_element(string $namespace, ?string $prefix, string $name, callable ...$configurators): Closure | ||
{ | ||
return | ||
/** | ||
* @return Generator<bool> | ||
*/ | ||
static function (XMLWriter $writer) use ($namespace, $prefix, $name, $configurators): Generator { | ||
yield $writer->startElementNs($prefix, $name, $namespace); | ||
foreach ($configurators as $configurator) { | ||
yield from $configurator($writer); | ||
} | ||
|
||
yield $writer->endElement(); | ||
}; | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Writer\Builder; | ||
|
||
use Closure; | ||
use Generator; | ||
use XMLWriter; | ||
|
||
/** | ||
* @return Closure(XMLWriter): Generator<bool> | ||
*/ | ||
function raw(string $value): Closure | ||
{ | ||
return | ||
/** | ||
* @return Generator<bool> | ||
*/ | ||
static function (XMLWriter $writer) use ($value): Generator { | ||
yield $writer->writeRaw($value); | ||
}; | ||
} |
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 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Writer\Mapper; | ||
|
||
use Closure; | ||
use XMLWriter; | ||
|
||
/** | ||
* @return Closure(XMLWriter): string XMLWriter | ||
*/ | ||
function memory_output(): Closure | ||
{ | ||
return static function (XMLWriter $writer): string { | ||
return $writer->outputMemory(); | ||
}; | ||
} |
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 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Writer\Opener; | ||
|
||
use Closure; | ||
use XMLWriter; | ||
|
||
/** | ||
* @return Closure(XMLWriter): bool XMLWriter | ||
*/ | ||
function memory_opener(): Closure | ||
{ | ||
return static function (XMLWriter $writer): bool { | ||
return $writer->openMemory(); | ||
}; | ||
} |
Oops, something went wrong.