Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: improves PHP generation.#7513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jcchavezs wants to merge5 commits intozaproxy:main
base:main
Choose a base branch
Loading
fromjcchavezs:improves_php_generator
Open
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
chore: makes lint happy.
Signed-off-by: José Carlos Chávez <jcchavezs@gmail.com>
  • Loading branch information
@jcchavezs
jcchavezs committedOct 18, 2022
commitf697b9ed9e331b7e6fe6b65c7c7ef0974155c6f5
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,9 @@
import java.util.ResourceBundle;
import java.util.stream.Collectors;

/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

**

* Generates PHP API code for PHP 7.4+
*/
public class PhpAPIGenerator extends AbstractAPIGenerator {

private static final String DEFAULT_OUTPUT_DIR = "../zap-api-php/src/Zap/";
Expand DownExpand Up@@ -110,27 +113,27 @@ private void generatePhpElement(ApiElement element, String component, String typ
String desc = getMessages().getString(descTag);
String commentBlock = "";
if (!desc.isEmpty()) {
commentBlock = "\t * " + desc + "\n";
commentBlock = " * " + desc + "\n";
}
if (isOptional()) {
commentBlock += "\t * " + OPTIONAL_MESSAGE + "\n";
commentBlock += " * " + OPTIONAL_MESSAGE + "\n";
}

if (!commentBlock.isEmpty()) {
out.write("\t/**\n" + commentBlock + "\t */\n");
out.write("/**\n" + commentBlock + " */\n");
}

} catch (Exception e) {
// Might not be set, so just print out the ones that are missing
System.out.println("No i18n for: " + descTag);
if (isOptional()) {
out.write("\t/**\n");
out.write("\t * " + OPTIONAL_MESSAGE + "\n");
out.write("\t */\n");
out.write("/**\n");
out.write(" * " + OPTIONAL_MESSAGE + "\n");
out.write(" */\n");
}
}

out.write("\tpublic function " + createMethodName(element.getName()) + "(");
out.write(" public function " + createMethodName(element.getName()) + "(");

out.write(
element.getParameters().stream()
Expand DownExpand Up@@ -181,17 +184,17 @@ private void generatePhpElement(ApiElement element, String component, String typ
.filter(e -> !e.isRequired())
.collect(Collectors.toList());
if (!optionalParameters.isEmpty()) {
out.write("\t\t$params = ");
out.write("$params = ");
out.write(reqParams.toString());
out.write(";\n");
reqParams.replace(0, reqParams.length(), "$params");

for (ApiParameter parameter : optionalParameters) {
String name = parameter.getName();
String varName = name.toLowerCase(Locale.ROOT);
out.write("\t\tif ($" + varName + " !== NULL) {\n");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Switched tabs into spaces as that is what is being used by standards. In any case, all the code is reformatted by proper PHP linters in the PHP API client.

out.write("\t\t\t$params['" + name + "'] = $" + varName + ";\n");
out.write("\t\t}\n");
out.write(" if ($" + varName + " !== NULL) {\n");
out.write("$params['" + name + "'] = $" + varName + ";\n");
out.write("}\n");
}
}

Expand All@@ -203,7 +206,7 @@ private void generatePhpElement(ApiElement element, String component, String typ
}

out.write(
"\t\treturn $this->zap->"
" return $this->zap->"
+ method
+ "($this->zap->"
+ baseUrl
Expand All@@ -220,14 +223,14 @@ private void generatePhpElement(ApiElement element, String component, String typ
out.write(")");
if (type.equals(VIEW_ENDPOINT)) {
if (element.getName().startsWith("option")) {
out.write("->" + element.getName().substring(6) +" ?? null;\n");
out.write("->" + element.getName().substring(6) +" ?? null;\n");
} else {
out.write("->" + element.getName() + " ?? null;\n");
}
} else {
out.write(";\n");
}
out.write("\t}\n\n");
out.write("}\n\n");
}

private static String createMethodName(String name) {
Expand DownExpand Up@@ -260,11 +263,11 @@ protected void generateAPIFiles(ApiImplementor imp) throws IOException {
out.write(" */\n");
out.write("class " + className + " {\n\n");

out.write("\tprivate Zap $zap;\n\n");
out.write(" private Zap $zap;\n\n");

out.write("\tpublic function __construct (Zap $zap) {\n");
out.write("\t\t$this->zap = $zap;\n");
out.write("\t}\n\n");
out.write(" public function __construct (Zap $zap) {\n");
out.write("$this->zap = $zap;\n");
out.write("}\n\n");

for (ApiElement view : imp.getApiViews()) {
this.generatePhpElement(view, imp.getPrefix(), VIEW_ENDPOINT, out);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp