ntlab/php-obj

A PHP object representation as string, javascript, annotation, or YAML

v1.8.1 2024-09-28 08:06 UTC

This package is auto-updated.

Last update: 2024-12-06 01:26:49 UTC


README

Build Status Latest Stable Version Total Downloads License

Represent PHP object as string, javascript, annotation, or YAML.

Examples

  • Represent PHP object as string

    <?php
    
    use NTLAB\Object\PHP;
    
    $a = new PHP([1, 2, 3], ['inline' => true]);
    echo (string) $a; // [1, 2, 3]
    
    $a = new PHP(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...'], ['inline' => true]);
    echo (string) $a; // ['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...']
  • Represent PHP object as annotation

    <?php
    
    use NTLAB\Object\Annotation;
    
    $a = new Annotation(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...'], ['annotation' => '@Fruit', 'inline' => true]);
    echo (string) $a; // @Fruit(name="Apple", color="Red", description="It's yummy...")
  • Represent PHP object as javascript

    <?php
    
    use NTLAB\Object\JS;
    
    $a = new JS(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...'], ['inline' => true]);
    echo (string) $a; // {name: 'Apple', color: 'Red', description: 'It\'s yummy...'}
    • Represent PHP object as YAML
    <?php
    
    use NTLAB\Object\YAML;
    
    $a = new YAML(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...']);
    echo (string) $a;
    // name:
    //     Apple
    // color:
    //     Red
    // description:
    //     It's yummy...