alto/language
Composer 安装命令:
composer require alto/language
包简介
Alto PHP library for programming language identification: extensions, aliases, markers, indentations
README 文档
README
A lightweight PHP library providing structured metadata for 62 programming languages — extensions, aliases, filenames, syntax markers, and more.
Zero dependencies. 100% test coverage. PHP 8.4+.
Installation
composer require alto/language
Quick Start
use Alto\Language\Languages; // Lookup by slug $php = Languages::get('php'); $php->name; // "PHP" $php->extensions; // [".php", ".phtml", ".php3", …] $php->type; // LanguageType::Programming // Lookup by file extension Languages::fromExtension('.ts'); // → typescript Languages::fromExtension('rs'); // → rust (dot is optional) // Lookup by alias Languages::fromAlias('py'); // → python Languages::fromAlias('jsx'); // → javascript // Lookup by filename Languages::fromFilename('Dockerfile'); // → dockerfile Languages::fromFilename('Makefile'); // → makefile Languages::fromFilename('.gitignore'); // → ignore // Compound extension fallback Languages::fromFilename('phpunit.xml.dist'); // → xml // Resolve from any identifier (slug → alias → extension → filename) Languages::resolve('typescript'); // by slug Languages::resolve('ts'); // by alias Languages::resolve('.tsx'); // by extension Languages::resolve('Makefile'); // by filename
API
Static Facade (Languages)
| Method | Returns | Description |
|---|---|---|
Languages::get($slug) |
?Language |
Lookup by slug |
Languages::fromExtension($ext) |
?Language |
Lookup by file extension |
Languages::fromAlias($alias) |
?Language |
Lookup by alias |
Languages::fromFilename($name) |
?Language |
Lookup by exact filename or extension |
Languages::resolve($identifier) |
?Language |
Try all lookup methods in order |
Languages::all() |
Language[] |
All registered languages |
Languages::ofType($type) |
Language[] |
Filter by LanguageType |
Languages::children($slug) |
Language[] |
Languages whose parent is the given slug |
Languages::conflicts() |
array |
Extension/alias/filename collisions |
Injectable Registry (LanguageRegistry)
All facade methods delegate to LanguageRegistry, which can be injected directly:
use Alto\Language\LanguageRegistry; $registry = new LanguageRegistry(); $python = $registry->get('python');
Language Object
Each Language is an immutable value object:
$lang = Languages::get('typescript'); $lang->name; // "TypeScript" $lang->slug; // "typescript" $lang->type; // LanguageType::Programming $lang->extensions; // [".ts", ".tsx", ".mts", ".cts"] $lang->aliases; // ["ts"] $lang->filenames; // [] $lang->year; // 2012 $lang->parent; // "javascript" $lang->markers; // CodeMarkers instance
Languages are JSON-serializable:
json_encode(Languages::get('go'));
Code Markers
Syntax fingerprints attached to each language:
$markers = Languages::get('php')->markers; $markers->lineComments; // ["//", "#"] $markers->blockComments; // [["/*", "*/"]] $markers->docComment; // ["/**", "*/"] $markers->stringDelimiters; // ["\"", "'"] $markers->heredoc; // true $markers->shebang; // "#!/usr/bin/env php" $markers->openingTag; // "<?php" $markers->typicalHeaders; // ["<?php", "<?="] $markers->blockStyle; // BlockStyle::Braces $markers->defaultIndentation; // 4 $markers->indentStyle; // IndentStyle::Spaces
Enums
LanguageType — categorizes languages by purpose:
Programming, Markup, Data, Prose, Query, Stylesheet, Template, Config, Other
BlockStyle — code block delimiters:
Braces, Indentation, BeginEnd, Tags, None
IndentStyle — default indentation:
Spaces, Tabs
Languages
62 languages included:
| Language | Extensions | Type |
|---|---|---|
| Bash | .sh, .bash |
Programming |
| C | .c, .h |
Programming |
| C# | .cs |
Programming |
| C++ | .cpp, .cc, .cxx, .hpp |
Programming |
| Clojure | .clj, .cljs, .cljc |
Programming |
| CMake | .cmake |
Programming |
| CoffeeScript | .coffee |
Programming |
| CSS | .css |
Stylesheet |
| Dart | .dart |
Programming |
| Diff | .diff, .patch |
Data |
| Dockerfile | — | Config |
| Dotenv | — | Config |
| Elixir | .ex, .exs |
Programming |
| Erlang | .erl, .hrl |
Programming |
| F# | .fs, .fsi, .fsx |
Programming |
| Git Attributes | — | Config |
| Git Config | — | Config |
| Go | .go |
Programming |
| GraphQL | .graphql, .gql |
Query |
| Groovy | .groovy, .gvy |
Programming |
| Haskell | .hs, .lhs |
Programming |
| HCL | .hcl, .tf |
Programming |
| htaccess | — | Config |
| HTML | .html, .htm |
Markup |
| HTTP | .http, .rest |
Data |
| Ignore | — | Config |
| INI | .ini, .cfg |
Config |
| Java | .java |
Programming |
| JavaScript | .js, .mjs, .cjs, .jsx |
Programming |
| JSON | .json |
Data |
| Julia | .jl |
Programming |
| Just | — | Config |
| Kotlin | .kt, .kts |
Programming |
| Less | .less |
Stylesheet |
| Lua | .lua |
Programming |
| Makefile | — | Programming |
| Markdown | .md, .markdown |
Prose |
| NEON | .neon |
Config |
| Nix | .nix |
Programming |
| Objective-C | .m, .mm |
Programming |
| OCaml | .ml, .mli |
Programming |
| Perl | .pl, .pm |
Programming |
| PHP | .php, .phtml |
Programming |
| PowerShell | .ps1, .psm1 |
Programming |
| Procfile | — | Config |
| Protocol Buffers | .proto |
Data |
| Python | .py, .pyw |
Programming |
| R | .r, .R |
Programming |
| Ruby | .rb |
Programming |
| Rust | .rs |
Programming |
| Sass | .sass |
Stylesheet |
| Scala | .scala, .sc |
Programming |
| SCSS | .scss |
Stylesheet |
| SQL | .sql |
Query |
| SVG | .svg |
Markup |
| Swift | .swift |
Programming |
| TOML | .toml |
Config |
| Twig | .twig |
Template |
| TypeScript | .ts, .tsx, .mts, .cts |
Programming |
| XML | .xml, .xsl, .xsd |
Markup |
| YAML | .yml, .yaml |
Data |
| Zig | .zig |
Programming |
Languages with filename-based matching (no extension): Dockerfile, Makefile, .gitignore, .env, Procfile,
Justfile, .htaccess, and more.
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
Adding a Language
Create a new file in data/languages/:
<?php // data/languages/mylang.php use Alto\Language\CodeMarkers; use Alto\Language\Language; use Alto\Language\LanguageType; return new Language( name: 'MyLang', slug: 'mylang', type: LanguageType::Programming, extensions: ['.ml'], aliases: ['my'], markers: new CodeMarkers( lineComments: ['//'], blockComments: [['/*', '*/']], ), );
License
Released by the Alto project under the MIT License. See the LICENSE file for details.
alto/language 适用场景与选型建议
alto/language 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「code」 「extensions」 「language」 「programming」 「identification」 「linguist」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alto/language 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alto/language 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alto/language 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use i18n translation PHP class for multi-language websites
A collection of helpers for PHPUnit to ease testing Tarantool libraries.
Package for convenient work with Laravel's localization features
Store your language lines in the database, yaml or other sources
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 37
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-22