PHP code example of xurudragon / api-versioning-bundle

1. Go to this page and download the library: Download xurudragon/api-versioning-bundle 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/ */

    

xurudragon / api-versioning-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new XuruDragon\ApiVersioningBundle\XuruDragonApiVersioningBundle(),
        );

        // ...
    }

    // ...
}



//config/bundles.php

return [
    // ....
    XuruDragon\ApiVersioningBundle\XuruDragonApiVersioningBundle::class => ['all' => true],
];


// ../ApiChanges/ApiChanges090.php

namespace Your\Bundle\ApiChanges;

use XuruDragon\ApiVersioningBundle\Changes\AbstractChanges,

class ApiChanges090 extends AbstractChanges
{

    /**
     * Apply version changes for current request.
     *
     * @param array $data
     *
     * @return null|array
     */
    public function apply(array $data = [])
    {
        return $data;
    }

    /**
     * Returns true if this version changes is supported for current request.
     *
     * @param array $data
     *
     * @return null|bool
     */
    public function supports(array $data = [])
    {
        return true;
    }
    // ...
}

$data = [
    'results' => [
        'firstname' => 'John',
        'lastname' => 'Doe',
        'location' => '4, Privet Drive, Little Whinging, Surey', 
    ],
];


// ../ApiChanges/ApiChanges090.php

namespace Your\Bundle\ApiChanges;

use XuruDragon\ApiVersioningBundle\Changes\AbstractChanges,

/**
 * Class ApiChanges090.
 */
class ApiChanges090 extends AbstractChanges
{
    /**
     * {@inheritdoc}
     */
    public function apply(array $data = [])
    {
        //short example, but can be more more complex
        unset($data['results']['location']);

        return $data;
    }

    /**
     * {@inheritdoc}
     */
    public function supports(array $data = [])
    {
        //check for the entry column "location" in the results sub-array of $data
        return isset($data['results']) && array_search('location', array_keys($data['results']), true);
    }
    // ...
}