1: <?php
2:
3: namespace webfilesframework\codegeneration\php;
4:
5: use webfilesframework\codegeneration\general\MAbstractClassMethod;
6:
7: 8: 9: 10: 11: 12:
13: class MPhpClassMethod extends MAbstractClassMethod
14: {
15:
16:
17: public function __construct($visibility, $name, $content)
18: {
19: $this->visibility = $visibility;
20: $this->name = $name;
21: $this->content = $content;
22: }
23:
24:
25: public function generateCode()
26: {
27:
28: $parameterCode = "";
29: $parameterCount = 0;
30:
31:
32: foreach ($this->parameters as $parameter) {
33:
34: $parameterCode .= $parameter->generateCode();
35:
36: if (count($this->parameters) > $parameterCount) {
37: $parameterCode .= ",";
38: }
39:
40: $parameterCount++;
41: }
42:
43: $code = $this->visibility . " function " . $this->name . " (" . $parameterCode . ") {\n";
44: $code .= $this->content;
45: $code .= "}\n\n";
46: return $code;
47: }
48:
49: public function addParameter(MPhpClassMethodParameter $parameter)
50: {
51: $this->parameters[] = $parameter;
52: }
53:
54: }