Standardize settings file naming and relocate documentation files Fix code quality violations from rsx:check Reorganize user_management directory into logical subdirectories Move Quill Bundle to core and align with Tom Select pattern Simplify Site Settings page to focus on core site information Complete Phase 5: Multi-tenant authentication with login flow and site selection Add route query parameter rule and synchronize filename validation logic Fix critical bug in UpdateNpmCommand causing missing JavaScript stubs Implement filename convention rule and resolve VS Code auto-rename conflict Implement js-sanitizer RPC server to eliminate 900+ Node.js process spawns Implement RPC server architecture for JavaScript parsing WIP: Add RPC server infrastructure for JS parsing (partial implementation) Update jqhtml terminology from destroy to stop, fix datagrid DOM preservation Add JQHTML-CLASS-01 rule and fix redundant class names Improve code quality rules and resolve violations Remove legacy fatal error format in favor of unified 'fatal' error type Filter internal keys from window.rsxapp output Update button styling and comprehensive form/modal documentation Add conditional fly-in animation for modals Fix non-deterministic bundle compilation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
149 lines
4.3 KiB
PHP
Executable File
149 lines
4.3 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Sokil\IsoCodes;
|
|
|
|
use Sokil\IsoCodes\Database\Countries;
|
|
use Sokil\IsoCodes\Database\Currencies;
|
|
use Sokil\IsoCodes\Database\HistoricCountries;
|
|
use Sokil\IsoCodes\Database\Languages;
|
|
use Sokil\IsoCodes\Database\LanguagesInterface;
|
|
use Sokil\IsoCodes\Database\LanguagesPartitioned;
|
|
use Sokil\IsoCodes\Database\Scripts;
|
|
use Sokil\IsoCodes\Database\Subdivisions;
|
|
use Sokil\IsoCodes\Database\SubdivisionsInterface;
|
|
use Sokil\IsoCodes\Database\SubdivisionsPartitioned;
|
|
use Sokil\IsoCodes\TranslationDriver\GettextExtensionDriver;
|
|
use Sokil\IsoCodes\TranslationDriver\TranslationDriverInterface;
|
|
|
|
/**
|
|
* Factory class to build ISO databases
|
|
*/
|
|
class IsoCodesFactory
|
|
{
|
|
/**
|
|
* Database splits into partition files.
|
|
*
|
|
* Fetching some entry will load only little part of database.
|
|
* Loaded entries not stored statically.
|
|
*
|
|
* This scenario may be useful when just few entries need
|
|
* to be loaded, for example on web request when one entry fetched.
|
|
*
|
|
* This may require a lot of file read operations.
|
|
*/
|
|
public const OPTIMISATION_MEMORY = 1;
|
|
|
|
/**
|
|
* Entire database loaded into memory from single JSON file once.
|
|
*
|
|
* All entries created and stored into RAM. Next read of save
|
|
* entry will just return it without io operations with files and building objects.
|
|
*
|
|
* This scenario may be useful for daemons to decrease file operations,
|
|
* or when most entries will be fetched from database.
|
|
*
|
|
* This may require a lot of RAM for storing all entries.
|
|
*/
|
|
public const OPTIMISATION_IO = 2;
|
|
|
|
/**
|
|
* Path to directory with databases
|
|
*
|
|
* @var string
|
|
*/
|
|
private $baseDirectory;
|
|
|
|
/**
|
|
* @var TranslationDriverInterface
|
|
*/
|
|
private $translationDriver;
|
|
|
|
public function __construct(
|
|
?string $baseDirectory = null,
|
|
?TranslationDriverInterface $translationDriver = null
|
|
) {
|
|
$this->baseDirectory = $baseDirectory;
|
|
$this->translationDriver = $translationDriver ?? new GettextExtensionDriver();
|
|
}
|
|
|
|
/**
|
|
* ISO 3166-1
|
|
*/
|
|
public function getCountries(): Countries
|
|
{
|
|
return new Countries($this->baseDirectory, $this->translationDriver);
|
|
}
|
|
|
|
/**
|
|
* ISO 3166-2
|
|
*
|
|
* @param int $optimisation One of self::OPTIMISATION_* constants
|
|
*
|
|
* @throws \InvalidArgumentException When invalid optimisation specified
|
|
*/
|
|
public function getSubdivisions(int $optimisation = self::OPTIMISATION_MEMORY): SubdivisionsInterface
|
|
{
|
|
switch ($optimisation) {
|
|
case self::OPTIMISATION_MEMORY:
|
|
$database = new SubdivisionsPartitioned($this->baseDirectory, $this->translationDriver);
|
|
break;
|
|
case self::OPTIMISATION_IO:
|
|
$database = new Subdivisions($this->baseDirectory, $this->translationDriver);
|
|
break;
|
|
default:
|
|
throw new \InvalidArgumentException('Invalid optimisation specified');
|
|
}
|
|
|
|
return $database;
|
|
}
|
|
|
|
/**
|
|
* ISO 3166-3
|
|
*/
|
|
public function getHistoricCountries(): HistoricCountries
|
|
{
|
|
return new HistoricCountries($this->baseDirectory, $this->translationDriver);
|
|
}
|
|
|
|
/**
|
|
* ISO 15924
|
|
*/
|
|
public function getScripts(): Scripts
|
|
{
|
|
return new Scripts($this->baseDirectory, $this->translationDriver);
|
|
}
|
|
|
|
/**
|
|
* ISO 4217
|
|
*/
|
|
public function getCurrencies(): Currencies
|
|
{
|
|
return new Currencies($this->baseDirectory, $this->translationDriver);
|
|
}
|
|
|
|
/**
|
|
* ISO 639-3
|
|
*
|
|
* @param int $optimisation One of self::OPTIMISATION_* constants
|
|
*
|
|
* @throws \InvalidArgumentException When invalid optimisation specified
|
|
*/
|
|
public function getLanguages(int $optimisation = self::OPTIMISATION_MEMORY): LanguagesInterface
|
|
{
|
|
switch ($optimisation) {
|
|
case self::OPTIMISATION_MEMORY:
|
|
$database = new LanguagesPartitioned($this->baseDirectory, $this->translationDriver);
|
|
break;
|
|
case self::OPTIMISATION_IO:
|
|
$database = new Languages($this->baseDirectory, $this->translationDriver);
|
|
break;
|
|
default:
|
|
throw new \InvalidArgumentException('Invalid optimisation specified');
|
|
}
|
|
|
|
return $database;
|
|
}
|
|
}
|