/** * @return PhpMethod */ protected function getEnumMethodGetValidValues() { $method = new PhpMethod(self::METHOD_GET_VALID_VALUES, array(), PhpMethod::ACCESS_PUBLIC, false, true); $validValues = $this->getEnumMethodValues(); $method->addChild('return array('); foreach ($validValues as $validValue) { $method->addChild(sprintf('%s,', $method->getIndentedString($validValue, 1))); } $method->addChild(');'); return $method; }
public function testPublicWithBodyToString() { $method = new PhpMethod('foo', array('bar', array('name' => 'demo', 'value' => 1), array('name' => 'sample', 'value' => null), new PhpFunctionParameter('deamon', true))); $method->addChild(new PhpVariable('bar', 1))->addChild('return $bar;'); $this->assertSame("public function foo(\$bar, \$demo = 1, \$sample = null, \$deamon = true)\n{\n \$bar = 1;\n return \$bar;\n}", $method->toString()); }
/** * @param MethodContainer $methods * @return Service */ protected function addGetResultMethod(MethodContainer $methods) { $method = new PhpMethod(self::METHOD_GET_RESULT); $method->addChild('return parent::getResult();'); $methods->add($method); return $this; }
public function testSimpleClassPublicMethodToString() { $class = new PhpClass('Foo'); $method = new PhpMethod('bar', array('bar', 'foo', 'sample'), PhpMethod::ACCESS_PRIVATE); $method->addChild(new PhpVariable('foo', 1)); $class->addChild($method); $this->assertSame("class Foo\n{\n private function bar(\$bar, \$foo, \$sample)\n {\n \$foo = 1;\n }\n}", $class->toString()); }
/** * @param MethodContainer $methods * @param string $name * @param string $body * @param string[] $methodParameters * @return StructArray */ protected function addArrayMethodGenericMethod(MethodContainer $methods, $name, $body, array $methodParameters = array()) { $method = new PhpMethod($name, $methodParameters); $method->addChild($body); $methods->add($method); return $this; }
/** * @return PhpMethod */ protected function getToStringMethod() { $method = new PhpMethod('__toString'); $method->addChild('return __CLASS__;'); return $method; }
/** * @param PhpMethod $method * @param StructModel $struct * @return ClassMap */ protected function addStructToClassMapList(PhpMethod $method, StructModel $struct) { if ($struct->getIsStruct() && !$struct->getIsRestriction()) { $method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), $this->getStructName($struct)), 1)); } return $this; }
/** * @param MethodContainer $methods * @return Struct */ protected function addStructMethodSetState(MethodContainer $methods) { $method = new PhpMethod(self::METHOD_SET_STATE, array(new PhpFunctionParameter('array', PhpFunctionParameter::NO_VALUE, 'array')), PhpMethod::ACCESS_PUBLIC, false, true); $method->addChild(sprintf('return parent::__set_state($array);')); $methods->add($method); return $this; }
/** * @param PhpMethod $method * @return Operation */ protected function defineBody(PhpMethod $method) { $method->addChild('try {')->addChild($method->getIndentedString(sprintf('$this->setResult(self::getSoapClient()->%s%s));', $this->getSoapCallName(), $this->getOperationCallParameters($method)), 1))->addChild($method->getIndentedString('return $this->getResult();', 1))->addChild('} catch (\\SoapFault $soapFault) {')->addChild($method->getIndentedString('$this->saveLastError(__METHOD__, $soapFault);', 1))->addChild($method->getIndentedString('return false;', 1))->addChild('}'); return $this; }