PHP code example of krtv / yii2-jms-serializer

1. Go to this page and download the library: Download krtv/yii2-jms-serializer 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/ */

    

krtv / yii2-jms-serializer example snippets


return [
    // ...
    'components' => [
        'serializer' => [
            'class' => 'krtv\yii2\serializer\Serializer',
            'formats' => [
                'json',

                // XML is also available to use.
                // 'xml',
            ],

            // Uncomment if you would like to use handlers: http://jmsyst.com/libs/serializer/master/handlers
            //
            // 'handlers' => [
            //    'datetime' => [
            //        'defaultFormat' => 'c',  // ISO8601
            //    ],
            //    'my_handler' => [
            //        'class' => 'app\\serializer\\handler\\MyHandler',
            //    ],
            //    // ...
            // ],

            // Uncomment if you would like to use different naming strategy for properties.
            // "camel_case" is a default one. Available strategies are: "camel_case", "identical" and "custom".
            //
            // 'namingStrategy' => [
            //     'name' => 'camel_case',
            //     'options' => [
            //         'separator' => '_',
            //         'lowerCase' => true,
            //     ],
            // ],

            // Uncomment if you would like to configure class-metadata or enable cache.
            //
            // 'metadata' => [
            //     'cache' => true,
            //     'directories' => [
            //         [
            //             'namespace' => 'Foo\\Bar',
            //             'alias' => '@app/config/serializer/foo/bar',
            //         ],
            //         // ...
            //     ]
            // ],
        ],

        // ...
    ],

    // ...
];

echo $serializer->serialize(['foo' => 'bar'], 'json'); // {"foo": "bar"}