Permalink
Browse files

Manual merge of all changes

  • Loading branch information...
1 parent 2a0cbe8 commit 57f030979fdac1a3517e2991c39b541d15487ef4 @walle committed Feb 24, 2010
Showing with 2,000 additions and 1,158 deletions.
  1. +6 −0 CHANGES
  2. +0 −801 Wsdl2PhpGenerator.php
  3. 0 { → conf}/settings.conf
  4. 0 { → conf}/translations/sv_SE/LC_MESSAGES/messages.mo
  5. 0 { → conf}/translations/sv_SE/LC_MESSAGES/messages.po
  6. +11 −8 generate.php
  7. +8 −8 { → lib}/cli/Cli.php
  8. +1 −1 { → lib}/cli/CliParser.php
  9. +2 −2 { → lib}/cli/Flag.php
  10. +2 −1 { → lib}/config/Config.php
  11. +6 −3 { → lib}/config/FileConfig.php
  12. +15 −13 { → lib}/phpSource/PhpClass.php
  13. +27 −27 { → lib}/phpSource/PhpDocComment.php
  14. +1 −1 { → lib}/phpSource/PhpDocElement.php
  15. +32 −32 { → lib}/phpSource/PhpDocElementFactory.php
  16. +1 −1 { → lib}/phpSource/PhpElement.php
  17. +20 −9 { → lib}/phpSource/PhpFile.php
  18. +7 −7 { → lib}/phpSource/PhpFunction.php
  19. +5 −5 { → lib}/phpSource/PhpVariable.php
  20. +113 −0 src/ComplexType.php
  21. +1 −1 Wsdl2PhpConfig.php → src/Config.php
  22. +98 −0 src/DocumentationManager.php
  23. +116 −0 src/Enum.php
  24. +2 −1 Wsdl2PhpException.php → src/Exception.php
  25. +390 −0 src/Generator.php
  26. +203 −0 src/Operation.php
  27. +193 −0 src/OutputManager.php
  28. +72 −0 src/Pattern.php
  29. +246 −0 src/Service.php
  30. +129 −0 src/Type.php
  31. +4 −4 Wsdl2PhpValidationException.php → src/ValidationException.php
  32. +89 −95 Wsdl2PhpValidator.php → src/Validator.php
  33. +55 −0 src/Variable.php
  34. +4 −4 tests/{Wsdl2PhpConfigTest.php → ConfigTest.php}
  35. +117 −0 tests/ValidatorTest.php
  36. +0 −117 tests/Wsdl2PhpValidatorTest.php
  37. +2 −3 tests/{ → lib}/cli/CliParserTest.php
  38. +2 −3 tests/{ → lib}/cli/CliTest.php
  39. +5 −5 tests/{ → lib}/cli/FlagTest.php
  40. +5 −5 tests/{ → lib}/config/FileConfigTest.php
  41. +1 −1 wsdl2php
  42. +6 −0 wsdl2php.bat
  43. +3 −0 wsdl2php.php
