xmlsquad / xml-authoring-library
包含被xmlsquad xml authoring suite项目中多个组件重用的代码。
v0.3.3
2018-10-14 09:39 UTC
Requires
- php: >=7.1
- psr/log: ^1.0
- symfony/console: ^3.4
- symfony/filesystem: ^3.4
- symfony/yaml: ^3.4
Requires (Dev)
- google/apiclient: ^2.0
- phpunit/phpunit: ^7.1
Suggests
- google/apiclient: To use the Google API helper (version ^2.0 is required)
- xmlsquad/xmlauthor-example-command: To see example how to use AbstractCommand
README
这是一个放置被许多命令(这些命令是xml-authoring-tools套件的一部分)重用的代码的地方。
作为一个地方来放置被xmlsquad xml-authoring suite中两个或多个项目重用的代码。
查看触发此项目创建的相关问题。
常见文档
帮助页面库。即与套件中多个项目相关的信息。
可以通过composer将此项目添加到您的项目中
$ composer require xmlsquad/xml-authoring-library --prefer-source
如果您想同时开发和,比如一个与之协同使用的命令。我相信composer允许您以源的方式获取库
引用
选项:--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日志记录器相同。
贡献
- 克隆存储库。
- 在控制台中运行
composer install
以安装依赖项。 - 进行更改。确保代码遵循PSR-2标准。
- 通过运行
composer test
测试代码。如果测试失败,修复代码。 - 提交并推送更改。