00f100/fcphp-command

此包最新版本(0.1.0)没有可用的许可信息。

库,用于将控制台命令操作成FcPhp

安装: 45

依赖: 0

建议者: 0

安全: 0

星星: 1

观察者: 1

分支: 1

开放问题: 0

类型:package

0.1.0 2018-08-12 21:08 UTC

This package is auto-updated.

Last update: 2024-09-18 06:09:33 UTC


README

将终端命令操作成FcPhp的包

Build Status codecov

PHP Version Packagist Version Total Downloads

如何安装

Composer

$ composer require 00f100/fcphp-command

或添加到composer.json中

{
    "require": {
        "00f100/fcphp-command": "*"
    }
}

如何使用

此包使用FcPhp 安全控制台来操作权限,并使用FcPhp 缓存来保存命令缓存以提高性能

use FcPhp\SConsole\SCEntity;
use FcPhp\Command\Interfaces\ICEntity;
use FcPhp\Command\Facades\CommandFacade;


// Instance of SCEntity provider from FcPhp Security Console
// or ...
$entity = new SCEntity();

// Custom commands...
$commands = [];

// Composer dir to autoload find "commands.php" into packages and cache into FcPhp Cache
$vendorPathAutoload = 'vendor/*/*/config';

$instance = CommandFacade::getInstance($entity, $commands, $vendorPathAutoload);

// Args from console request
// Example: php index.php package datasource connect -h localhost -u user -p password
$args = [
    'package',
    'datasource',
    'connect',
    '-h',
    'localhost',
    '-u',
    'user',
    '-p',
    'password'
];

// Return instance FcPhp\Command\Interfaces\ICEntity
$match = $this->instance->match($args);

if($match instanceof ICEntity) {
    // Print status code
    echo $match->getStatusCode();

    // Print action
    echo $match->getAction();

    // ...
}

FcPhp\Command\Interfaces\ICEntity

<?php

namespace FcPhp\Command\Interfaces
{
    interface ICEntity
    {
        /**
         * Method to contruct instance
         *
         * @param array $params Params to entity
         * @return void
         */
        public function __construct(array $params = []);

        /**
         * Method to get command
         *
         * @return string|null
         */
        public function getCommand();

        /**
         * Method to get action
         *
         * @return string|null
         */
        public function getAction();

        /**
         * Method to get rule
         *
         * @return string|null
         */
        public function getRule();

        /**
         * Method to get params to controller
         *
         * @return array
         */
        public function getParams() :array;

        /**
         * Method to get status code
         *
         * @return int
         */
        public function getStatusCode() :int;

        /**
         * Method to get status message
         *
         * @return string|null
         */
        public function getStatusMessage();
    }
}