empaphy/composer-yaml 问题修复 & 功能扩展

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

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

empaphy/composer-yaml

最新稳定版本:v1.1.1

Composer 安装命令:

composer require empaphy/composer-yaml

包简介

composer.yaml support for Composer

README 文档

README

This Composer plugin will make your composer project use composer.yaml as it's Composer config instead of composer.json. It does so fully transparently without the need to run additional commands.

composer.json is still required, (to bootstrap this plugin, among other things) however it is now generated automatically when a change in composer.yaml is detected. Think of this similarly to how composer.lock is generated.

Installation

composer require "empaphy/composer-yaml:^1.0"

Usage

Just use composer as you usually would! The first time you run any Composer CLI command after installing this plugin, it will generate a composer.yaml based on your existing composer.json.

Just remember to modify composer.yaml from now on, and to not modify composer.json, since any changes in that file will be overridden.

Why YAML? What's wrong with JSON?

JSON was never designed to be a human-readable format. It's intended use is for computers to exchange information with one another. Hence, it misses essential features which one would need from a file that is manipulated by humans, like comments.

YAML allows for comments and a lot more, making expressive Composer configuration possible.

  • Comments allow you to clarify your configuration.
  • Quotes are not required, which makes the file much more readable.
  • No trailing commas are required, which reduces the risk of syntax errors.
  • Support for multiline strings allows you to split string over multiple rows. YAML allows you to fold or retain newlines in multiline strings.
  • YAML anchors let you reference and use the same data multiple times.

YAML vs JSON

For example, if you take a typical composer.json like this:

{
    "name":              "empaphy/foo",
    "description":       "Foo library for PHP",
    "license":           "MIT",
    "minimum-stability": "stable",
    "prefer-stable":     true,

    "require": {
        "php": ">=7.4",

        "symfony/config":         "~5.4.0",
        "symfony/console":        "~5.4.0",
        "symfony/filesystem":     "~5.4.0",
        "symfony/process":        "~5.4.0",
        "symfony/yaml":           "~5.4.0",

        "yogarine/composer-yaml": "~5.4.0"
    },

    "require-dev": {
        "phpunit/phpunit": "^9.0",
        "phploc/phploc":   "^7.0",
        "phpstan/phpstan": "^1.0"
    },

    "autoload": {
        "psr-4": { "Empaphy\\Foo\\": "src/" }
    },
    
    "config": {
        "platform": {
            "php": "8.0.20"
        }
    },

    "scripts": {
        "pre-install-cmd": [
            "if [ -d .git -o -f .git -a -d ../.git ]; then git submodule update; fi"
        ]
    }
}

You can turn it into something like this:

##
# Example Composer configuration for the Foo package.
#
# Use composer to install dependencies for this package:
#
#     composer install --no-dev --optimize-autoloader
#

name:        empaphy/foo            # The name of the package.
description: Foo library for PHP    # A short description of the package.
license:     MIT                    # The license of the package.

# This defines the default behavior for filtering packages by stability.
minimum-stability: stable

# Prefer more stable packages over unstable ones when finding compatible stable
# packages is possible.
#
# If you require a dev version or only alphas are available for a package, those
# will still be selected granted that the minimum-stability allows for it.
prefer-stable: true

# Map of packages required by this package.
#
# The package will not be installed unless those requirements can be met.
require:
    php: '>=7.4'  # We depend on property types. 

    # Symfony dependencies:
    symfony/config:     &symfony-version '~5.4.0'
    symfony/console:    *symfony-version
    symfony/filesystem: *symfony-version
    symfony/process:    *symfony-version
    symfony/yaml:       *symfony-version

    yogarine/composer-yaml: 'dev-main'  # Adds support for this file. :-)

require-dev:
    phpunit/phpunit: '^9.0'
    phploc/phploc:   '^7.0'
    phpstan/phpstan: '^1.0'

autoload:
    psr-4: [ Empaphy\Foo: src/ ]
    
config:
    platform:
        php: '8.0.20'  # We currently run 8.0.20 on all our production servers,
                       # so ensure we're forward-compatible with PHP 8.
    allow-plugins:
        yogarine/composer-yaml: true  # Required to for composer.yaml support.

scripts:
    # Occurs before the `install` command is executed with a lock file present.
    pre-install-cmd:
      - |  # Ensure submodules are updated.
        if [ -d .git -o -f .git -a -d ../.git ]; then
          git submodule update
        fi

Known Issues / Roadmap

  • Using Composer CLI commands that would previously modify the composer.json will still work and properly modify the composer.yaml, but they will remove any custom formatting changes and comments you have made to your composer.yaml file.

    I plan to fix this in a future version, but it involves writing a custom YAML Manipulator, so it might take a while. For now, just refrain from using the CLI commands to modify the composer config. I mean, why even would you, when you can now use fancy YAML markup to pimp up your composer.yaml? ;-)

  • Handle first-time install of a composer.yaml project properly. Especially in the edge case where composer.yaml was modified, but composer-yaml has not yet been installed.

  • Warn about changes made to composer.json

  • Add config option to choose default behaviours, for example for overwriting an existing YAML file.

统计信息

  • 总下载量: 95
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固