iceman1010 / php-chardet-modern
PHP wrapper around the chardet CLI - drop-in replacement for yupmin/php-chardet on modern dependencies
Requires
- php: >=7.4
- symfony/process: ^5.4 || ^6.4 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Namespace-identical fork of yupmin/php-chardet
(1.0.1, abandoned 2015) on modern dependencies. Same PHP namespace
(Yupmin\PHPChardet), same API, same behavior — it is a drop-in replacement:
- "yupmin/php-chardet": "^1.0" + "iceman1010/php-chardet-modern": "^1.1"
No consumer code changes are required; the Yupmin\PHPChardet classes resolve
exactly as before.
What changed vs. upstream
symfony/processrequirement modernized:^5.4 || ^6.4 || ^7.0(upstream pinned~2.3, which Composer >= 2.9 refuses for security advisories). The runner now uses theProcessclass directly instead of the removedProcessBuilder.symfony/filesystemdependency dropped (upstream used it for a singlefile_exists()check).- PHP floor raised to
>= 7.4. - API surface, namespace, class names, and observable behavior are unchanged.
Requirements
- PHP >= 7.4
- Composer
- The
chardetcommand-line tool on your PATH (runtime requirement inherited from upstream, unchanged)
Install the CLI, e.g.:
sudo apt-get install chardet
# or
pip install chardet
Installation
composer require iceman1010/php-chardet-modern
Usage
use Yupmin\PHPChardet\Chardet; $chardet = new Chardet(); $chardetContainer = $chardet->analyze('test.txt'); $filePath = $chardetContainer->getFilePath(); $charset = $chardetContainer->getCharset(); // e.g. 'utf-8' (lowercased) $confidence = $chardetContainer->getConfidence(); // e.g. 0.99 (float)
Failure modes (all inherited from upstream):
- Non-existent path or directory passed to
analyze():\Exception. chardetCLI exits non-zero:\RuntimeExceptioncarrying the error output.- Unanalyzable input (chardet reports
None):\Exception.
Tests
composer install vendor/bin/phpunit
Tests that need the chardet CLI skip automatically when it is absent.
smoke.php is a dependency-free check (no PHPUnit needed) for verifying the
installed package on a target host:
php smoke.php # in this repo (uses ./vendor/autoload.php) php smoke.php /path/to/project/vendor/autoload.php # against a project autoloader
Credits & license
Fork of yupmin/php-chardet by
yun young-jin (MIT). See LICENSE — original copyright preserved, fork
copyright added.