forikal-uk/xml-authoring-library

该软件包已被废弃且不再维护。作者建议使用https://github.com/xmlsquad/xml-authoring-library软件包。

存储被xmlsquad xml authoring suite项目多个组件重用的代码。

v0.3.3 2018-10-14 09:39 UTC

This package is not auto-updated.

Last update: 2019-02-20 19:23:32 UTC


README

这是一个放置被xml-authoring-tools套件中的多个命令重用代码的地方。

作为一个放置xmlsquad xml-authoring套件中两个或更多项目重用代码的地方。

查看触发此项目创建的问题

通用文档

帮助页面的库。即与该套件中的多个项目相关的信息。

此项目可以通过composer添加到您的项目中

$ composer require xmlsquad/xml-authoring-library --prefer-source

如果您想同时开发和维护库以及使用它的命令。我相信composer允许您以源代码形式获取库。

查看: composer require

引用

选项:--prefer-source:当可用时从源代码安装软件包。

并查看Composer Repositories > Packages

引用

源代码:源代码用于开发。这通常来自源代码仓库,如git。当您想修改已下载的软件包时,可以获取此内容。

代码引用

Google API助手

Google API SDK的抽象。它帮助在测试中模拟Google API并在控制台命令中验证用户。

您需要将Google SDK安装到项目中才能使用此助手

composer require google/apiclient:^2.0

使用示例

use XmlSquad\Library\GoogleAPI\GoogleAPIClient;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MyCommand extends Command
{
    execute(InputInterface $input, OutputInterface $output)
    {
        $googleClient = new GoogleAPIClient(); // You can pass a \Google_Client mock to the constructor. It will be used in the Google services.
        
        if (!$googleClient->authenticateFromCommand(
            $input,
            $output
            'google-client-secret.json', // A path to a Google API client secret file
            'google-access-token.json', // A path to a file where to store a Google API access token so the helper won't prompt to authenticate next time
            [\Google_Service_Drive::DRIVE_READONLY, \Google_Service_Sheets::SPREADSHEETS_READONLY] // A list of required permissions
        )) {
            return 1;
        }
        
        // $googleAPIClient->driveService is a \Google_Service_Drive instance. All the other services are available.
        $file = $googleAPIClient->driveService->files->get('87ad6fg90gr0m91c84');
        
        return 0;
    }
}

您可以从这里了解如何获取Google API客户端密钥文件。如果您需要自定义控制台消息和行为,请使用authenticate方法。更多信息可以在源代码中找到。

控制台记录器

一个兼容PSR-3的记录器,它将消息写入Symfony控制台输出。与内置的Synfony Console记录器相比,这个不会打印日志级别标签,并且是可定制的(我们可以编辑源代码)。

使用示例

use XmlSquad\Library\Console\ConsoleLogger;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Psr\Log\LogLevel;

// ...

protected function execute(InputInterface $input, OutputInterface $output)
{
    $consoleLogger = new ConsoleLogger($output, [
        LogLevel::DEBUG  => OutputInterface::VERBOSITY_VERY_VERBOSE,
        LogLevel::INFO   => OutputInterface::VERBOSITY_VERBOSE,
        LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL
    ], [
        LogLevel::DEBUG  => '',
        LogLevel::INFO   => '',
        LogLevel::NOTICE => 'info'
    ]);
    
    $service = new MyService($consoleLogger);
}

构造函数参数与Synfony Console记录器相同。

贡献

  1. 克隆仓库。
  2. 通过在控制台运行 composer install 来安装依赖项。
  3. 进行更改。确保代码遵循 PSR-2 编码风格指南
  4. 通过运行 composer test 测试代码。如果测试失败,请修复代码。
  5. 提交并推送更改。