Giter Site home page Giter Site logo

aura.accept's Introduction

Aura.Accept

Provides content-negotiation tools using Accept* headers.

Installation and Autoloading

This package is installable and PSR-4 autoloadable via Composer as aura/accept.

Alternatively, download a release, or clone this repository, then map the Aura\Accept\ namespace to the package src/ directory.

Dependencies

This package requires PHP 7.2 or later. It has been tested on PHP 7.2 - 8.1. We recommend using the latest available version of PHP as a matter of principle.

Aura library packages may sometimes depend on external interfaces, but never on external implementations. This allows compliance with community standards without compromising flexibility. For specifics, please examine the package composer.json file.

Quality

Scrutinizer Code Quality codecov Continuous Integration

To run the PHPUnit unit tests at the command line, issue composer install and then vendor/bin/phpunit at the package root. This requires Composer to be available as composer.

This library attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Community

To ask questions, provide feedback, or otherwise communicate with the Aura community, please join our Google Group, follow @auraphp on Twitter, or chat with us on #auraphp on Freenode.

Documentation

This package is fully documented here.

aura.accept's People

Contributors

dhrrgn avatar dshafik avatar galactic-void avatar garoevans avatar gomboc avatar harikt avatar iansltx avatar jakeasmith avatar jelofson avatar koriym avatar pborreli avatar ralouphie avatar tomkyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aura.accept's Issues

Making set() / add() public

The abstract negotiator has a set() and add() method which would be good to have as public methods so that the negotiator could be instantiated and have the headers supplied independently from the $_SERVER super global, a mock array, and so that negotiators could be used more directly without the factory.

negotiateLanguage() does not seem to handle countries

If my preferred language is Castilian Spanish I'd expect to be served Spanish. But:

$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'es-ES';
$accept_factory = new AcceptFactory($_SERVER);
$accept = $accept_factory->newInstance();
$available_languages = array('es', 'pt');
$language = $accept->negotiateLanguage($available_languages);
var_dump($language);

... prints bool(false).

The other way round:

$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'es';
$accept_factory = new AcceptFactory($_SERVER);
$accept = $accept_factory->newInstance();
$available_languages = array('es-ES', 'pt');
$language = $accept->negotiateLanguage($available_languages);
var_dump($language);

... produces es, which is conceptually correct but is not really in the available list, thus requires more custom post-processing.

I don't know what the specs say about the expected behaviour but this feels like an overlook.

AbstractNegotiator Sort Fails

The AbstractNegotiator class's sort strategy has a logic error.

When it places values in buckets, it uses the value from the getQuality method, which returns a float.

The float value gets typecast into an integer index, and all values with the same leading digit Quality get grouped together and considered equal.

Typecasting the Quality to a string fixes the behavior.

Before:

$bucket[$value->getQuality()][] = $value;

After:

$bucket[(string)$value->getQuality()][] = $value;

Steps to reproduce:

  • Provide non-sorted header value

curl -I --header "Accept-Language: fr-CA;q=0.3,en-US;q=0.6,en-CA;q=0.7,en;q=0.4" APP_ENDPOINT

Expected result from negotiateLanguage(): en-CA
Actual result: fr-CA

Need a failing test for negotiateMedia

Hi Paul,

Do you have a failing test, so I can test

$media = $this->accept->negotiateMedia($available);
if (! $media) {
   $this->response->status->set(406);
   $this->response->content->setType('text/plain');
   $this->response->content->set(implode(',', $available));
   return false;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.