PHP code example of decodelabs / nuance

1. Go to this page and download the library: Download decodelabs/nuance library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

decodelabs / nuance example snippets


use DecodeLabs\Nuance\Renderer\Html as HtmlRenderer;

$renderer = new HtmlRenderer();
$value = ['foo' => 'bar', 'baz' => ['qux' => 'quux']];
$output = $renderer->render($value);

use DecodeLabs\Nuance\Dumpable;
use DecodeLabs\Nuance\Entity\NativeObject;

class MyCustomObject implements Dumpable
{
    public function toNuanceEntity(): NativeObject
    {
        $output = new NativeObject($this);

        // Custom display name - rendered as a class name
        $output->displayName = 'Custom\\Object';

        // Item name - an extension of the display name, useful for sub-types or options
        $output->itemName = 'option-1';

        // Sensitive - marks the entire object as sensitive, which will prevent
        // data within it from being displayed
        $output->sensitive = true;

        // Numerical size of the object, if applicable
        $output->length = 42;

        // Definition string
        $output->definition = '<xml>MyCustomObject</xml>';

        // Text string
        $output->text = 'My custom object text representation';

        // Intrinsic values of the object - useful for collection-like objects
        $output->values = [
            'key1' => 'value1',
            'key2' => 'value2',
        ];

        // Don't show keys from values list
        $output->valueKeys = false;

        // Shortcut to setting a single value in value list without keys
        $output->value = 'single value';

        // Properties - bona fide members of the object, manually collected
        $output->setProperty(
            name: 'property1',
            value: 'value1',
            visibility: 'protected',
            virtual: false,
            readOnly: true
        );

        // Metadata - additional information about the object
        $output->meta = [
            'created_at' => '2023-10-01',
            'updated_at' => '2023-10-02',
        ];

        // Programatically disable dump sections
        $output->sections->disable('info');

        return $output;
    }
}