|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * User: sy-records |
| 5 | + |
| 6 | + * Usage: php bin/release or php bin/release version |
| 7 | + */ |
| 8 | + |
| 9 | +require_once 'vendor/autoload.php'; |
| 10 | + |
| 11 | +use Qcloud\Cos\Client; |
| 12 | +use Qcloud\Cos\Service; |
| 13 | +use GuzzleHttp\Command\Guzzle\Description; |
| 14 | + |
| 15 | +$class = new ReflectionClass(Client::class); |
| 16 | +$oldDocComment = $class->getDocComment(); |
| 17 | +$clientFile = $class->getFileName(); |
| 18 | +$clientFileContent = file_get_contents($class->getFileName()); |
| 19 | + |
| 20 | +$des = new Description(Service::getService()); |
| 21 | +$operations = array_keys($des->getOperations()); |
| 22 | +$docComment = "/**\n"; |
| 23 | +foreach ($operations as $key => $operation) { |
| 24 | + $type = $arg = ''; |
| 25 | + $model = $des->getOperation($operation)->getResponseModel(); |
| 26 | + if ($des->hasModel($model)) { |
| 27 | + $type = $des->getModel($model)->getType(); |
| 28 | + if (!empty($des->getOperation($operation)->getParams())) { |
| 29 | + $arg = ' (array $arg)'; |
| 30 | + } |
| 31 | + } |
| 32 | + $docComment .= " * @method {$type} {$operation}{$arg}\n"; |
| 33 | +} |
| 34 | +$docComment .= ' */'; |
| 35 | + |
| 36 | +$data = str_replace($oldDocComment, $docComment, $clientFileContent); |
| 37 | +$status = file_put_contents($clientFile, $data); |
| 38 | + |
| 39 | +if ($status) { |
| 40 | + echo 'Regenerate docComment successfully.', PHP_EOL; |
| 41 | +} |
| 42 | + |
| 43 | +if (isset($argv[1])) { |
| 44 | + $version = $argv[1]; |
| 45 | + $versionContent = str_replace(Client::VERSION, $version, $data); |
| 46 | + $status = file_put_contents($clientFile, $versionContent); |
| 47 | + |
| 48 | + if ($status) { |
| 49 | + echo 'Update version successfully.', PHP_EOL; |
| 50 | + } |
| 51 | +} |
0 commit comments