Skip to content

Commit

Permalink
Bump 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peze committed Nov 15, 2024
1 parent 189c27c commit 1c23198
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DSL = require('@darabonba/parser');
const {
_name, _string, _subModelName, _vid,
_isBinaryOp, _modelName, _isBuiltinModel,
REQUEST, RESPONSE, CORE, _upperFirst, _avoidKeywords,
REQUEST, RESPONSE, CORE, _upperFirst, _avoidKeywords, _filedsAccess,
ERROR, MODEL, STREAM, UNRETRY_ERROR, RETRY_CONTEXT, SSE_EVENT,
RESP_ERROR, RETRY_OPTION, RUNTIME_OPTION, EXTEND_PARAM
} = require('./helper');
Expand Down Expand Up @@ -1298,13 +1298,14 @@ ${this.config.clientName}::main(array_slice($argv, 1));`);
let node;
for (let i = 0; i < ast.nodes.length; i++) {
node = ast.nodes[i];
const fieldName = _name(node.fieldName);
// TODO document gen
this.emit('/**\n', level);
this.emit('* @var ', level);
this.visitFieldType(node.fieldValue, level, _name(node.fieldName));
this.visitFieldType(node.fieldValue, level, fieldName);
this.emit('\n');
this.emit('*/\n', level);
this.emit(`protected $${_name(node.fieldName)};\n`, level);
this.emit(`${_filedsAccess(fieldName)} $${fieldName};\n`, level);
}

this.emit('\n');
Expand Down
15 changes: 14 additions & 1 deletion lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const keywords = [
'try', 'unset', 'use', 'var', 'while', 'xor'
];

const publicFields = [
// be compatible with TeaError
'message', 'errCode', 'data', 'name', 'statusCode',
'description', 'accessDeniedDetail', 'errorInfo',
];

const builtinModels = ['$Request', '$Response', '$Error', '$SSEEvent', '$Model'];
const NAMESPACE = 'AlibabaCloud\\Dara';
const CORE = 'AlibabaCloud\\Dara\\Dara';
Expand Down Expand Up @@ -61,6 +67,13 @@ function _avoidKeywords(str) {
return str;
}

function _filedsAccess(str) {
if (publicFields.indexOf(str) > -1) {
return 'public';
}
return 'protected';
}

function _modelName(str) {
if (keywords.indexOf(str.toLowerCase()) > -1 || str.toLowerCase() === 'model') {
return str + '_';
Expand Down Expand Up @@ -98,7 +111,7 @@ function _isBuiltinModel(name){

module.exports = {
_name, _string, _subModelName, _vid, _upperFirst, _isBuiltinModel,
_isBinaryOp, _modelName, _avoidKeywords, RETRY_CONTEXT,
_isBinaryOp, _modelName, _avoidKeywords, _filedsAccess, RETRY_CONTEXT,
REQUEST, RESPONSE, MODEL, NAMESPACE, ERROR, STREAM, UNRETRY_ERROR,
CORE, SSE_EVENT, RESP_ERROR, RETRY_OPTION, RUNTIME_OPTION, EXTEND_PARAM
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@darabonba/php-generator",
"version": "1.2.1",
"version": "2.0.0",
"description": "The SDK generator for PHP",
"main": "lib/generator",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/complex/Exceptions/Err1Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Err1Exception extends DaraException {
/**
* @var string[]
*/
protected $data;
public $data;

public function __construct($map)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/model/Exceptions/MainFileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MainFileException extends DaraException {
/**
* @var model_[]
*/
protected $data;
public $data;
/**
* @var \Dara\PHP\Tests\Models\MainFile\model_
*/
Expand Down

0 comments on commit 1c23198

Please sign in to comment.