xp-framework/compiler
Composer 安装命令:
composer require xp-framework/compiler
包简介
XP Compiler
README 文档
README
Compiles future PHP to today's PHP.
Usage
After adding the compiler to your project via composer require xp-framework/compiler, it will hook into the class loading chain and compile .php-files on-demand. This keeps the efficient code-save-reload/rerun development process typical for PHP.
Example
The following code uses Hack language, PHP 8.6, PHP 8.5, PHP 8.4, PHP 8.3, PHP 8.2, 8.1 and 8.0 features but runs on anything >= PHP 7.4. Builtin features from newer PHP versions are translated to work with the currently executing runtime if necessary.
<?php // In a file "HelloWorld.php" use lang\Reflection; use util\Date; use util\cmd\Console; #[Author('Timm Friebe')] #[Permissions(0o777)] class HelloWorld { private const string GREETING= 'Hello'; public static function main(array<string> $args): void { $greet= fn($to, $from) => self::GREETING.' '.$to.' from '.$from; $author= Reflection::type(self::class)->annotation(Author::class)->argument(0); Console::writeLine(new Date()->toString(), ': '); $greet($args[0] ?? 'World', from: $author) |> Console::writeLine(?); } }
To run this code, use xp -m /path/to/xp/reflection HelloWorld in a terminal window.
Compilation
Compilation can also be performed explicitely by invoking the compiler:
# Compile code and write result to a class file $ xp compile HelloWorld.php HelloWorld.class.php # Compile standard input and write to standard output. $ echo "<?php ..." | xp compile - # Compile src/main/php and src/test/php to the dist folder. $ xp compile -o dist src/main/php/ src/test/php/ # Compile src/main/php to the dist.xar archive $ xp compile -o dist.xar src/main/php/ # Compile src/main/php, do not write output $ xp compile -n src/main/php/ # Target PHP 7.4 (default target is current PHP version) $ xp compile -t php:7.4 HelloWorld.php HelloWorld.class.php # Emit XP meta information (includes lang.ast.emit.php.XpMeta): $ xp compile -t php:7.4 -a php:xp-meta -o dist src/main/php
The -o and -n options accept multiple input sources following them. The -q option suppresses all diagnostic output except for errors.
Features supported
XP Compiler supports features such as annotations, arrow functions, enums, property type-hints, the null-safe instance operator as well as all PHP 7 and PHP 8 syntax additions. A complete list including examples can be found in our Wiki.
More features
Additional syntax like an is operator, generics or record types can be added by installing compiler plugins from here:
$ composer require xp-lang/php-is-operator # ... $ xp compile Usage: xp compile <in> [<out>] @FileSystemCL<./vendor/xp-framework/compiler/src/main/php> lang.ast.emit.PHP74 lang.ast.emit.PHP80 lang.ast.emit.PHP81 lang.ast.emit.PHP82 lang.ast.emit.PHP83 [*] lang.ast.emit.PHP84 lang.ast.emit.PHP85 lang.ast.syntax.php.Using [*] @FileSystemCL<./vendor/xp-lang/php-is-operator/src/main/php> lang.ast.syntax.php.IsOperator
Implementation status
Some features from newer PHP versions as well as Hack language are still missing. The goal, however, is to have all features implemented - with the exception of where Hack's direction conflicts with PHP! An overview can be seen on this Wiki page.
To contribute, open issues and/or pull requests.
See also
xp-framework/compiler 适用场景与选型建议
xp-framework/compiler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26.82k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2017 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「module」 「xp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xp-framework/compiler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xp-framework/compiler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xp-framework/compiler 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
bootstrap select field module implementing http://silviomoreto.github.io/bootstrap-select/
Yii2 module to manage website content. Kind of a CMS...
Codeurx Modular is simply a package for Laravel to help you create and manage modules.
User Module for the Attogram Framework
Info Module for the Attogram Framework
Contact Form Module for the Attogram Framework
统计信息
- 总下载量: 26.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 14
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-10-14

