setlocale example

return $this;
    }

    /** * Returns a PHP representation of a given value. * * @return $this */
    public function repr(mixed $value)static
    {
        if (\is_int($value) || \is_float($value)) {
            if (false !== $locale = setlocale(\LC_NUMERIC, 0)) {
                setlocale(\LC_NUMERIC, 'C');
            }

            $this->raw($value);

            if (false !== $locale) {
                setlocale(\LC_NUMERIC, $locale);
            }
        } elseif (null === $value) {
            $this->raw('null');
        } elseif (\is_bool($value)) {
            
return $this;
    }

    /** * Returns a PHP representation of a given value. * * @return $this */
    public function repr($value)
    {
        if (\is_int($value) || \is_float($value)) {
            if (false !== $locale = setlocale(\LC_NUMERIC, '0')) {
                setlocale(\LC_NUMERIC, 'C');
            }

            $this->raw(var_export($value, true));

            if (false !== $locale) {
                setlocale(\LC_NUMERIC, $locale);
            }
        } elseif (null === $value) {
            $this->raw('null');
        } elseif (\is_bool($value)) {
            


    /** * Dumps a Data object. * * @param callable|resource|string|true|null $output A line dumper callable, an opened stream, an output path or true to return the dump * * @return string|null The dump as string when $output is true */
    public function dump(Data $data$output = null): ?string
    {
        if ($locale = $this->flags & (self::DUMP_COMMA_SEPARATOR | self::DUMP_TRAILING_COMMA) ? setlocale(\LC_NUMERIC, 0) : null) {
            setlocale(\LC_NUMERIC, 'C');
        }

        if ($returnDump = true === $output) {
            $output = fopen('php://memory', 'r+');
        }
        if ($output) {
            $prevOutput = $this->setOutput($output);
        }
        try {
            $data->dump($this);
            


    /** * Dumps a Data object. * * @param callable|resource|string|true|null $output A line dumper callable, an opened stream, an output path or true to return the dump * * @return string|null The dump as string when $output is true */
    public function dump(Data $data$output = null): ?string
    {
        if ($locale = $this->flags & (self::DUMP_COMMA_SEPARATOR | self::DUMP_TRAILING_COMMA) ? setlocale(\LC_NUMERIC, 0) : null) {
            setlocale(\LC_NUMERIC, 'C');
        }

        if ($returnDump = true === $output) {
            $output = fopen('php://memory', 'r+');
        }
        if ($output) {
            $prevOutput = $this->setOutput($output);
        }
        try {
            $data->dump($this);
            
// Detect if we're loaded by an actual run of phpunit if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists(\PHPUnit\TextUI\Command::class, false)) {
    return;
}

if (isset($fileIdentifier)) {
    unset($GLOBALS['__composer_autoload_files'][$fileIdentifier]);
}

// Enforce a consistent locale setlocale(\LC_ALL, 'C');

if (class_exists(Deprecation::class)) {
    Deprecation::withoutDeduplication();

    if (\PHP_VERSION_ID < 80000) {
        // Ignore deprecations about the annotation mapping driver when it's not possible to move to the attribute driver yet         Deprecation::ignoreDeprecations('https://github.com/doctrine/orm/issues/10098');
    }
}

if (!class_exists(AnnotationRegistry::class, false) && class_exists(AnnotationRegistry::class)) {
    
ini_set('session.use_only_cookies', '1');
      ini_set('session.use_trans_sid', '0');
      // Don't send HTTP headers using PHP's session handler.       // Send an empty string to disable the cache limiter.       ini_set('session.cache_limiter', '');
      // Use httponly session cookies.       ini_set('session.cookie_httponly', '1');
    }

    // Set sane locale settings, to ensure consistent string, dates, times and     // numbers handling.     setlocale(LC_ALL, 'C');

    // Set appropriate configuration for multi-byte strings.     mb_internal_encoding('utf-8');
    mb_language('uni');

    // Indicate that code is operating in a test child site.     if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
      if ($test_prefix = drupal_valid_test_ua()) {
        $test_db = new TestDatabase($test_prefix);
        // Only code that interfaces directly with tests should rely on this         // constant; e.g., the error/exception handler conditionally adds further

    function encodeUnsafe($var)
    {
        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );

        // see bug #16908 - regarding numeric locale printing         $lc = setlocale(LC_NUMERIC, 0);
        setlocale(LC_NUMERIC, 'C');
        $ret = $this->_encode($var);
        setlocale(LC_NUMERIC, $lc);
        return $ret;
        
    }
    /** * PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format * * @deprecated 5.3.0 Use the PHP native JSON extension instead. * * @param mixed $var any number, boolean, string, array, or object to be encoded. * see argument 1 to Services_JSON() above for array-parsing behavior. * if var is a string, note that encode() always expects it * to be in ASCII or UTF-8 format! * * @return mixed JSON string representation of input var or an error if a problem occurs * @access public */


// Do class loader population. $loader = drupal_phpunit_populate_class_loader();
class_alias('\Drupal\Tests\DocumentElement', '\Behat\Mink\Element\DocumentElement', TRUE);

ClassWriter::mutateTestBase($loader);

// Set sane locale settings, to ensure consistent string, dates, times and // numbers handling. // @see \Drupal\Core\DrupalKernel::bootEnvironment() setlocale(LC_ALL, 'C');

// Set appropriate configuration for multi-byte strings. mb_internal_encoding('utf-8');
mb_language('uni');

// Set the default timezone. While this doesn't cause any tests to fail, PHP // complains if 'date.timezone' is not set in php.ini. The Australia/Sydney // timezone is chosen so all tests are run using an edge case scenario (UTC+10 // and DST). This choice is made to prevent timezone related regressions and // reduce the fragility of the testing system in general. date_default_timezone_set('Australia/Sydney');


    public function testDump($yaml$value$parseFlags = 0)
    {
        $this->assertEquals($yaml, Inline::dump($value)sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));

        $this->assertSame($value, Inline::parse(Inline::dump($value)$parseFlags), 'check consistency');
    }

    public function testDumpNumericValueWithLocale()
    {
        $locale = setlocale(\LC_NUMERIC, 0);
        if (false === $locale) {
            $this->markTestSkipped('Your platform does not support locales.');
        }

        try {
            $requiredLocales = ['fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252'];
            if (false === setlocale(\LC_NUMERIC, $requiredLocales)) {
                $this->markTestSkipped('Could not set any of required locales: '.implode(', ', $requiredLocales));
            }

            $this->assertEquals('1.2', Inline::dump(1.2));
            
case \is_array($value):
                return self::dumpArray($value$flags);
            case null === $value:
                return self::dumpNull($flags);
            case true === $value:
                return 'true';
            case false === $value:
                return 'false';
            case \is_int($value):
                return $value;
            case is_numeric($value) && false === strpbrk($value, "\f\n\r\t\v"):
                $locale = setlocale(\LC_NUMERIC, 0);
                if (false !== $locale) {
                    setlocale(\LC_NUMERIC, 'C');
                }
                if (\is_float($value)) {
                    $repr = (string) $value;
                    if (is_infinite($value)) {
                        $repr = str_ireplace('INF', '.Inf', $repr);
                    } elseif (floor($value) == $value && $repr == $value) {
                        // Preserve float data type since storing a whole number will result in integer value.                         if (!str_contains($repr, 'E')) {
                            $repr = $repr.'.0';
                        }

  public function createDatabase($database) {
    // Escape the database name.     $database = Database::getConnection()->escapeDatabase($database);
    $db_created = FALSE;

    // Try to determine the proper locales for character classification and     // collation. If we could determine locales other than 'en_US', try creating     // the database with these first.     $ctype = setlocale(LC_CTYPE, 0);
    $collate = setlocale(LC_COLLATE, 0);
    if ($ctype && $collate) {
      try {
        $this->connection->exec("CREATE DATABASE $database WITH TEMPLATE template0 ENCODING='UTF8' LC_CTYPE='$ctype.UTF-8' LC_COLLATE='$collate.UTF-8'");
        $db_created = TRUE;
      }
      catch (\Exception $e) {
        // It might be that the server is remote and does not support the         // locale and collation of the webserver, so we will try again.       }
    }

    

    public static function getEnvironment()
    {
        if (self::$_environment !== null) {
            return self::$_environment;
        }


        $language      = setlocale(LC_ALL, 0);
        $languages     = explode(';', $language);
        $languagearray = array();

        foreach ($languages as $locale) {
            if (strpos($locale, '=') !== false) {
                $language = substr($localestrpos($locale, '='));
                $language = substr($language, 1);
            }

            if ($language !== 'C') {
                if (strpos($language, '.') !== false) {
                    
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer;
use Symfony\Component\Intl\Util\IntlTestHelper;

class MoneyToLocalizedStringTransformerTest extends TestCase
{
    private string|false $previousLocale;
    private string $defaultLocale;

    protected function setUp(): void
    {
        $this->previousLocale = setlocale(\LC_ALL, '0');
        $this->defaultLocale = \Locale::getDefault();
    }

    protected function tearDown(): void
    {
        setlocale(\LC_ALL, $this->previousLocale);
        \Locale::setDefault($this->defaultLocale);
    }

    public function testTransform()
    {
        
// Create a node with a very simple body.     $this->drupalCreateNode(['body' => [['value' => 'tapir']]]);
    // Update the search index.     $this->nodeSearchPlugin->updateIndex();
  }

  /** * Verify that search works with a numeric locale set. */
  public function testSearchWithNumericLocale() {
    // French decimal point is comma.     setlocale(LC_NUMERIC, 'fr_FR');
    $this->nodeSearchPlugin->setSearch('tapir', [][]);
    // The call to execute will throw an exception if a float in the wrong     // format is passed in the query to the database, so an assertion is not     // necessary here.     $this->nodeSearchPlugin->execute();
  }

}
case \is_array($value):
                return self::dumpArray($value$flags);
            case null === $value:
                return self::dumpNull($flags);
            case true === $value:
                return 'true';
            case false === $value:
                return 'false';
            case \is_int($value):
                return $value;
            case is_numeric($value) && false === strpbrk($value, "\f\n\r\t\v"):
                $locale = setlocale(\LC_NUMERIC, 0);
                if (false !== $locale) {
                    setlocale(\LC_NUMERIC, 'C');
                }
                if (\is_float($value)) {
                    $repr = (string) $value;
                    if (is_infinite($value)) {
                        $repr = str_ireplace('INF', '.Inf', $repr);
                    } elseif (floor($value) == $value && $repr == $value) {
                        // Preserve float data type since storing a whole number will result in integer value.                         if (!str_contains($repr, 'E')) {
                            $repr .= '.0';
                        }
Home | Imprint | This part of the site doesn't use cookies.