<commit_before><?php

namespace Symfony\Component\HttpFoundation;

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * HeaderBag is a container for HTTP headers.
 *
 * @author <NAME> <<EMAIL>>
 */
class HeaderBag
{
    protected $headers;
    protected $cacheControl;
    protected $type;

    /**
     * Constructor.
     *
     * @param array  $headers An array of HTTP headers
     * @param string $type       The type (null, request, or response)
     */
    public function __construct(array $headers = array(), $type = null)
    {
        $this->replace($headers);

        if (null !== $type && !in_array($type, array('request', 'response'))) {
            throw new \InvalidArgumentException(sprintf('The "%s" type is not supported by the HeaderBag constructor.', $type));
        }
        $this->type = $type;
    }

    /**
     * Returns the headers.
     *
     * @return array An array of headers
     */
    public function all()
    {
        return $this->headers;
    }

    /**
     * Returns the parameter keys.
     *
     * @return array An array of parameter keys
     */
    public function keys()
    {
        return array_keys($this->headers);
    }

    /**
     * Replaces the current HTTP headers by a new set.
     *
     * @param array  $headers An array of HTTP headers
     */
    public function replace(array $headers = array())
    {
        $this->cacheControl = null;
        $this->headers = array();
        foreach ($headers as $key => $values) {
            $this->set($key, $values);
        }
    }

    /**
     * Returns a header value by name.
     *
     * @param string  $key   The header name
     * @param Boolean $first Whether to return the first value or all header values
     *
     * @return string|array The first header value if $first is true, an array of values otherwise
     */
    public function get($key, $first = true)
    {
        $key = strtr(strtolower($key), '_', '-');

        if (!array_key_exists($key, $this->headers)) {
            return $first ? null : array();
        }

        if ($first) {
            return count($this->headers[$key]) ? $this->headers[$key][0] : '';
        } else {
            return $this->headers[$key];
        }
    }

    /**
     * Sets a header by name.
     *
     * @param string       $key     The key
     * @param string|array $values  The value or an array of values
     * @param Boolean      $replace Whether to replace the actual value of not (true by default)
     */
    public function set($key, $values, $replace = true)
    {
        $key = strtr(strtolower($key), '_', '-');

        if (!is_array($values)) {
            $values = array($values);
        }

        if (true === $replace || !isset($this->headers[$key])) {
            $this->headers[$key] = $values;
        } else {
            $this->headers[$key] = array_merge($this->headers[$key], $values);
        }
    }

    /**
     * Returns true if the HTTP header is defined.
     *
     * @param string $key The HTTP header
     *
     * @return Boolean true if the parameter exists, false otherwise
     */
    public function has($key)
    {
        return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
    }

    /**
     * Returns true if the given HTTP header contains the given value.
     *
     * @param string $key   The HTTP header name
     * @param string $value The HTTP value
     *
     * @return Boolean true if the value is contained in the header, false otherwise
     */
    public function contains($key, $value)
    {
        return in_array($value, $this->get($key, false));
    }

    /**
     * Deletes a header.
     *
     * @param string $key The HTTP header name
     */
    public function delete($key)
    {
        unset($this->headers[strtr(strtolower($key), '_', '-')]);
    }<commit_msg>[HttpFoundation] updated get() signature to get($key, $default = null, $first = true)<commit_after><?php

namespace Symfony\Component\HttpFoundation;

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * HeaderBag is a container for HTTP headers.
 *
 * @author <NAME> <<EMAIL>>
 */
class HeaderBag
{
    protected $headers;
    protected $cacheControl;
    protected $type;

    /**
     * Constructor.
     *
     * @param array  $headers An array of HTTP headers
     * @param string $type       The type (null, request, or response)
     */
    public function __construct(array $headers = array(), $type = null)
    {
        $this->replace($headers);

        if (null !== $type && !in_array($type, array('request', 'response'))) {
            throw new \InvalidArgumentException(sprintf('The "%s" type is not supported by the HeaderBag constructor.', $type));
        }
        $this->type = $type;
    }

    /**
     * Returns the headers.
     *
     * @return array An array of headers
     */
    public function all()
    {
        return $this->headers;
    }

    /**
     * Returns the parameter keys.
     *
     * @return array An array of parameter keys
     */
    public function keys()
    {
        return array_keys($this->headers);
    }

    /**
     * Replaces the current HTTP headers by a new set.
     *
     * @param array  $headers An array of HTTP headers
     */
    public function replace(array $headers = array())
    {
        $this->cacheControl = null;
        $this->headers = array();
        foreach ($headers as $key => $values) {
            $this->set($key, $values);
        }
    }

    /**
     * Returns a header value by name.
     *
     * @param string  $key     The header name
     * @param mixed   $default The default value
     * @param Boolean $first   Whether to return the first value or all header values
     *
     * @return string|array The first header value if $first is true, an array of values otherwise
     */
    public function get($key, $default = null, $first = true)
    {
        $key = strtr(strtolower($key), '_', '-');

        if (!array_key_exists($key, $this->headers)) {
            if (null === $default) {
                return $first ? null : array();
            } else {
                return $first ? $default : array($default);
            }
        }

        if ($first) {
            return count($this->headers[$key]) ? $this->headers[$key][0] : $default;
        } else {
            return $this->headers[$key];
        }
    }

    /**
     * Sets a header by name.
     *
     * @param string       $key     The key
     * @param string|array $values  The value or an array of values
     * @param Boolean      $replace Whether to replace the actual value of not (true by default)
     */
    public function set($key, $values, $replace = true)
    {
        $key = strtr(strtolower($key), '_', '-');

        if (!is_array($values)) {
            $values = array($values);
        }

        if (true === $replace || !isset($this->headers[$key])) {
            $this->headers[$key] = $values;
        } else {
            $this->headers[$key] = array_merge($this->headers[$key], $values);
        }
    }

    /**
     * Returns true if the HTTP header is defined.
     *
     * @param string $key The HTTP header
     *
     * @return Boolean true if the parameter exists, false otherwise
     */
    public function has($key)
    {
        return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
    }

    /**
     * Returns true if the given HTTP header contains the given value.
     *
     * @param string $key   The HTTP header name
     * @param string $value The HTTP value
     *
     * @return Boolean true if the value is contained in the header, false otherwise
     */
    public function contains($key, $value)
    {
        return in_array($value, $this->get($key, null, false));
    }

    /**
     * Deletes a header.
     *
     * @param string $key The HTTP header name
     */
    public function delete($key)
    {
        unset($this->headers[strtr(strtolower($key), '_', '-')]);
    }
{'fraction_non_alphanumeric': 0.1327145612343298, 'fraction_numerical': 0.00024108003857280618, 'mean_word_length': 2.0559852670349907, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3772077', 'n_tokens_mistral': 2360, 'n_tokens_neox': 2326, 'n_words': 761}