Permalink
Browse files

Merge branch 'master' of https://github.com/brunnels/wsdl2phpgenerato…

  • Loading branch information...
2 parents 6450ee6 + a06d796 commit a4f83ac090132742db3682f3e8465cb94b8e22d2 @brunnels committed Feb 8, 2013
Showing with 95 additions and 9 deletions.
  1. +84 −2 src/ComplexType.php
  2. +11 −7 src/Validator.php
View
@@ -42,10 +42,10 @@ function __construct($name)
}
/**
- * Implements the loading of the class object
+ * Implements the loading of the class object using simple properties
* @throws Exception if the class is already generated(not null)
*/
- protected function generateClass()
+ protected function generateSimpleClass()
{
if ($this->class != null)
{
@@ -101,6 +101,88 @@ protected function generateClass()
}
/**
+ * Implements the loading of the class object using setters and getters
+ * @throws Exception if the class is already generated(not null)
+ */
+ protected function generateClass()
+ {
+ if ($this->class != null)
+ {
+ throw new Exception("The class has already been generated");
+ }
+
+ $primitives = array(
+ 'int',
+ 'float',
+ 'string',
+ 'bool',
+ 'mixed'
+ );
+
+ $config = Generator::getInstance()->getConfig();
+
+ $class = new PhpClass($this->phpIdentifier, $config->getClassExists());
+
+ // Only add the constructor if type constructor is selected
+ if ($config->getNoTypeConstructor() == false)
+ {
+ $constructorComment = new PhpDocComment();
+ $constructorComment->setAccess(PhpDocElementFactory::getPublicAccess());
+
+ $constructorSource = ' foreach($properties as $key => $value)'.PHP_EOL;
+ $constructorSource .= ' {'.PHP_EOL;
+ $constructorSource .= ' $setter = \'set\' . ucfirst($key);'.PHP_EOL;
+ $constructorSource .= ' $this->$setter($value);'.PHP_EOL;
+ $constructorSource .= ' }'.PHP_EOL;
+
+ $constructorParameters = 'Array $properties = array()';
+ $constructorFunction = new PhpFunction('public', '__construct', $constructorParameters, $constructorSource, $constructorComment);
+ $class->addFunction($constructorFunction);
+ }
+
+ // Add member variables
+ foreach ($this->members as $member)
+ {
+ $type = '';
+
+ try
+ {
+ $type = Validator::validateType($member->getType());
+ }
+ catch (ValidationException $e)
+ {
+ $type .= 'Custom';
+ }
+
+ $name = Validator::validateNamingConvention($member->getName());
+
+ $classComment = new PhpDocComment();
+ $classComment->setVar(PhpDocElementFactory::getVar($type, $name, ''));
+ $classComment->setAccess(PhpDocElementFactory::getPrivateAccess());
+ $classVar = new PhpVariable('private', $name, '', $classComment);
+ $class->addVariable($classVar);
+
+ $setterParameters = ((!in_array($type, $primitives)) ? "$type " : '') . "$$name";
+ $setterSource = " \$this->$name = $$name;".PHP_EOL;
+ $setterComment = new PhpDocComment();
+ $setterComment->setAccess(PhpDocElementFactory::getPublicAccess());
+ $setterComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
+ $setterFunction = new PhpFunction('public', 'set' . ucfirst($name), $setterParameters, $setterSource, $setterComment);
+ $class->addFunction($setterFunction);
+
+ $getterSource = " return \$this->$name;".PHP_EOL;
+ $getterComment = new PhpDocComment();
+ $getterComment->setAccess(PhpDocElementFactory::getPublicAccess());
+ $getterComment->setReturn(PhpDocElementFactory::getReturn($type, ''));
+ $getterFunction = new PhpFunction('public', 'get' . ucfirst($name), '', $getterSource, $getterComment);
+ $class->addFunction($getterFunction);
+
+ }
+
+ $this->class = $class;
+ }
+
+ /**
* Adds the member. Owerwrites members with same name
*
* @param string $type
View
@@ -138,7 +138,7 @@ public static function validateNamingConvention($name)
}
return preg_replace('/[^a-zA-Z0-9_x7f-xff]*/', '', preg_replace('/^[^a-zA-Z_x7f-xff]*/', '', $name));
-
+
}
@@ -196,7 +196,7 @@ private static function validateTypeName($type)
if (substr($type, -2) == "[]" || strtolower(substr($type, 0, 7)) == "arrayof")
{
return 'array';
- }
+ }
switch (strtolower($type))
{
@@ -214,9 +214,13 @@ private static function validateTypeName($type)
case "string": case "token": case "normalizedstring": case "hexbinary":
return 'string';
break;
-
+
+ case "boolean":
+ return 'bool';
+ break;
+
case "anytype":
- return 'SoapVar';
+ return 'Array';
break;
default:
@@ -242,15 +246,15 @@ private static function isKeyword($str)
{
return in_array(strtolower($str), self::$keywords);
}
-
+
/**
* Applies config prefix and suffix to a string
- *
+ *
* @param string $str
*/
private static function applyPrefixAndSuffix($str)
{
- $config = Generator::getInstance()->getConfig();
+ $config = Generator::getInstance()->getConfig();
return $config->getPrefix() . (($config->getPrefix()) ? ucfirst($str) : $str) . $config->getSuffix();
}
}

0 comments on commit a4f83ac

Please sign in to comment.