spatie/7to5
最新稳定版本:1.3.0
Composer 安装命令:
composer require spatie/7to5
包简介
Convert PHP 7 code to PHP 5 code
README 文档
README
This package has been abandoned
We are not maintaining this package any more. Feel free to fork our code and maintain your own copy.
Convert PHP 7.0 code to PHP 5 code
This package can convert PHP 7.0 code to PHP 5. This can be handy when you are running PHP 7 in development, but PHP 5 in production.
You can convert an entire directory with PHP 7.0 code with a the console command:
php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code}
Here's an example of what it can do. It'll convert this code with PHP 7 features:
class Test { public function test() { $class = new class() { public function method(string $parameter = '') : string { return $parameter ?? 'no parameter set'; } }; $class->method(); $anotherClass = new class() { public function anotherMethod(int $integer) : int { return $integer > 3; } }; } }
to this equivalent PHP 5 code:
class AnonymousClass0 { public function method($parameter = '') { return isset($parameter) ? $parameter : 'no parameter set'; } } class AnonymousClass1 { public function anotherMethod($integer) { return $integer < 3 ? -1 : ($integer == 3 ? 0 : 1); } } class Test { public function test() { $class = new AnonymousClass0(); $class->method(); $anotherClass = new AnonymousClass1(); } }
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Installation
If you plan on use the console command we recommend installing the package globally:
$ composer global require spatie/7to5
If you want to integrate the package in your own code require the package like usual:
$ composer require spatie/7to5
The conversion process
This package converts PHP 7 code to equivalent PHP 5 code by:
- removing scalar type hints
- removing return type hints
- removing the strict type declaration
- replacing the spaceship operator by an equivalent PHP 5 code
- replacing null coalesce statements by equivalent PHP 5 code
- replacing group use declarations by equivalent PHP 5 code
- replacing defined arrays by equivalent PHP 5 code
- converting anonymous classes to regular classes
Because there are a lot of things that cannot be detected and/or converted properly we do not guarantee that the converted code will work. We highly recommend running your automated tests against the converted code to determine if it works.
Using the console command
This package provides a console command php7to5 to convert files and directories.
This is how a entire directory can be converted:
$ php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code}
Want to convert a single file? That's cool too! You can use the same command.
$ php7to5 convert {$sourceFileWithPHP7Code} {$destinationFileWithPHP5Code}
By default the command will only copy over php-files. Want to copy over all files? Use the copy-all option:
$ php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code} --copy-all
By default the command will only convert files with a php extension, but you can customize that by using the --extension option.
$ php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code} --extension=php --extension=phtml
If necessary, you can exclude directories / files.
$ php7to5 convert {$directoryWithPHP7Code} {$destinationWithPHP5Code} --exсlude=cache
Programmatically convert files
You can convert a single file by running this code:
$converter = new Converter($pathToPhp7Code); $converter->saveAsPhp5($pathToWherePhp5CodeShouldBeSaved);
An entire directory can be converted as well:
$converter = new DirectoryConverter($sourceDirectory); $converter->savePhp5FilesTo($destinationDirectory);
By default this will recursively copy all to files to the destination directory, even the non php files.
If you only want to copy over the php files do this:
$converter = new DirectoryConverter($sourceDirectory); $converter ->doNotCopyNonPhpFiles() ->savePhp5FilesTo($destinationDirectory);
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
We publish all received postcards on our company website.
Credits
Original idea: Jens Segers
Support us
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
License
The MIT License (MIT). Please see License File for more information.
spatie/7to5 适用场景与选型建议
spatie/7to5 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.65k 次下载、GitHub Stars 达 174, 最近一次更新时间为 2016 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「tree」 「convert」 「syntax」 「abstract」 「PHP7」 「spatie」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spatie/7to5 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spatie/7to5 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spatie/7to5 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides a simple decimal/roman number converter
A library that provides a simple infrastructure to create your own converters and to perform any conversion you want
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
jsTree widget for yii2
Doctrine2 behavior traits - slowhop fork
Convert xml to array
统计信息
- 总下载量: 25.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 175
- 点击次数: 18
- 依赖项目数: 4
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-19