1. PHP / Говнокод #22851

    −16

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    <?php
    
        public function getGlobals()
        {
            return $this->globals;
        }
    
        /**
         * Initializes the built-in escapers.
         *
         * Each function specifies a way for applying a transformation to a string
         * passed to it. The purpose is for the string to be "escaped" so it is
         * suitable for the format it is being displayed in.
         *
         * For example, the string: "It's required that you enter a username & password.\n"
         * If this were to be displayed as HTML it would be sensible to turn the
         * ampersand into '&amp;' and the apostrophe into '&aps;'. However if it were
         * going to be used as a string in JavaScript to be displayed in an alert box
         * it would be right to leave the string as-is, but c-escape the apostrophe and
         * the new line.
         *
         * For each function there is a define to avoid problems with strings being
         * incorrectly specified.
         */
        protected function initializeEscapers()
        {
            $that = $this;
            $this->escapers = array(
                'html' =>
                /**
                 * Runs the PHP function htmlspecialchars on the value passed.
                 *
                 * @param string $value the value to escape
                 *
                 * @return string the escaped value
                 */
                function ($value) use ($that) {
                    // Numbers and Boolean values get turned into strings which can cause problems
                    // with type comparisons (e.g. === or is_int() etc).
                    return is_string($value) ? htmlspecialchars($value, ENT_QUOTES, $that->getCharset(), false) : $value;
                },
                'js' =>
                /**
                 * A function that escape all non-alphanumeric characters
                 * into their \xHH or \uHHHH representations
                 *
                 * @param string $value the value to escape
                 * @return string the escaped value
                 */
                function ($value) use ($that) {
                    if ('UTF-8' != $that->getCharset()) {
                        $value = $that->convertEncoding($value, 'UTF-8', $that->getCharset());
                    }
    
                    $callback = function ($matches) use ($that) {
                        $char = $matches[0];                        // \xHH
                        if (!isset($char[1])) {
                            return '\\x' . substr('00' . bin2hex($char), -2);
                        }                        // \uHHHH
                        $char = $that->convertEncoding($char, 'UTF-16BE', 'UTF-8');
                        return '\\u' . substr('0000' . bin2hex($char), -4);
                    };
                }
            );
        }

    Typing Lessons PHP/Symfony https://typing.io/lesson/php/symfony/PhpEngine.php/9

    Запостил: konmado, 25 Апреля 2017

    Комментарии (2) RSS

    Добавить комментарий