PHP code example of bear / accept

1. Go to this page and download the library: Download bear/accept 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/ */

    

bear / accept example snippets



use Ray\Di\AbstractModule;
use Ray\Di\Scope;

class AppModule extends AbstractModule
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $available = [
            'Accept' => [
                'application/hal+json' => 'prod-hal-app',
                'application/json' => 'prod-app',
                'text/csv' => 'prod-csv-app',
                'cli' => 'prod-html-app'
            ],
            'Accept-Language' => [
                'en-US' => 'en',
                'ja-JP' => 'ja'
            ]
        ];
        // $available support 'Accept' and 'Accept-Language' key only
        $this->install(new AcceptModule($available));
    }
}

use use BEAR\Accept\Annotation\Produces;

/**
 * @Produces({"application/json", "text/csv"})
 */
public function onGet()



$available = [
    'Accept' => [
        'text/html' => 'prod-html-app',
        'application/hal+json' => 'prod-hal-app',
        'application/json' => 'prod-app',
        'cli' => 'cli-html-app'
    ],
    'Accept-Language' => [
        'ja' => 'ja',
        'en-US' => 'us'
    ]
];
$accept = new \BEAR\Accept\Accept($available);
[$context, $vary] = $accept($_SERVER);
//


use BEAR\Sunday\Module\Constant\NamedModule;

class JaModule extends AbstractModule
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $text = ['greeting' => 'こんにちは'];
        $this->install(new NamedModule($text));
    }
}
diff
+    /* @global \BEAR\Resource\Vary $vary */
+    if (isset($vary)) {
+        $page->headers['Vary'] = $vary;
+    }
     $page->transfer($app->responder, $_SERVER);