CoreFiles by mySites.guru
LanguageNegotiator.php41 lines, 1,075 bytes, from Joomla_4.4.2-Stable-Full_Package.zip
Raw History Compare with 4.4.1
md5
6fcef138dbc04354f4c61c7c3bd8e0e7
sha1
ea991a50cebbc6fb556e7d4c4410858fdb70f0d4
sha256
5fbc41e3b1aa992099b2d2048a9c82a9fdc43f87b089672bdab3f3ac1160f5f1
<?php

namespace Negotiation;

class LanguageNegotiator extends AbstractNegotiator
{
    /**
     * {@inheritdoc}
     */
    protected function acceptFactory($accept)
    {
        return new AcceptLanguage($accept);
    }

    /**
     * {@inheritdoc}
     */
    protected function match(AcceptHeader $acceptLanguage, AcceptHeader $priority, $index)
    {
        if (!$acceptLanguage instanceof AcceptLanguage || !$priority instanceof AcceptLanguage) {
            return null;
        }

        $ab = $acceptLanguage->getBasePart();
        $pb = $priority->getBasePart();

        $as = $acceptLanguage->getSubPart();
        $ps = $priority->getSubPart();

        $baseEqual = !strcasecmp((string)$ab, (string)$pb);
        $subEqual  = !strcasecmp((string)$as, (string)$ps);

        if (($ab == '*' || $baseEqual) && ($as === null || $subEqual || null === $ps)) {
            $score = 10 * $baseEqual + $subEqual;

            return new AcceptMatch($acceptLanguage->getQuality() * $priority->getQuality(), $score, $index);
        }

        return null;
    }
}

The same content is in 236 releases, Joomla 4.2.0-alpha3 to 6.3.0-alpha1. See them all, or every version of this file.