<commit_before><?php
/**
 * Klein (klein.php) - A lightning fast router for PHP
 *
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> (Rican7) (contributor and v2 refactorer)
 * @copyright   (c) <NAME>
 * @link        https://github.com/chriso/klein.php
 * @license     MIT
 */

namespace Klein\DataCollection;

/**
 * ServerDataCollection
 *
 * A DataCollection for "$_SERVER" like data
 *
 * Look familiar?
 *
 * Inspired by @fabpot's Symfony 2's HttpFoundation
 * @link https://github.com/symfony/HttpFoundation/blob/master/ServerBag.php
 *
 * @uses DataCollection
 * @package     Klein\DataCollection
 */
class ServerDataCollection extends DataCollection
{

    /**
     * Class properties
     */

    /**
     * The prefix of HTTP headers normally
     * stored in the Server data
     *
     * @static
     * @var string
     * @access protected
     */
    protected static $http_header_prefix = 'HTTP_';

    /**
     * The list of HTTP headers that for some
     * reason aren't prefixed in PHP...
     *
     * @static
     * @var string
     * @access protected
     */
    protected static $http_nonprefixed_headers = array(
        'CONTENT_LENGTH',
        'CONTENT_TYPE',
        'CONTENT_MD5',
    );


    /**
     * Methods
     */

    /**
     * Quickly check if a string has a passed prefix
     *
     * Use the more convoluted "substr" method, as its
     * slightly faster than using the "strpos" method
     *
     * @param string $string    The string to check
     * @param string $prefix    The prefix to test
     * @static
     * @access public
     * @return boolean
     */
    public static function hasPrefix($string, $prefix)
    {
        if (substr($string, 0, strlen($prefix)) === $prefix) {
            return true;
        }

        return false;
    }

    /**
     * Get our headers from our server data collection
     *
     * PHP is weird... it puts all of the HTTP request
     * headers in the $_SERVER array. This handles that
     *
     * @access public
     * @return array
     */
    public function getHeaders()
    {
        // Define a headers array
        $headers = array();

        foreach ($this->attributes as $key => $value) {
            // Does our server attribute have our header prefix?
            if (self::hasPrefix($key, self::$http_header_prefix)) {<commit_msg>Swapping the "substr()" method for the "strpos()" method of checking if a string starts with another for performance reasons: - http://maettig.com/code/php/php-performance-benchmarks.php - https://github.com/chriso/klein.php/pull/92#discussion_r4196057<commit_after><?php
/**
 * Klein (klein.php) - A lightning fast router for PHP
 *
 * @author      <NAME> <<EMAIL>>
 * @author      <NAME> (Rican7) (contributor and v2 refactorer)
 * @copyright   (c) <NAME>
 * @link        https://github.com/chriso/klein.php
 * @license     MIT
 */

namespace Klein\DataCollection;

/**
 * ServerDataCollection
 *
 * A DataCollection for "$_SERVER" like data
 *
 * Look familiar?
 *
 * Inspired by @fabpot's Symfony 2's HttpFoundation
 * @link https://github.com/symfony/HttpFoundation/blob/master/ServerBag.php
 *
 * @uses DataCollection
 * @package     Klein\DataCollection
 */
class ServerDataCollection extends DataCollection
{

    /**
     * Class properties
     */

    /**
     * The prefix of HTTP headers normally
     * stored in the Server data
     *
     * @static
     * @var string
     * @access protected
     */
    protected static $http_header_prefix = 'HTTP_';

    /**
     * The list of HTTP headers that for some
     * reason aren't prefixed in PHP...
     *
     * @static
     * @var string
     * @access protected
     */
    protected static $http_nonprefixed_headers = array(
        'CONTENT_LENGTH',
        'CONTENT_TYPE',
        'CONTENT_MD5',
    );


    /**
     * Methods
     */

    /**
     * Quickly check if a string has a passed prefix
     *
     * @param string $string    The string to check
     * @param string $prefix    The prefix to test
     * @static
     * @access public
     * @return boolean
     */
    public static function hasPrefix($string, $prefix)
    {
        if (strpos($string, $prefix) === 0) {
            return true;
        }

        return false;
    }

    /**
     * Get our headers from our server data collection
     *
     * PHP is weird... it puts all of the HTTP request
     * headers in the $_SERVER array. This handles that
     *
     * @access public
     * @return array
     */
    public function getHeaders()
    {
        // Define a headers array
        $headers = array();

        foreach ($this->attributes as $key => $value) {
            // Does our server attribute have our header prefix?
            if (self::hasPrefix($key, self::$http_header_prefix)) {
{'fraction_non_alphanumeric': 0.11169102296450939, 'fraction_numerical': 0.003966597077244259, 'mean_word_length': 2.1602902374670183, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 5, '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': '1450569', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1363, 'n_words': 430}