PHPackages                             bear/accept - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bear/accept

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bear/accept
===========

Provides content-negotiation using Accept\* headers for BEAR.Sunday

1.0.1(5mo ago)173.7k↓49.5%MITPHPPHP ^8.2CI passing

Since Aug 10Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/bearsunday/BEAR.Accept)[ Packagist](https://packagist.org/packages/bear/accept)[ RSS](/packages/bear-accept/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (6)Used By (0)

BEAR.Accept
===========

[](#bearaccept)

Provides content-negotiation using Accept\* headers for [BEAR.Sunday](http://bearsunday.github.io/)

Composer install
----------------

[](#composer-install)

```
$ composer require bear/accept

```

Module install
--------------

[](#module-install)

```
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));
    }
}
```

`Accept` specifies all of the available media in the format `[$mediatype => $context]`. `cli` is the context in case of console access. The renderer of the context of the media type matched by content negotiation is used for rendering the resource.

`Accept-Language` specifies all available languages in the format `[$lang => $contextKey]`.

For example, if `application/hal+json` and `ja-JP`matches, the `$context` is `prod-hal-jp-app`. (We set `JpModule` in `App\Module` folder and bind it for Japanese.)

Usage
=====

[](#usage)

Apply to the specified resource
-------------------------------

[](#apply-to-the-specified-resource)

Annotate the resource to do content negotiation with `#[Produces]`.

```
use BEAR\Accept\Annotation\Produces;

#[Produces(['application/json', 'text/csv'])]
public function onGet()
```

**application/json** and **text/csv** media type is available for this resource. The `Vary` header is added automatically.

Apply to all resources
----------------------

[](#apply-to-all-resources)

To perform content negotiation on all resources, prepare a special bootstrap file. This is especially useful when negotiating languages.

cn.php

```
require dirname(__DIR__) . '/vendor/autoload.php';

$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);
//
```

Add a vary header in `Bootstrap` to enable caching when using content negotiation.

```
+    /* @global \BEAR\Resource\Vary $vary */
+    if (isset($vary)) {
+        $page->headers['Vary'] = $vary;
+    }
     $page->transfer($app->responder, $_SERVER);
```

Prepare the module of the DI setting necessary for each language.

```
use BEAR\Sunday\Module\Constant\NamedModule;

class JaModule extends AbstractModule
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $text = ['greeting' => 'こんにちは'];
        $this->install(new NamedModule($text));
    }
}
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance71

Regular maintenance activity

Popularity31

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1013 days

Total

4

Last Release

162d ago

Major Versions

0.1.0 → 1.0.02022-06-24

PHP version history (3 changes)0.1.0PHP &gt;=7.0.0

1.0.0PHP ^7.4 || ^8.0

1.0.1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/db4fc75ffc631168d0d7143b6f2c24b1534dfb921212bd851c026c5cbbb1344d?d=identicon)[koriym](/maintainers/koriym)

---

Top Contributors

[![koriym](https://avatars.githubusercontent.com/u/529021?v=4)](https://github.com/koriym "koriym (60 commits)")

---

Tags

bearsundaybearsunday-modulecontent-negotiationacceptcontent negotiation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bear-accept/health.svg)

```
[![Health](https://phpackages.com/badges/bear-accept/health.svg)](https://phpackages.com/packages/bear-accept)
```

###  Alternatives

[willdurand/negotiation

Content Negotiation tools for PHP provided as a standalone library.

1.4k122.0M157](/packages/willdurand-negotiation)[aura/accept

Provides content-negotiation tools using Accept\* headers.

34552.0k9](/packages/aura-accept)[bitworking/mimeparse

Basic functions for handling mime-types.

41181.6k1](/packages/bitworking-mimeparse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
