first commit
This commit is contained in:
107
pgserver/third_party/cos/bin/format
vendored
Normal file
107
pgserver/third_party/cos/bin/format
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* User: sy-records
|
||||
* Email: lufei@php.net
|
||||
* Usage: php bin/format
|
||||
*/
|
||||
|
||||
$directories = ['src', 'tests', 'sample'];
|
||||
$rootDirectoryPath = realpath(dirname(__DIR__));
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
$directoryPath = $rootDirectoryPath . '/' . $directory;
|
||||
|
||||
$directoryIterator = new RecursiveDirectoryIterator($directoryPath, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$iterator = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
$phpFiles = findPhpFiles($iterator);
|
||||
|
||||
foreach ($phpFiles as $file) {
|
||||
$formattedContent = formatFile($file);
|
||||
writeToFile($file, $formattedContent, $directory);
|
||||
}
|
||||
}
|
||||
|
||||
echo 'Formatting completed', PHP_EOL;
|
||||
|
||||
/**
|
||||
* Returns an array of PHP file paths from the directory iterator.
|
||||
*
|
||||
* @param RecursiveIteratorIterator $iterator The iterator of the directory to search through.
|
||||
* @return array An array of PHP file paths.
|
||||
*/
|
||||
function findPhpFiles($iterator)
|
||||
{
|
||||
$phpFiles = [];
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->getExtension() !== 'php' || $file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$phpFiles[] = $file->getPathname();
|
||||
}
|
||||
return $phpFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted content of a file.
|
||||
*
|
||||
* @param string $file The path to the file to format.
|
||||
* @return string The formatted content.
|
||||
*/
|
||||
function formatFile($file)
|
||||
{
|
||||
$content = file_get_contents($file);
|
||||
return formatLineEndings($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content with formatted line endings.
|
||||
*
|
||||
* @param string $content The content to format.
|
||||
* @return string The content with formatted line endings.
|
||||
*/
|
||||
function formatLineEndings($content)
|
||||
{
|
||||
return trim($content) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content with all occurrences of 'schema' replaced with 'scheme'.
|
||||
*
|
||||
* @param string $content The content to perform replacements on.
|
||||
* @return string The content with all occurrences of 'schema' replaced with 'scheme'.
|
||||
*/
|
||||
function replaceSchemaWithScheme($content)
|
||||
{
|
||||
return str_replace(['schema', 'Schema'], ['scheme', 'Scheme'], $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the provided content to a file if it differs from the original content of the file.
|
||||
* Also checks the directory and if it's not 'src', replaces 'schema' with 'scheme' in the content.
|
||||
*
|
||||
* @param string $file The path to the file to write.
|
||||
* @param string $content The content to write to the file.
|
||||
* @param string $directory The directory the file resides in.
|
||||
*/
|
||||
function writeToFile($file, $content, $directory)
|
||||
{
|
||||
$originalContent = file_get_contents($file);
|
||||
$changed = false;
|
||||
if ($originalContent !== $content) {
|
||||
echo "Formatted empty lines in {$file}", PHP_EOL;
|
||||
$changed = true;
|
||||
}
|
||||
if ($directory != 'src') {
|
||||
$_content = replaceSchemaWithScheme($content);
|
||||
if ($content !== $_content) {
|
||||
echo "Use scheme instead of schema in {$file}", PHP_EOL;
|
||||
$content = $_content;
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
if ($changed) {
|
||||
file_put_contents($file, $content);
|
||||
}
|
||||
}
|
||||
85
pgserver/third_party/cos/bin/release
vendored
Normal file
85
pgserver/third_party/cos/bin/release
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* User: sy-records
|
||||
* Email: lufei@php.net
|
||||
* Usage: php bin/release or php bin/release version
|
||||
*/
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use Qcloud\Cos\Client;
|
||||
use Qcloud\Cos\Service;
|
||||
use GuzzleHttp\Command\Guzzle\Description;
|
||||
|
||||
$class = new ReflectionClass(Client::class);
|
||||
$oldDocComment = $class->getDocComment();
|
||||
$clientFile = $class->getFileName();
|
||||
$clientFileContent = file_get_contents($class->getFileName());
|
||||
|
||||
$des = new Description(Service::getService());
|
||||
$operations = array_keys($des->getOperations());
|
||||
$docComment = "/**\n";
|
||||
$token = genToken();
|
||||
foreach ($operations as $key => $operation) {
|
||||
$type = $arg = $methodDesc = '';
|
||||
$model = $des->getOperation($operation)->getResponseModel();
|
||||
if ($des->hasModel($model)) {
|
||||
$type = $des->getModel($model)->getType();
|
||||
if (!empty($des->getOperation($operation)->getParams())) {
|
||||
$arg = '(array $args)';
|
||||
}
|
||||
$methodDesc = '';
|
||||
if (isset($token['method'][$operation])) {
|
||||
$line = $token['method'][$operation];
|
||||
if (isset($token['comment'][$line])) {
|
||||
$methodDesc = $token['comment'][$line];
|
||||
} elseif (isset($token['comment'][$line - 1])) {
|
||||
$methodDesc = $token['comment'][$line - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
$docComment .= " * @method {$type} {$operation}{$arg} {$methodDesc}\n";
|
||||
}
|
||||
$docComment .= " * @see \Qcloud\Cos\Service::getService()\n";
|
||||
$docComment .= ' */';
|
||||
|
||||
$data = str_replace($oldDocComment, $docComment, $clientFileContent);
|
||||
$status = file_put_contents($clientFile, $data);
|
||||
|
||||
if ($status) {
|
||||
echo 'Regenerate docComment successfully.', PHP_EOL;
|
||||
}
|
||||
|
||||
if (isset($argv[1])) {
|
||||
$version = $argv[1];
|
||||
$versionContent = str_replace(Client::VERSION, $version, $data);
|
||||
$status = file_put_contents($clientFile, $versionContent);
|
||||
|
||||
if ($status) {
|
||||
echo 'Update version successfully.', PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function genToken()
|
||||
{
|
||||
$result = [];
|
||||
$token = token_get_all(file_get_contents(dirname(__DIR__) . '/src/Service.php'));
|
||||
foreach ($token as $value) {
|
||||
if (!is_array($value) || !in_array($value[0], [T_COMMENT, T_CONSTANT_ENCAPSED_STRING])) {
|
||||
continue;
|
||||
}
|
||||
switch ($value[0]) {
|
||||
case T_COMMENT:
|
||||
$result['comment'][$value[2]] = trim(ltrim($value[1], '//'));
|
||||
break;
|
||||
case T_CONSTANT_ENCAPSED_STRING:
|
||||
$key = trim($value[1], "'");
|
||||
if(!isset($result['method'][$key])) {
|
||||
$result['method'][$key] = $value[2];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
Reference in New Issue
Block a user