定制 xp-framework/command 二次开发

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

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

xp-framework/command

最新稳定版本:v12.0.1

Composer 安装命令:

composer require xp-framework/command

包简介

XPCLI

关键字:

README 文档

README

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version

Also known as "xpcli": Command line argument parsing via annotations.

Example

use util\cmd\{Command, Arg}; use rdbms\DriverManager; use io\streams\Streams; /** Performs an SQL query */ class Query extends Command { private $connection, $query; private $verbose= false; /** Connection DSN, e.g. `mysql://user:pass@host[:port][/database]` */ #[Arg(position: 0)] public function useConnection(string $dsn) { $this->connection= DriverManager::getConnection($dsn); $this->connection->connect(); } /** SQL query. Use `-` to read from standard input */ #[Arg(position: 1)] public function useQuery(string $query) { if ('-' === $query) { $this->query= Streams::readAll($this->in->stream()); } else { $this->query= $query; } } /** Verbose output */ #[Arg] public function useVerbose() { $this->verbose= true; } /** @return int */ public function run() { $this->verbose && $this->out->writeLine('@ ', $this->connection); $this->verbose && $this->out->writeLine('>>> ', $this->query); $result= $this->connection->open($this->query); if ($result->isSuccess()) { $this->verbose && $this->out->writeLine('<<< ', $result->affected()); return $result->affected() ? 0 : 1; } else { $this->verbose && $this->out->writeLine('<<< Results'); foreach ($result as $found => $record) { $this->out->writeLine($record); } return isset($found) ? 0 : 2; } } }

To execute the class, use the cmd command:

$ xp -m /path/to/rdbms cmd Query 'mysql://localhost/test' 'select * from account' -v @ rdbms.mysqlx.MySqlxConnection(->rdbms.DSN@(mysql://localhost/test), rdbms.mysqlx.MySqlxProtocol(...) >>> select * from account <<< Results [ account_id => 1 username => "kiesel" email => "alex.dandrea@example.com" ] [ account_id => 2 username => "thekid" email => "timm.friebe@example.com" ]

To show the command's usage, supply -? or --help:

query-class-usage

See also

  • RFC #0133 - Add support for filenames as argument for XPCLI
  • RFC #0102 - XP Class Runners (original RFC)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固