定制 oscarnevarezleal/laravel-sed 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

oscarnevarezleal/laravel-sed

Composer 安装命令:

composer require oscarnevarezleal/laravel-sed

包简介

Larased CLI

README 文档

README

A CLI utility that modifies Laravel configuration files.

Note: This project is primarily intended as CLI tool to manage laravel applications from the outside, although it contains several laravel commands expect that the majority of features will be unavailable as Laravel commands.

Installation

composer global require oscarnevarezleal/laravel-sed

Usage

Larased 0.0.4

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help                  Displays help for a command
  list                  Lists commands
 larased
  larased:config-edit   Edits a config file

Commands

Command Description Arguments
larased:config-edit Replace configuration value $config-path $value [options]

Options

Short version Long version Comments
-d --basePath The working directory
-e --envor When this option is specified, the substitution will have a call to the env function using as 1st argument the value taken from the environment key specified and secondly a literal value or another env call when using chained envs (See Environment chain in the examples section )

Concepts

Before dive in into the examples, a previous step is to clarify what a config path is so you know how to use it when editing Laravel configuration files.

Config Paths

Most of the commands expect a valid config-path to work with.

Config paths consists of two parts joined by a slash.

The first part is the relative path of the file to be modified seen from the root of the project and, without especial characters nor file extensions.

The second part is the array property path found in the file.

Example

A property name in ./config/app.php became the config path config.app/name

A nested property such as the user in a mysql connection configured in ./config/database.php became the config.database/connections.mysql.user

Examples

Literal values

Take the following part of the configuration file config/app.php for instance.

# config/app.php
<?php

return [
    'name' => 'App',
    /*
    |--------------------------------------------------------------------------
    | Application Debug Mode
    |--------------------------------------------------------------------------
    |
    | When your application is in debug mode, detailed error messages with
    | stack traces will be shown on every error that occurs within your
    | application. If disabled, a simple generic error page is shown.
    |
    */
    'debug' => (bool) env('APP_DEBUG', false),
    /*
    |--------------------------------------------------------------------------
    | Application URL
    |--------------------------------------------------------------------------
    |
    | This URL is used by the console to properly generate URLs when using
    | the Artisan command line tool. You should set this to the root of
    | your application so that it is used when running Artisan tasks.
    |
    */
    'url' => env('APP_URL', 'http://localhost'),
    'asset_url' => env('ASSET_URL', null)
    
    #....
];

If you'd like to change a literal value, e.g., name to MyAwesomeApp you run the following command:

larased larased:config-edit config.app/name my-awesome-app  

It will result in:

<?php

return [
    'name' => 'my-awesome-app',

What about environment values check with a default value? In that case we need to use the -e flag like this:

larased larased:config-edit config.app/name -e APP_NAME my-awesome-app  

It will result in:

<?php

return [
    'name' => env('APP_NAME', 'MyAwesomeApp'),

Nested properties

Some other properties are not very at hand but nested under an array path. Take the username of a mysql connection for instance.

larased larased:config-edit config.database/connections.mysql.username noroot

It will result on a successful update as shown below.

# ...
	'connections' => [
		'sqlite' => [
			'driver' => 'sqlite',
			'url' => env('DATABASE_URL'),
			'database' => env('DB_DATABASE', database_path('database.sqlite')),
			'prefix' => '',
			'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
		],
		'mysql' => [
			'driver' => 'mysql',
			'url' => env('DATABASE_URL'),
			'host' => env('DB_HOST', '127.0.0.1'),
			'port' => env('DB_PORT', '3306'),
			'database' => env('DB_DATABASE', 'forge'),
			'username' => 'no-root',

# ...

Environment chain with default

Sometimes there's no one but multiple environment variables you'd like to use before the default. In that case the flag -e has a convenient variant that we can use. A list of environment variables names can be separated by a pipe |.

larased larased:config-edit config.database/connections.mysql.username noroot -e "DB_USER|DB_USER_ENV"

Docker

# Pull latest
docker pull docker pull docker.pkg.github.com/oscarnevarezleal/laravel-sed/laravel-sed:dev

# create an alias
alias larased='docker run --rm -it -v `pwd`:/var/laraseed:ro laravel-sed:latest'
#windows
docker run --rm -it -v ${PWD}:/var/laraseed:ro laravel-sed:latest config.app/name my-awesome-app 

#linux and MacOS
docker run --rm -it -v `pwd`:/var/laraseed:ro laravel-sed:latest config.app/name my-awesome-app   

Known Drawbacks

How to Apply Coding Standards?

This package uses nikic/php-parser, built on technology called an abstract syntax tree (AST). An AST doesn't know about spaces and when written to a file it produces poorly formatted code in both PHP and docblock annotations. That's why your project needs to have a coding standard tool such as ECS.

oscarnevarezleal/laravel-sed 适用场景与选型建议

oscarnevarezleal/laravel-sed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.36k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 08 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 oscarnevarezleal/laravel-sed 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

与 oscarnevarezleal/laravel-sed 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-20