sniccowp / php-scoper-excludes
dev-master
2022-02-09 15:04 UTC
Requires
- php: ^7.4
- ext-json: *
- nikic/php-parser: ^4.0.0
- symfony/console: ^5.0
Requires (Dev)
- php-stubs/wordpress-globals: 0.2.0
- php-stubs/wordpress-stubs: ^5.9
- phpunit/phpunit: ^9.5
- symfony/finder: ^5.4
This package is auto-updated.
Last update: 2024-09-13 17:10:18 UTC
README
将任何PHP文件输入,得到包含完全命名空间
- 类名
- 接口名
- 特质名
- 函数名
- 常量名
示例
假设你有一个以下占位符文件
namespace WP_CLI { trait FooTrait { } class Autoloader { public function foo() { } } function foo_func() { } define('FOO', 'BAR'); const BAZ = 'BIZ'; } namespace WP_CLI\Utils { function wp_not_installed() { } const BAM = 'boom'; } namespace WP_CLI\Bootstrap { interface BootstrapInterface { } trait BarTrait { } abstract class AutoloaderStep { } }
生成的排除列表将是
// exclude-wp-cli-classes.php <?php return array ( 0 => 'WP_CLI\\Autoloader', 1 => 'WP_CLI\\Bootstrap\\AutoloaderStep', );
// exclude-wp-cli-functions.php <?php return array ( 0 => 'WP_CLI\\foo_func', 1 => 'WP_CLI\\Utils\\wp_not_installed', );
// exclude-wp-cli-constants.php <?php return array ( 0 => 'FOO', 1 => 'WP_CLI\\BAZ', 2 => 'WP_CLI\\Utils\\BAM', );
// exclude-wp-cli-interfaces.php <?php return array ( 0 => 'WP_CLI\\Bootstrap\\BootstrapInterface', );
// exclude-wp-cli-interfaces.php <?php return array ( 0 => 'WP_CLI\\FooTrait', 1 => 'WP_CLI\\Bootstrap\\BarTrait', );
生成必要的文件后,您可以将它们与php-scopers的排除符号功能结合使用。
我们已经为WordPress、WP-CLI和WooCommerce生成了排除列表。您可以在以下位置找到它们
- sniccowp/php-scoper-wordpress-excludes
- sniccowp/php-scoper-wp-cli-excludes
- sniccowp/php-scoper-woocommerce-excludes
这些是使用以下发布的占位符自动生成的: https://github.com/php-stubs
然而,使用占位符文件不是必需的。任何PHP代码都可以工作。
使用
安装
composer/require sniccowp/php-scoper-excludes --dev
创建配置
在当前工作目录中生成配置文件
vendor/bin/generate-excludes generate-config
// generate-excludes.inc.php return [ Option::EMULATE_PHP_VERSION => Option::PHP_8_0, Option::OUTPUT_DIR => __DIR__.'/excludes', Option::FILES => [ Finder::create()->files() ->in(__DIR__.'/vendor/php-stubs') ->depth('< 3') ->name('*.php'), __DIR__.'/foo.php', [__DIR__.'/bar.php', __DIR__.'/baz.php'] ], ];
使用symfony/finder
是完全可选的。您也可以提供字符串列表或任何可迭代对象。
生成排除列表
vendor/bin/generate-excludes
致谢
如果没有Nikita Popov的出色解析器(nikic/php-parser),这一切都不可能实现。