View
6 CHANGES
@@ -1,5 +1,11 @@
CHANGES
+Version 1.4
+
+* Improved the phpdoc generated
+* Added support for enumerated values issue #13
+* Added support for generating phpdoc from the documentation blocks in the wsdl issue #18
+
Version 1.3
* Adding the -v verbose flag
View
801 Wsdl2PhpGenerator.php
@@ -1,801 +0,0 @@
-<?php
-/**
- * @package Wsdl2PhpGenerator
- */
-
-/**
- * Include the needed files
- */
-include_once('Wsdl2PhpConfig.php');
-include_once('Wsdl2PhpException.php');
-include_once('Wsdl2PhpValidator.php');
-
-// Php code classes
-include_once('phpSource/PhpFile.php');
-include_once('phpSource/PhpVariable.php');
-include_once('phpSource/PhpDocComment.php');
-include_once('phpSource/PhpDocElementFactory.php');
-
-/**
- * Class that contains functionality for generating classes from a wsdl file
- *
- * @package Wsdl2PhpGenerator
- * @author Fredrik Wallgren <fredrik@wallgren.me>
-@license http://www.opensource.org/licenses/mit-license.php MIT License
- */
-class Wsdl2PhpGenerator
-{
- /**
- * A SoapClient for loading the WSDL
- * @var SoapClient
- * @access private
- */
- private $client = null;
-
- /**
- * DOM document used to load and parse the wsdl
- * @var DOMDocument
- * @access private
- */
- private $dom = null;
-
- /**
- * A phpSource code representation of the client
- *
- * @var PhpClass The service class
- */
- private $service;
-
- /**
- * An array of class objects that represents the complexTypes in the service
- *
- * @var array Array of PhpClass objects
- */
- private $types;
-
- /**
- * An array of class objects that represents the simpleTypes in the service
- *
- * @var array Array of \phpSource\PhpClass objects
- */
- private $enums;
-
- /**
- *
- * @var array Array with restriction datatypes for simple types
- */
- private $simple;
-
- /**
- * The validator to use
- *
- * @var Wsdl2PhpValidator
- * @access private
- */
- private $validator;
-
- /**
- * This is the object that holds the current config
- *
- * @var Wsdl2PhpConfig
- * @access private
- */
- private $config;
-
- /**
- *
- * @var array Array containing documentation for service and functions 'service' => "" 'functions' => array()
- */
- private $documentation;
-
- /**
- * Construct the generator
- */
- public function __construct()
- {
- $this->validator = new Wsdl2PhpValidator();
- $this->service = null;
- $this->types = array();
- $this->enums = array();
- $this->simple = array();
- $this->documentation = array('service' => '',
- 'functions' => array());
- }
-
- /**
- * Generates php source code from a wsdl file
- *
- * @see Wsdl2PhpConfig
- * @param Wsdl2PhpConfig $config The config to use for generation
- * @access public
- */
- public function generate(Wsdl2PhpConfig $config)
- {
- $this->config = $config;
-
- $this->log(_('Starting generation'));
-
- $this->load();
-
- $this->savePhp();
-
- $this->log(_('Generation complete'));
- }
-
- /**
- * Load the wsdl file into php
- */
- private function load()
- {
- $wsdl = $this->config->getInputFile();
-
- try
- {
- $this->log(_('Loading the wsdl'));
- $this->client = new SoapClient($wsdl);
- }
- catch(SoapFault $e)
- {
- throw new Exception('Error connectiong to to the wsdl. Error: '.$e->getMessage());
- }
-
- $this->log(_('Loading the DOM'));
- $this->dom = DOMDocument::load($wsdl);
-
- $this->loadDocumentation();
- $this->loadTypes();
- $this->loadService();
- }
-
- /**
- * Loads the service class
- *
- * @access private
- */
- private function loadService()
- {
- $serviceName = $this->dom->getElementsByTagNameNS('*', 'service')->item(0)->getAttribute('name');
-
- // Add prefix and suffix
- $serviceName = $this->config->getPrefix().$serviceName.$this->config->getSuffix();
-
- try
- {
- $serviceName = $this->validator->validateClass($serviceName);
- }
- catch (Wsdl2PhpValidationException $e)
- {
- $serviceName .= 'Custom';
- }
-
- $serviceComment = new PhpDocComment($this->documentation['service']);
-
- $this->service = new PhpClass($serviceName, $this->config->getClassExists(), 'SoapClient', $serviceComment);
-
- $this->log(_('Generating class '.$serviceName));
-
- $this->log(_('Generating comment for '.$serviceName));
-
- $comment = new PhpDocComment();
- $comment->addParam(PhpDocElementFactory::getParam('string', 'wsdl', 'The wsdl file to use'));
- $comment->addParam(PhpDocElementFactory::getParam('array', 'config', 'A array of config values'));
- $comment->setAccess(PhpDocElementFactory::getPublicAccess());
-
- $source = ' foreach(self::$classmap as $key => $value)
- {
- if(!isset($options[\'classmap\'][$key]))
- {
- $options[\'classmap\'][$key] = $value;
- }
- }
- '.$this->generateServiceOptions($this->config).'
- parent::__construct($wsdl, $options);'.PHP_EOL;
-
- $this->log(_('Generating constructor for '.$serviceName));
-
- $function = new PhpFunction('public', '__construct', '$wsdl = \''.$this->config->getInputFile().'\', $options = array()', $source, $comment);
-
- $this->service->addFunction($function);
-
- $name = 'classmap';
- $comment = new PhpDocComment();
- $comment->setAccess(PhpDocElementFactory::getPrivateAccess());
- $comment->setVar(PhpDocElementFactory::getVar('array', $name, 'The defined classes'));
-
- $init = 'array('.PHP_EOL;
- foreach ($this->types as $realName => $type)
- {
- $init .= " '".$realName."' => '".$type->getIdentifier()."',".PHP_EOL;
- }
- $init = substr($init, 0, strrpos($init, ','));
- $init .= ')';
- $var = new PhpVariable('private static', $name, $init, $comment);
- $this->service->addVariable($var);
-
- $this->log(_('Adding classmap'));
-
- $this->log(_('Loading operations for '.$serviceName));
-
- $functions = $this->client->__getFunctions();
- foreach($functions as $function)
- {
- $matches = array();
- if(preg_match('/^(\w[\w\d_]*) (\w[\w\d_]*)\(([\w\$\d,_ ]*)\)$/', $function, $matches))
- {
- $returns = $matches[1];
- $call = $matches[2];
- $params = $matches[3];
- }
- else if(preg_match('/^(list\([\w\$\d,_ ]*\)) (\w[\w\d_]*)\(([\w\$\d,_ ]*)\)$/', $function, $matches))
- {
- $returns = $matches[1];
- $call = $matches[2];
- $params = $matches[3];
- }
- else
- {
- // invalid function call
- throw new Wsdl2PhpException('Invalid function call: '.$function);
- }
-
- $docDesc = '';
- if (array_key_exists($call, $this->documentation['functions']))
- {
- $docDesc = $this->documentation['functions'][$call];
- }
-
- $name = $this->validator->validateNamingConvention($call);
-
- $comment = new PhpDocComment($docDesc);
- $comment->setAccess(PhpDocElementFactory::getPublicAccess());
-
- $source = ' return $this->__soapCall(\''.$name.'\', array(';
- $paramStr = '';
- foreach (explode(', ', $params) as $param)
- {
- $val = explode(' ', $param);
-
- // Check if we have type hint
- if (count($val) == 1)
- {
- if (strlen($val[0]) > 0)
- {
- $source .= $val[0].', ';
- $paramStr .= $val[0].', ';
- $comment->addParam(PhpDocElementFactory::getParam('', $val[0], ''));
- }
- }
- else
- {
- $source .= $val[1].', ';
-
- // If we have valid typehint use it otherwise not
- if ($this->validator->isPrimitive($val[0]))
- {
- $paramStr .= $val[1].', ';
- }
- else
- {
- $found = false;
- // Check so the input type is a valid type in the wsdl
- foreach ($this->types as $type)
- {
- if ($type->getIdentifier() == $val[0])
- {
- $found = true;
- break;
- }
- }
-
- if ($found)
- {
- $paramStr .= $val[0].' '.$val[1].', ';
- }
- else
- {
- $paramStr .= $val[1].', ';
- }
- }
-
- // Use the restriction datatype for phpdoc for non enum simple types
- if (array_key_exists($val[0], $this->simple))
- {
- $found = false;
- foreach ($this->enums as $type)
- {
- if ($type->getIdentifier() == $val[0])
- {
- $found = true;
- break;
- }
- }
-
- if ($found)
- {
- $comment->addParam(PhpDocElementFactory::getParam($val[0], $val[1], _('Constant: ').$this->simple[$val[0]][0]));
- }
- else
- {
- // TODO: Refactor simple type to a separate class
- $comment->addParam(PhpDocElementFactory::getParam($this->simple[$val[0]][0], $val[1], _('Restriction pattern: ').$this->simple[$val[0]][1]));
- }
- }
- else
- {
- $comment->addParam(PhpDocElementFactory::getParam($val[0], $val[1], ''));
- }
- }
- }
- // Remove last comma
- $source = substr($source, 0, -2);
- $source .= '));'.PHP_EOL;
-
- $paramStr = substr($paramStr, 0, -2);
-
- $function = new PhpFunction('public', $name, $paramStr, $source, $comment);
-
- if ($this->service->functionExists($function->getIdentifier()) == false)
- {
- $this->log(_('Adding operation '.$name.'('.$paramStr.')'));
- $this->service->addFunction($function);
- }
- }
-
- $this->log(_('Done loading service'));
- }
-
- /**
- *
- * @param Wsdl2PhpConfig $config The config containing the values to use
- *
- * @return string Returns the string for the options array
- */
- private function generateServiceOptions(Wsdl2PhpConfig $config)
- {
- $ret = '';
-
- $this->log(_('Generating service options'));
-
- if (count($config->getOptionFeatures()) > 0)
- {
- $this->log(_('Adding option features'));
- $i = 0;
- $ret .= "
- if (isset(\$options['features']) == false)
- {
- \$options['features'] = ";
- foreach ($config->getOptionFeatures() as $option)
- {
- if ($i++ > 0)
- {
- $ret .= ' | ';
- }
-
- $ret .= $option;
- }
-
- $ret .= ";
- }".PHP_EOL;
- }
-
- if (strlen($config->getWsdlCache()) > 0)
- {
- $this->log(_('Adding wsdl cache option'));
-
- $ret .= "
- if (isset(\$options['wsdl_cache']) == false)
- {
- \$options['wsdl_cache'] = ".$config->getWsdlCache();
- $ret .= ";
- }".PHP_EOL;
- }
-
- if (strlen($this->config->getCompression()) > 0)
- {
- $this->log(_('Adding compression'));
-
- $ret .= "
- if (isset(\$options['compression']) == false)
- {
- \$options['compression'] = ".$config->getCompression();
- $ret .= ";
- }".PHP_EOL;
- }
-
- return $ret;
- }
-
- /**
- * Loads all type classes
- *
- * @access private
- */
- private function loadTypes()
- {
- $this->log(_('Loading types'));
-
- $types = $this->client->__getTypes();
-
- foreach($types as $type)
- {
- $parts = explode("\n", $type);
- $className = explode(" ", $parts[0]);
- $className = $className[1];
-
- if(substr($className, -2, 2) == '[]' || substr($className, 0, 7) == 'ArrayOf')
- {
- // skip arrays
- continue;
- }
-
- $members = array();
- for($i = 1; $i < count($parts) - 1; $i++)
- {
- $parts[$i] = trim($parts[$i]);
- list($type, $member) = explode(" ", substr($parts[$i], 0, strlen($parts[$i])-1) );
-
- if(strpos($member, ':'))
- {
- $arr = explode(':', $member);
- $member = $arr[1];
- }
-
- $add = true;
- foreach($members as $mem)
- {
- if($mem['member'] == $member)
- {
- $add = false;
- }
- }
-
- if($add)
- {
- $members[] = array('member' => $member, 'type' => $type);
- }
- }
-
- // Add prefix and suffix
- $className = $this->config->getPrefix().$className.$this->config->getSuffix();
-
- $realName = $className;
-
- // Collect simple types
- $values = array();
- $restrictions = array();
- if(count($members) == 0)
- {
- $theNode = null;
-
- $typesNode = $this->dom->getElementsByTagName('types')->item(0);
- $schemaList = $typesNode->getElementsByTagName('schema');
-
- foreach ($schemaList as $schema)
- {
- foreach ($schema->childNodes as $node)
- {
- if($node instanceof DOMElement)
- {
- if ($node->hasAttributes())
- {
- $t = $node->attributes->getNamedItem('name');
- if ($t)
- {
- if($t->nodeValue == $className)
- {
- $theNode = $node;
- }
- }
- }
- }
- }
- }
-
- // Simple type
- if($theNode)
- {
- $restriction = '';
- $pattern = '';
-
- $restrictionList = $theNode->getElementsByTagName('restriction');
- if ($restrictionList->item(0))
- {
- $restriction = $restrictionList->item(0)->attributes->getNamedItem('base')->nodeValue;
- if (strpos($restriction, ':'))
- {
- $arr = explode(':', $restriction);
- $restriction = $arr[1];
- }
- }
-
- // If enum
- $valueList = $theNode->getElementsByTagName('enumeration');
- if ($valueList->length > 0)
- {
- foreach ($valueList as $value)
- {
- $values[] = $value->attributes->getNamedItem('value')->nodeValue;
- }
- }
- else // If pattern
- {
- if (strlen($restriction) > 0)
- {
- $patternList = $theNode->getElementsByTagName('pattern');
- $pattern = $patternList->item(0)->attributes->getNamedItem('value')->nodeValue;
- }
- }
-
- if (strlen($restriction) > 0)
- {
- $restrictions[$realName] = array($restriction, $pattern);
- }
- }
- }
-
- try
- {
- $className = $this->validator->validateClass($className);
- }
- catch (Wsdl2PhpValidationException $e)
- {
- $className .= 'Custom';
- }
-
- $this->log(_('Generating type '.$className));
-
- $class = new PhpClass($className, $this->config->getClassExists());
-
- $constructorComment = new PhpDocComment();
- $constructorComment->setAccess(PhpDocElementFactory::getPublicAccess());
- $constructorSource = '';
- $constructorParameters = '';
-
- // Add enumerators "const members"
- foreach ($values as $value)
- {
- try
- {
- $name = $this->validator->validateNamingConvention($value);
- }
- catch (ValidationException $e)
- {
- $name = 'constant'.$name;
- }
- try
- {
- $name = $this->validator->validateType($name);
- }
- catch (ValidationException $e)
- {
- $name .= 'Custom';
- }
-
- $class->addConstant($value, $name);
- }
-
- // Add member variables
- foreach ($members as $varArr)
- {
- try
- {
- $type = $this->validator->validateType($varArr['type']);
- }
- catch (Wsdl2PhpValidationException $e)
- {
- $type .= 'Custom';
- }
-
- $name = $this->validator->validateNamingConvention($varArr['member']);
- $comment = new PhpDocComment();
- $comment->setVar(PhpDocElementFactory::getVar($type, $name, ''));
- $comment->setAccess(PhpDocElementFactory::getPublicAccess());
- $var = new PhpVariable('public', $name, '', $comment);
- $class->addVariable($var);
-
- $constructorSource .= ' $this->'.$name.' = $'.$name.';'.PHP_EOL;
- $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
- $constructorComment->setAccess(PhpDocElementFactory::getPublicAccess());
- $constructorParameters .= ', $'.$name;
- }
-
- $constructorParameters = substr($constructorParameters, 2); // Remove first comma
- $function = new PhpFunction('public', '__construct', $constructorParameters, $constructorSource, $constructorComment);
-
- // Only add the constructor if type constructor is selected
- if ($this->config->getNoTypeConstructor() == false)
- {
- $class->addFunction($function);
-
- $this->log(_('Adding constructor for '.$className));
- }
-
- // Add the class to the right container
- if(count($members) == 0 && count($values) > 0)
- {
- $this->enums[$realName] = $class;
- $this->simple[$realName] = $restrictions[$realName];
- }
- else if(count($members) > 0 && count($values) == 0)
- {
- $this->types[$realName] = $class;
- }
- else
- {
- if (array_key_exists($realName, $restrictions))
- {
- $this->simple[$realName] = $restrictions[$realName];
- }
- else
- {
- $this->types[$realName] = $class;
- }
- }
- }
-
- $this->log(_('Done loading types'));
- }
-
- /**
- * Loads the documentation for service and functions
- */
- private function loadDocumentation()
- {
- $docList = $this->dom->getElementsByTagName('documentation');
-
- foreach($docList as $item)
- {
- if($item->parentNode->localName == 'service')
- {
- $this->documentation['service'] = trim($item->parentNode->nodeValue);
- }
- else if($item->parentNode->localName == 'operation')
- {
- $name = $item->parentNode->getAttribute('name');
- $this->documentation['functions'][$name] = trim($item->nodeValue);
- }
- }
- }
-
- /**
- * Save all the loaded classes to the configured output dir
- *
- * @throws Wsdl2PhpException If no service is loaded
- * @throws Wsdl2PhpException If the output dir does not exist and can't be created
- *
- * @access private
- */
- private function savePhp()
- {
- $outputDirectory = $this->config->getOutputDir();
-
- $this->log(_('Starting save to directory '. $outputDirectory));
-
- if ($this->service === null)
- {
- throw new Wsdl2PhpException('No service loaded');
- }
-
- $useNamespace = (strlen($this->config->getNamespaceName()) > 0);
-
- //Try to create output dir if non existing
- if (is_dir($outputDirectory) == false && is_file($outputDirectory) == false)
- {
- $this->log(_('Creating output dir'));
- if(mkdir($outputDirectory, 0777, true) == false)
- {
- throw new Wsdl2PhpException('Could not create output directory and it does not exist!');
- }
- }
-
- $validClasses = $this->config->getClassNamesArray();
-
- $file = null;
-
- if ($this->config->getOneFile())
- {
- // Check if the service class is in valid classes of if all classes should be generated
- if (count($validClasses) == 0 || count($validClasses) > 0 && in_array($this->service->getIdentifier(), $validClasses))
- {
- // Generate file and add all classes to it then save it
- $file = new PhpFile($this->service->getIdentifier());
-
- $this->log(_('Opening file '.$this->service->getIdentifier()));
-
- if ($useNamespace)
- {
- $file->addNamespace($this->config->getNamespaceName());
- }
-
- $file->addClass($this->service);
-
- $this->log(_('Adding service to file'));
- }
-
- foreach (array_merge($this->types, $this->enums) as $class)
- {
- // Check if the class should be saved
- if (count($validClasses) == 0 || count($validClasses) > 0 && in_array($class->getIdentifier(), $validClasses))
- {
- if ($file == null)
- {
- $file = new PhpFile($class->getIdentifier());
- }
-
- $file->addClass($class);
- $this->log(_('Adding type to file '.$class->getIdentifier()));
- }
- }
-
- // Sanity check, if the user only wanted to generate non-existing classes
- if ($file != null)
- {
- $this->log(_('Saving file'));
- $file->save($outputDirectory);
- }
- }
- else
- {
- // Save types
- foreach (array_merge($this->types, $this->enums) as $class)
- {
- // Check if the class should be saved
- if (count($validClasses) == 0 || count($validClasses) > 0 && in_array($class->getIdentifier(), $validClasses))
- {
- $file = new PhpFile($class->getIdentifier());
-
- if ($useNamespace)
- {
- $file->addNamespace($this->config->getNamespaceName());
- }
-
- $file->addClass($class);
-
- $this->log(_('Adding class '.$class->getIdentifier().' to file'));
-
- $file->save($outputDirectory);
-
- // Add the filename as dependency for the service
- $this->service->addDependency($class->getIdentifier().'.php');
-
- $this->log(_('Adding dependency'));
- }
- }
-
- // Check if the service class is in valid classes of if all classes should be generated
- if (count($validClasses) == 0 || count($validClasses) > 0 && in_array($this->service->getIdentifier(), $validClasses))
- {
- // Generate file and save the service class
- $file = new PhpFile($this->service->getIdentifier());
-
- $this->log(_('Opening file '.$this->service->getIdentifier()));
-
- if ($useNamespace)
- {
- $file->addNamespace($this->config->getNamespaceName());
- }
-
- $file->addClass($this->service);
-
- $this->log(_('Adding service to file'));
-
- $file->save($outputDirectory);
-
- $this->log(_('Saving file'));
- }
- }
- }
-
- /**
- * Logs a message to the standard output
- *
- * @param string $message The message to log
- */
- private function log($message)
- {
- if ($this->config->getVerbose() == true)
- {
- print $message.PHP_EOL;
- }
- }
-}
View
0 settings.conf → conf/settings.conf
File renamed without changes.
View
0 translations/sv_SE/LC_MESSAGES/messages.mo → ...ranslations/sv_SE/LC_MESSAGES/messages.mo
File renamed without changes.
View
0 translations/sv_SE/LC_MESSAGES/messages.po → ...ranslations/sv_SE/LC_MESSAGES/messages.po
File renamed without changes.
View
19 generate.php
@@ -6,19 +6,20 @@
/**
* Include the needed files
*/
-include_once('cli/Cli.php');
-include_once('config/FileConfig.php');
-include_once('Wsdl2PhpGenerator.php');
+require_once dirname(__FILE__).'/lib/cli/Cli.php';
+require_once dirname(__FILE__).'/lib/config/FileConfig.php';
+
+require_once dirname(__FILE__).'/src/Generator.php';
// Try to read the config file if any
try
{
- $config = new FileConfig('settings.conf');
+ $config = new configFileConfig(dirname(__FILE__).'/conf/settings.conf');
$locale = $config->get('language');
$domain = 'messages';
$lcDir = 'LC_MESSAGES';
- $path = $_SERVER['DOCUMENT_ROOT'].'translations';
+ $path = 'conf/translations';
$loc = substr($locale, 0, 5);
$file = $path.'/'.$loc.'/'.$lcDir.'/'.$domain.'.mo';
@@ -37,7 +38,7 @@
}
// Start
-$cli = new Cli('wsdl2php', '[OPTIONS] -i wsdlfile -o directory', '1.4');
+$cli = new cliCli('wsdl2php', '[OPTIONS] -i wsdlfile -o directory', '1.4');
$cli->addFlag('-e', _('If all classes should be guarded with if(!class_exists) statements'), true, false);
$cli->addFlag('-t', _('If no type constructor should be generated'), true, false);
$cli->addFlag('-s', _('If the output should be a single file'), true, false);
@@ -91,6 +92,8 @@
print _('You have selected to only generate one class and save it to a single file. If you have selected the service class and outputs this file to a directory where you previosly have generated the classes the file will be overwritten. Continue? [Y/n]').PHP_EOL;
}
+ //TODO: Refactor this to cli class?
+
// Force the user to supply a valid input
while(true)
{
@@ -154,7 +157,7 @@
$gzip = 'SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP';
}
-$config = new Wsdl2PhpConfig($inputFile, $outputDir, $verbose, $singleFile, $classExists, $noTypeConstructor, $namespaceName, $optionsArray, $wsdlCache, $gzip, $classNames, $prefix, $suffix);
+$config = new wsdl2phpConfig($inputFile, $outputDir, $verbose, $singleFile, $classExists, $noTypeConstructor, $namespaceName, $optionsArray, $wsdlCache, $gzip, $classNames, $prefix, $suffix);
-$generator = new Wsdl2PhpGenerator();
+$generator = new wsdl2phpGenerator();
$generator->generate($config);
View
16 cli/Cli.php → lib/cli/Cli.php
@@ -1,13 +1,13 @@
<?php
/**
-* @package cli
-*/
+ * @package cli
+ */
/**
* Include the needed files
*/
-include_once('CliParser.php');
-include_once('Flag.php');
+require_once dirname(__FILE__).'/CliParser.php';
+require_once dirname(__FILE__).'/Flag.php';
/**
* Class that represents the command line interface
@@ -16,7 +16,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class Cli extends CliParser
+class cliCli extends cliCliParser
{
/**
*
@@ -98,7 +98,7 @@ public function addFlag($flag, $description, $isBool = false, $required = false)
}
// Not busy, add it
- $this->acceptedFlags[$flag] = new Flag($flag, $description, $isBool);
+ $this->acceptedFlags[$flag] = new cliFlag($flag, $description, $isBool);
if ($required)
{
@@ -170,7 +170,7 @@ public function validate(array $argv)
// Add the help flag if not defined
if (array_key_exists('-h', $this->acceptedFlags) === false)
{
- $this->acceptedFlags['-h'] = new Flag('-h', _('Help'), true);
+ $this->acceptedFlags['-h'] = new cliFlag('-h', _('Help'), true);
}
if ($this->getValue('-h'))
@@ -239,7 +239,7 @@ public function getValue($flag)
/**
*
* @param string $flag
- * @return Flag|null Returns the flag either by name or alias
+ * @return cliFlag|null Returns the flag either by name or alias
*/
private function getFlag($flag)
{
View
2 cli/CliParser.php → lib/cli/CliParser.php
@@ -10,7 +10,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class CliParser
+class cliCliParser
{
/**
* Flags is stored flag => value
View
4 cli/Flag.php → lib/cli/Flag.php
@@ -10,7 +10,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class Flag
+class cliFlag
{
/**
*
@@ -63,7 +63,7 @@ public function __construct($name, $description, $isBool = false)
*/
public function __toString()
{
- return implode(', ', array_merge(array($this->name), $this->aliases)).str_pad('', $this->maxNumAliases - count($this->aliases), "\t").$this->description.PHP_EOL;
+ return implode(', ', array_merge(array($this->name), $this->aliases)).str_pad('', $this->maxNumAliases - count($this->aliases), "t").$this->description.PHP_EOL;
}
/**
View
3 config/Config.php → lib/config/Config.php
@@ -1,4 +1,5 @@
<?php
+
/**
* @package config
*/
@@ -10,7 +11,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-interface Config
+interface configConfig
{
/**
* Binds a value to the key
View
9 config/FileConfig.php → lib/config/FileConfig.php
@@ -6,7 +6,7 @@
/**
* Include the interface
*/
-include_once('Config.php');
+require_once dirname(__FILE__).'/Config.php';
/**
* A implementation of Config using a flatfile for storage
@@ -15,7 +15,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class FileConfig implements Config
+class configFileConfig implements configConfig
{
/**
* The separator in the file
@@ -89,6 +89,7 @@ public function __construct($filename, $buffer = false, $separator = '=')
$this->loaded = false;
$this->buffer = $buffer;
$this->commentChar = '#'; // Hardcoded
+ //TODO: Allow optional commentchars? ';' etc. ?
}
/**
@@ -131,6 +132,7 @@ public function set($key, $value)
* Returns the value attached to key or throw an exception
* @param string $key
* @return string
+ * @throws Exception If the value does not exist in the config
*/
public function get($key)
{
@@ -162,7 +164,8 @@ public function exists($key)
/**
* Loads the config file if the file exists else throws an exception.
- * Throws an exception if the file is invalid.
+ *
+ * @throws Exception If the file is invalid
*/
private function load()
{
View
28 phpSource/PhpClass.php → lib/phpSource/PhpClass.php
@@ -6,9 +6,9 @@
/**
* Include the needed files
*/
-include_once('PhpElement.php');
-include_once('PhpDocComment.php');
-include_once('PhpFunction.php');
+require_once dirname(__FILE__).'/PhpElement.php';
+require_once dirname(__FILE__).'/PhpDocComment.php';
+require_once dirname(__FILE__).'/PhpFunction.php';
/**
* Class that represents the source code for a class in php
@@ -17,7 +17,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class PhpClass extends PhpElement
+class phpSourcePhpClass extends phpSourcePhpElement
{
/**
*
@@ -79,10 +79,10 @@ class PhpClass extends PhpElement
* @param string $identifier
* @param bool $classExists
* @param string $extends A string of the class that this class extends
- * @param PhpDocComment $comment
+ * @param phpSourcePhpDocComment $comment
* @param bool $final
*/
- public function __construct($identifier, $classExists = false, $extends = '', PhpDocComment $comment = null, $final = false)
+ public function __construct($identifier, $classExists = false, $extends = '', phpSourcePhpDocComment $comment = null, $final = false)
{
$this->dependencies = array();
$this->classExists = $classExists;
@@ -200,7 +200,7 @@ public function addConstant($value, $name = '')
{
if (strlen($value) == 0)
{
- throw new \Exception('No value supplied');
+ throw new Exception('No value supplied');
}
// If no name is supplied use the value as name
@@ -212,13 +212,13 @@ public function addConstant($value, $name = '')
}
else
{
- throw new \Exception('No name supplied');
+ throw new Exception('No name supplied');
}
}
if (array_key_exists($name, $this->constants))
{
- throw new \Exception('A constant of the name ('.$name.') does already exist.');
+ throw new Exception('A constant of the name ('.$name.') does already exist.');
}
$this->constants[$name] = $value;
@@ -228,10 +228,11 @@ public function addConstant($value, $name = '')
* Adds a variable to the class
* Throws Exception if the variable does already exist
*
- * @param PhpVariable $variable The variable object to add
+ * @param phpSourcePhpVariable $variable The variable object to add
* @access public
+ * @throws Exception If the variable name already exists
*/
- public function addVariable(PhpVariable $variable)
+ public function addVariable(phpSourcePhpVariable $variable)
{
if ($this->variableExists($variable->getIdentifier()))
{
@@ -245,10 +246,11 @@ public function addVariable(PhpVariable $variable)
* Adds a function to the class
* Overwrites
*
- * @param PhpFunction $function The function object to add
+ * @param phpSourcePhpFunction $function The function object to add
* @access public
+ * @throws Exception If the function name already exists
*/
- public function addFunction(PhpFunction $function)
+ public function addFunction(phpSourcePhpFunction $function)
{
if ($this->functionExists($function->getIdentifier()))
{
View
54 phpSource/PhpDocComment.php → lib/phpSource/PhpDocComment.php
@@ -6,65 +6,65 @@
/**
* Include the needed files
*/
-include_once('PhpDocElement.php');
+require_once dirname(__FILE__).'/PhpDocElement.php';
/**
* Class that represents the source code for a phpdoc comment in php
*
* @package phpSource
* @author Fredrik Wallgren <fredrik@wallgren.me>
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
+  * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class PhpDocComment
+class phpSourcePhpDocComment
{
/**
*
- * @var PhpDocElement A access element
+ * @var phpSourcePhpDocElement A access element
* @access private
*/
private $access;
/**
*
- * @var PhpDocElement A var element
+ * @var phpSourcePhpDocElement A var element
* @access private
*/
private $var;
/**
*
- * @var array Array of PhpDocElements
+ * @var array Array of phpSourcePhpDocElements
* @access private
*/
private $params;
/**
*
- * @var PhpDocElement
+ * @var phpSourcePhpDocElement
*/
private $return;
/**
*
- * @var PhpDocElement
+ * @var phpSourcePhpDocElement
*/
private $package;
/**
*
- * @var PhpDocElement
+ * @var phpSourcePhpDocElement
*/
private $author;
/**
*
- * @var PhpDocElement
+ * @var phpSourcePhpDocElement
*/
private $licence;
/**
*
- * @var array Array of PhpDocElements
+ * @var array Array of phpSourcePhpDocElements
*/
private $throws;
@@ -155,72 +155,72 @@ public function getSource()
/**
*
- * @param PhpDocElement $access Sets the new access
+ * @param phpSourcePhpDocElement $access Sets the new access
*/
- public function setAccess(PhpDocElement $access)
+ public function setAccess(phpSourcePhpDocElement $access)
{
$this->access = $access;
}
/**
*
- * @param PhpDocElement $var Sets the new var
+ * @param phpSourcePhpDocElement $var Sets the new var
*/
- public function setVar(PhpDocElement $var)
+ public function setVar(phpSourcePhpDocElement $var)
{
$this->var = $var;
}
/**
*
- * @param PhpDocElement $package The package element
+ * @param phpSourcePhpDocElement $package The package element
*/
- public function setPackage(PhpDocElement $package)
+ public function setPackage(phpSourcePhpDocElement $package)
{
$this->package = $package;
}
/**
*
- * @param PhpDocElement $author The author element
+ * @param phpSourcePhpDocElement $author The author element
*/
- public function setAuthor(PhpDocElement $author)
+ public function setAuthor(phpSourcePhpDocElement $author)
{
$this->author = $author;
}
/**
*
- * @param PhpDocElement $licence The license elemnt
+ * @param phpSourcePhpDocElement $licence The license elemnt
*/
- public function setLicence(PhpDocElement $licence)
+ public function setLicence(phpSourcePhpDocElement $licence)
{
$this->licence = $licence;
}
/**
*
- * @param PhpDocElement $return Sets the new return
+ * @param phpSourcePhpDocElement $return Sets the new return
*/
- public function setReturn(PhpDocElement $return)
+ public function setReturn(phpSourcePhpDocElement $return)
{
$this->return = $return;
}
/**
*
- * @param PhpDocElement $param Adds a new param
+ * @param phpSourcePhpDocElement $param Adds a new param
*/
- public function addParam(PhpDocElement $param)
+ public function addParam(phpSourcePhpDocElement $param)
{
$this->params[] = $param;
}
/**
*
- * @param PhpDocElement $throws Adds a new throws
+ * @param phpSourcePhpDocElement $throws Adds a new throws
*/
- public function addThrows(PhpDocElement $throws)
+ public function addThrows(phpSourcePhpDocElement $throws)
{
$this->throws[] = $throws;
}
View
2 phpSource/PhpDocElement.php → lib/phpSource/PhpDocElement.php
@@ -10,7 +10,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class PhpDocElement
+class phpSourcePhpDocElement
{
/**
*
View
64 phpSource/PhpDocElementFactory.php → lib/phpSource/PhpDocElementFactory.php
@@ -6,7 +6,7 @@
/**
* Include the needed files
*/
-include_once('PhpDocElement.php');
+require_once dirname(__FILE__).'/PhpDocElement.php';
/**
* Class that contains static methods to create preset doc elements
@@ -15,7 +15,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class PhpDocElementFactory
+class phpSourcePhpDocElementFactory
{
/**
* Creates a param element
@@ -24,35 +24,35 @@ class PhpDocElementFactory
* @param string $name The name of the variable
* @param string $description
*
- * @throws \Exception Throws exception if no name is supplied
+ * @throws Exception Throws exception if no name is supplied
*
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getParam($dataType, $name, $description)
{
if (strlen($name) == 0)
{
- throw new \Exception('A parameter must have a name!');
+ throw new Exception('A parameter must have a name!');
}
if ($name[0] == '$')
{
$name = substr($name, 1);
}
- return new PhpDocElement('param', $dataType, $name, $description);
+ return new phpSourcePhpDocElement('param', $dataType, $name, $description);
}
/**
* Creates a throws element
*
* @param string $exception
* @param string $description
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getThrows($exception, $description)
{
- return new PhpDocElement('throws', $exception, '', $description);
+ return new phpSourcePhpDocElement('throws', $exception, '', $description);
}
/**
@@ -61,127 +61,127 @@ public static function getThrows($exception, $description)
* @param string $dataType The name of the datatype
* @param string $name The name of the variable
* @param string $description Description of the variable
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getVar($dataType, $name, $description)
{
- return new PhpDocElement('var', $dataType, $name, $description);
+ return new phpSourcePhpDocElement('var', $dataType, $name, $description);
}
/**
* Creates a access element
*
* @param string $dataType The name of the datatype
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getAccess($dataType)
{
- return new PhpDocElement('access', $dataType, '', '');
+ return new phpSourcePhpDocElement('access', $dataType, '', '');
}
/**
* Creates a access element with the access public
*
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getPublicAccess()
{
- return new PhpDocElement('access', 'public', '', '');
+ return new phpSourcePhpDocElement('access', 'public', '', '');
}
/**
* Creates a access element with the access private
*
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getPrivateAccess()
{
- return new PhpDocElement('access', 'private', '', '');
+ return new phpSourcePhpDocElement('access', 'private', '', '');
}
/**
* Creates a access element with the access protected
*
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getProtectedAccess()
{
- return new PhpDocElement('access', 'protected', '', '');
+ return new phpSourcePhpDocElement('access', 'protected', '', '');
}
/**
* Creates a package element
*
* @param string $package The name of the package
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getPackage($package)
{
- return new PhpDocElement('package', $package, '', '');
+ return new phpSourcePhpDocElement('package', $package, '', '');
}
/**
* Creates a author element
*
* @param string $author The name of the author
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getAuthor($author)
{
- return new PhpDocElement('author', $author, '', '');
+ return new phpSourcePhpDocElement('author', $author, '', '');
}
/**
* Creates a return element
*
* @param string $dataType The name of the datatype
* @param string $description The description of the return value
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getReturn($dataType, $description)
{
- return new PhpDocElement('return', $dataType, '', $description);
+ return new phpSourcePhpDocElement('return', $dataType, '', $description);
}
/**
* Creates a abstract element
*
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getAbstract()
{
- return new PhpDocElement('abstract', '', '', '');
+ return new phpSourcePhpDocElement('abstract', '', '', '');
}
/**
* Creates a final element
*
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getFinal()
{
- return new PhpDocElement('final', '', '', '');
+ return new phpSourcePhpDocElement('final', '', '', '');
}
/**
* Creates a depricated element
*
* @param string $information The description of why the element is depticated etc.
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getDepricated($information = '')
{
- return new PhpDocElement('depricated', '', '', $information);
+ return new phpSourcePhpDocElement('depricated', '', '', $information);
}
/**
* Creates a licence element
*
* @param string $information Information about the licence
- * @return PhpDocElement The created element
+ * @return phpSourcePhpDocElement The created element
*/
public static function getLicence($information)
{
- return new PhpDocElement('licence', '', '', $information);
+ return new phpSourcePhpDocElement('licence', '', '', $information);
}
}
View
2 phpSource/PhpElement.php → lib/phpSource/PhpElement.php
@@ -10,7 +10,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-abstract class PhpElement
+abstract class phpSourcePhpElement
{
/**
*
View
29 phpSource/PhpFile.php → lib/phpSource/PhpFile.php
@@ -6,8 +6,7 @@
/**
* Include the needed files
*/
-include_once('PhpClass.php');
-include_once('PhpFunction.php'); // Just in case and to show where the functionality is
+require_once dirname(__FILE__).'/PhpClass.php';
/**
* Class that represents the source code for a php file
@@ -17,7 +16,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class PhpFile
+class phpSourcePhpFile
{
/**
*
@@ -35,14 +34,14 @@ class PhpFile
/**
*
- * @var array Array of PhpClass objects
+ * @var array Array of phpSourcePhpClass objects
* @access private
*/
private $classes;
/**
*
- * @var array Array of PhpFunction objects
+ * @var array Array of phpSourcePhpFunction objects
* @access private
*/
private $functions;
@@ -115,13 +114,24 @@ public function addNamespace($namespace)
$this->namespaces[] = $namespace;
}
}
+
+ /**
+ * Checks if the file has a namespace
+ *
+ * @return bool Returns true if a namespace is added to the file
+ */
+ public function hasNamespace()
+ {
+ return (count($this->namespaces) > 0);
+ }
/**
* Adds a class to the file
*
- * @param PhpClass $class The class to add
+ * @param phpSourcePhpClass $class The class to add
+ * @throws Exception If the class already exists
*/
- public function addClass(PhpClass $class)
+ public function addClass(phpSourcePhpClass $class)
{
if ($this->classExists($class->getIdentifier()))
{
@@ -134,9 +144,10 @@ public function addClass(PhpClass $class)
/**
* Adds a global function to the file, should not be used, classes rocks :)
*
- * @param PhpFunction $function The function to add
+ * @param phpSourcePhpFunction $function The function to add
+ * @throws Exception If the function already exists
*/
- public function addFunction(PhpFunction $function)
+ public function addFunction(phpSourcePhpFunction $function)
{
if ($this->functionExists($function->getIdentifier()))
{
View
14 phpSource/PhpFunction.php → lib/phpSource/PhpFunction.php
@@ -6,9 +6,9 @@
/**
* Include the needed files
*/
-include_once('PhpElement.php');
-include_once('PhpDocComment.php');
-include_once('PhpVariable.php');
+require_once dirname(__FILE__).'/PhpElement.php';
+require_once dirname(__FILE__).'/PhpDocComment.php';
+require_once dirname(__FILE__).'/PhpVariable.php';
/**
* Class that represents the source code for a function in php
@@ -17,7 +17,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class PhpFunction extends PhpElement
+class phpSourcePhpFunction extends phpSourcePhpElement
{
/**
*
@@ -35,7 +35,7 @@ class PhpFunction extends PhpElement
/**
*
- * @var PhpDocComment A comment in phpdoc format that describes the function
+ * @var phpSourcePhpDocComment A comment in phpdoc format that describes the function
* @access private
*/
private $comment;
@@ -46,9 +46,9 @@ class PhpFunction extends PhpElement
* @param string $identifier
* @param string $params
* @param string $source
- * @param PhpDocComment $comment
+ * @param phpSourcePhpDocComment $comment
*/
- function __construct($access, $identifier, $params, $source, PhpDocComment $comment = null)
+ function __construct($access, $identifier, $params, $source, phpSourcePhpDocComment $comment = null)
{
$this->access = $access;
$this->identifier = $identifier;
View
10 phpSource/PhpVariable.php → lib/phpSource/PhpVariable.php
@@ -6,7 +6,7 @@
/**
* Include the needed files
*/
-include_once('PhpElement.php');
+require_once dirname(__FILE__).'/PhpElement.php';
/**
* Class that represents the source code for a variable in php
@@ -15,11 +15,11 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class PhpVariable extends PhpElement
+class phpSourcePhpVariable extends phpSourcePhpElement
{
/**
*
- * @var PhpDocComment A comment in phpdoc format that describes the variable
+ * @var phpSourcePhpDocComment A comment in phpdoc format that describes the variable
* @access private
*/
private $comment;
@@ -36,9 +36,9 @@ class PhpVariable extends PhpElement
* @param string $access
* @param string $identifier
* @param string $initialization The value to set the variable at initialization
- * @param PhpDocComment $comment
+ * @param phpSourcePhpDocComment $comment
*/
- function __construct($access, $identifier, $initialization = '', PhpDocComment $comment = null)
+ function __construct($access, $identifier, $initialization = '', phpSourcePhpDocComment $comment = null)
{
$this->comment = $comment;
$this->access = $access;
View
113 src/ComplexType.php
@@ -0,0 +1,113 @@
+<?php
+
+/**
+ * @package Wsdl2PhpGenerator
+ */
+
+/**
+ * @see wsdl2phpType
+ */
+require_once dirname(__FILE__).'/Type.php';
+
+/**
+ * @see wsdl2phpVariable
+ */
+require_once dirname(__FILE__).'/Variable.php';
+
+/**
+ * ComplexType
+ *
+ * @package Wsdl2PhpGenerator
+ * @author Fredrik Wallgren <fredrik@wallgren.me>
+@license http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+class wsdl2phpComplexType extends wsdl2phpType
+{
+ /**
+ *
+ * @var array The members in the type
+ */
+ private $members;
+
+ /**
+ * Construct the object
+ *
+ * @param string $name The identifier for the class
+ * @param string $restriction The restriction(datatype) of the values
+ */
+ function __construct($name)
+ {
+ parent::__construct($name, null);
+ $this->members = array();
+ }
+
+ /**
+ * Implements the loading of the class object
+ * @throws wsdl2phpException if the class is already generated(not null)
+ */
+ protected function generateClass()
+ {
+ if ($this->class != null)
+ {
+ throw new wsdl2phpException("The class has already been generated");
+ }
+
+ $config = wsdl2phpGenerator::getInstance()->getConfig();
+
+ $class = new phpSourcePhpClass($this->phpIdentifier, $config->getClassExists());
+
+ $constructorComment = new phpSourcePhpDocComment();
+ $constructorComment->setAccess(phpSourcePhpDocElementFactory::getPublicAccess());
+ $constructorSource = '';
+ $constructorParameters = '';
+
+ // Add member variables
+ foreach ($this->members as $member)
+ {
+ $type = '';
+
+ try
+ {
+ $type = wsdl2phpValidator::validateType($member->getType());
+ }
+ catch (wsdl2phpValidationException $e)
+ {
+ $type .= 'Custom';
+ }
+
+ $name = wsdl2phpValidator::validateNamingConvention($member->getName());
+ $comment = new phpSourcePhpDocComment();
+ $comment->setVar(phpSourcePhpDocElementFactory::getVar($type, $name, ''));
+ $comment->setAccess(phpSourcePhpDocElementFactory::getPublicAccess());
+ $var = new phpSourcePhpVariable('public', $name, '', $comment);
+ $class->addVariable($var);
+
+ $constructorSource .= ' $this->'.$name.' = $'.$name.';'.PHP_EOL;
+ $constructorComment->addParam(phpSourcePhpDocElementFactory::getParam($type, $name, ''));
+ $constructorComment->setAccess(phpSourcePhpDocElementFactory::getPublicAccess());
+ $constructorParameters .= ', $'.$name;
+ }
+
+ $constructorParameters = substr($constructorParameters, 2); // Remove first comma
+ $function = new phpSourcePhpFunction('public', '__construct', $constructorParameters, $constructorSource, $constructorComment);
+
+ // Only add the constructor if type constructor is selected
+ if ($config->getNoTypeConstructor() == false)
+ {
+ $class->addFunction($function);
+ }
+
+ $this->class = $class;
+ }
+
+ /**
+ * Adds the member. Owerwrites members with same name
+ *
+ * @param string $type
+ * @param string $name
+ */
+ public function addMember($type, $name)
+ {
+ $this->members[$name] = new wsdl2phpVariable($type, $name);
+ }
+}
View
2 Wsdl2PhpConfig.php → src/Config.php
@@ -10,7 +10,7 @@
* @author Fredrik Wallgren <fredrik@wallgren.me>
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-class Wsdl2PhpConfig
+class wsdl2phpConfig
{
/**
*
View
98 src/DocumentationManager.php
@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * @package Wsdl2PhpGenerator
+ */
+
+/**
+ * Very stupid datatype to use instead of array
+ *
+ * @package Wsdl2PhpGenerator
+ * @author Fredrik Wallgren <fredrik@wallgren.me>
+@license http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+class wsdl2phpDocumentationManager
+{
+ /**
+ *
+ * @var string The documentation for the service
+ */
+ private $serviceDescription;
+
+ /**
+ * The key is the function name
+ *
+ * @var array An array with strings with function descriptions
+ */
+ private $functionDescriptions;
+
+ public function __construct()
+ {
+ $this->serviceDescription = '';
+ $this->functionDescriptions = array();
+ }
+
+ /**
+ * Loads all documentation into the instance
+ *
+ * @param DOMDocument $dom The wsdl file dom document
+ */
+ public function loadDocumentation(DOMDocument $dom)
+ {
+ $docList = $dom->getElementsByTagName('documentation');
+
+ foreach($docList as $item)
+ {
+ if($item->parentNode->localName == 'service')
+ {
+ $this->serviceDescription = trim($item->parentNode->nodeValue);
+ }
+ else if($item->parentNode->localName == 'operation')
+ {
+ $name = $item->parentNode->getAttribute('name');
+ $this->setFunctionDescription($name, trim($item->nodeValue));
+ }
+ }
+ }
+
+ /**
+ *
+ * @return string The documentation for the service
+ */
+ public function getServiceDescription()
+ {
+ return $this->serviceDescription;
+ }
+
+ /**
+ *
+ * @param string $serviceDescription The new documentation
+ */
+ public function setServiceDescription($serviceDescription)
+ {
+ $this->serviceDescription = $serviceDescription;
+ }
+
+ /**
+ *
+ * @param string $function The name of the function
+ * @param string $description The documentation
+ */
+ public function setFunctionDescription($function, $description)
+ {
+ $this->functionDescriptions[$function] = $description;
+ }
+
+ /**
+ *
+ * @param string $function
+ * @return string The description
+ */
+ public function getFunctionDescription($function)
+ {
+ $ret = '';
+ $ret = @$this->functionDescriptions[$function];
+
+ return $ret;
+ }
+}
View
116 src/Enum.php
@@ -0,0 +1,116 @@
+<?php
+
+/**
+ * @package Wsdl2PhpGenerator
+ */
+
+/**
+ * @see wsdl2phpType
+ */
+require_once dirname(__FILE__).'/Type.php';
+
+/**
+ * Enum represents a simple type with enumerated values
+ *
+ * @package Wsdl2PhpGenerator
+ * @author Fredrik Wallgren <fredrik@wallgren.me>
+@license http://www.opensource.org/licenses/mit-license.php MIT License
+ */