Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum in XML example. #84

Merged
merged 3 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion plugins/Sandbox/templates/CakeExamples/enums.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

use Cake\Core\Plugin;
use Cake\Utility\Xml;

?>

Expand Down Expand Up @@ -65,7 +66,7 @@ public function initialize(array \$config): void {

<p>
Unfortunately, enums cannot implement Stringable.
So here we need to always manually do the respective string output.
So here we need to always manually call the respective string output.
</p>

<h4><?php echo h('$user->status->label()');?></h4>
Expand Down Expand Up @@ -118,6 +119,20 @@ public function initialize(array \$config): void {
Here you can see that it is now a backed enum object again.
</p>

<h4>XML</h4>
<p>Since CakePHP 5.1.2</p>

<?php
$code = '$result = Xml::fromArray([\'user\' => $user], [\'pretty\' => true])->saveXML();';
echo $this->Highlighter->highlight($code, ['lang' => 'php']);
?>

<?php
$result = Xml::fromArray(['user' => $user], ['pretty' => true])->saveXML();
echo $this->Highlighter->highlight($result, ['lang' => 'xml']);
?>


<h4>More examples</h4>
<ul>
<li><?php echo $this->Html->link('Validation', ['action' => 'enumValidation']);?></li>
Expand Down
Loading