fostam/pharizer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fostam/pharizer

Composer 安装命令:

composer require fostam/pharizer

包简介

Create phar files / executables from a PHP project file structure

README 文档

README

Create phar files / executables from a PHP project file structure.

Features

  • Easy to integrate into build chains
  • Supports multiple phar files per project
  • Extended file filter capabilities

Install

The easiest way to install pharizer is by using composer:

$> composer require fostam/pharizer

After installation, it can be called from the following location:

$> vendor/bin/pharizer

Configuration file

The configuration file specifies the PHARs that should be built and uses the YAML format. Usually, it resides at the top level of your project file structure. The default name is pharizer.yaml.

Example pharizer.yaml:

target-directory: dist
targets:
  myphar:
    source-directory: .
    stub-file: src/myphar.php
    filters:
      - include: ^(src|vendor)/
      - exclude: .*
 
  another.phar:
    source-directory: .
    stub-file: src/another.php
    filters:
      - include: ^(src|vendor)/
      - exclude: .*

Main Keys:

  • target-directory (optional): If all targets should be placed under a common directory, e.g. dist, it can be specified here. Defaults to the current directory (.).
  • targets: A list of targets. A target name can have (but does not need) the .phar extension. It can contain a path, too. Examples: dist/myphar.phar, myphar).

Target Keys:

  • source-directory (optional): The base directory used for collecting files. Defaults to the current directory (.).
  • stub-file: The "entry point" file that is invoked when the phar is executed or included. The location must be relative to the source-directory.
  • filters: Filter patterns can be used to control which files are included in the PHAR and which not. See "Filters" for more details.
  • shebang (optional): The shebang line used for the stub file. Defaults to #!/usr/bin/env php.
  • exclude-pharizer (optional): If set to true, automatically excludes all pharizer files (if pharizer has been installed with composer for the current project). Defaults to true.

Commands

Build

With the build command, all targets from the pharizer.yaml are built:

$> pharizer build

To build a single target, append the target name as defined in the pharizer.yaml:

$> pharizer build myphar.phar

List Files

Similarly to the build command, the list-files command either processes all or a specific target from the configuration file. The command lists all files that match the filters for a target and can be used to test and try out the filters.

Filters

Definition

Filters are defined as a list of include and exclude regular expression (PCRE) patterns. By default, the regular expressions are not anchored, i.e. if you want them to be anchored to the beginning or end of a file path, you have to use ^ or $.

Delimiter escaping is handled internally, so it is not necessary to escape the slash character (/).

Patterns are matched against the full file path of each file under source-directory. The source path itself (including the slash in the beginning) is truncated.

Example: The file /my/app/src/file.php in the source directory /my/app will become src/file.php when applying filter patterns.

Processing

For each file in the source-directory, the patterns are processed in the order in which they have been given in the target filter list. The first pattern that matches determines whether the file is included or excluded. If no pattern matches, the file is included by default. If you want to change the default behaviour to exclude, simply add exclude: ".*" as last filter.

Caveats

YAML Escaping

YAML does not allow characters like *, so when giving a pattern containing an asterisk, put it in single quotes. Avoid double quotes, as they don't work well with backslash escapes.

- exclude: '.*\.php'

Anchors

Try to anchor patterns either with ^ and $ or / to avoid unintended matching.

Example:

lib/file.php
lib/file2.php
other/glibc.c

The pattern include: src would not only match the files in the src directory, but also the "src" part of glibc.c. This can be avoided by anchoring the pattern, e.g. include: ^src/.

Options

Configuration File

By default, pharizer.yaml in the current directory is used as configuration file. With the -c option, an alternative configuration file can be specified:

$> pharizer build -c ../myphar.yaml

Verbosity

For each successfully built target, pharizer will print the name and size of the target PHAR file. To turn this off, use the -q (quiet) option.

Return Codes

If no errors occurred, pharizer exits with a return code of 0, otherwise with a return code > 0.

fostam/pharizer 适用场景与选型建议

fostam/pharizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「console」 「binary」 「phar」 「archive」 「script」 「executable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fostam/pharizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fostam/pharizer 我们能提供哪些服务?
定制开发 / 二次开发

基于 fostam/pharizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 60
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-07-03