Skip to content

Commit

Permalink
Added the ability to ignore duplicate class names when generating cl…
Browse files Browse the repository at this point in the history
…asses from the WSDL.

git-svn-id: http://google-api-adwords-php.googlecode.com/svn/trunk@206 bd846e36-b2c2-11de-ae6a-cd50274c347e
  • Loading branch information
eric.koleda@google.com authored and aminin committed Dec 21, 2011
1 parent 4833023 commit 25d86b6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
21 changes: 17 additions & 4 deletions build_lib/WSDLInterpreter/WSDLInterpreter.php
Expand Up @@ -88,6 +88,13 @@ class WSDLInterpreter
*/
private $_classmap = array();

/**
* Array of types that shouldn't be checked for class name uniqueness
* @var array
* @access private
*/
private $_skipClassNameCheckTypes = array();

/**
* Array of sources for WSDL message classes
* @var array
Expand Down Expand Up @@ -190,7 +197,7 @@ class WSDLInterpreter
*/
public function __construct($wsdl, $soapClientClassName, $classmap,
$serviceName, $version, $author, $package, $soapClientClassPath, $proxy,
$enablePseudoNamespaces)
$enablePseudoNamespaces, $skipClassNameCheckTypes)
{
try {
$this->_wsdl = $wsdl;
Expand All @@ -203,8 +210,13 @@ public function __construct($wsdl, $soapClientClassName, $classmap,
$this->_enablePseudoNamespaces = isset($enablePseudoNamespaces) ?
$enablePseudoNamespaces : false;
if (!$this->_enablePseudoNamespaces) {
// Only use the classmap if pseudo-namespaces aren't enabled.
$this->_classmap = $classmap;
// Only use if pseudo-namespaces aren't enabled.
if (isset($classmap)) {
$this->_classmap = $classmap;
}
if (isset($skipClassNameCheckTypes)) {
$this->_skipClassNameCheckTypes = $skipClassNameCheckTypes;
}
}
$this->_soapClientClassPath = $soapClientClassPath;

Expand Down Expand Up @@ -326,7 +338,8 @@ private function _validateClassName($className, $addToClassMap = true,
$validClassName = $this->_package . '_' . $validClassName;
}

if (class_exists($validClassName)) {
if (!in_array($validClassName, $this->_skipClassNameCheckTypes)
&& class_exists($validClassName)) {
throw new Exception("Class ".$validClassName." already defined.".
" Cannot redefine class with class loaded.");
}
Expand Down
23 changes: 22 additions & 1 deletion build_lib/Wsdl2PhpTask.php
Expand Up @@ -69,6 +69,15 @@ class Wsdl2PhpTask extends Task {
*/
private $classmap = NULL;

/**
* The WSDL types that shouldn't have their class names checked for
* uniqueness.
* @var array the WSDL types that shouldn't have their class names checked for
* uniqueness.
* @access private
*/
private $skipClassNameCheckTypes = NULL;

/**
* The author of the service to be included in the file header.
* @var string the author of the service
Expand Down Expand Up @@ -160,6 +169,18 @@ public function setClassmap($classmap) {
}
}

/**
* The setter for the attribute <var>$skipClassNameCheckTypes</var>.
* @param string $skipClassNameCheckTypes comma separated list of the type
* names
*/
public function setSkipClassNameCheckTypes($skipClassNameCheckTypes) {
if (!empty($skipClassNameCheckTypes)) {
$this->skipClassNameCheckTypes = array_map('trim',
explode(',', $skipClassNameCheckTypes));
}
}

/**
* The setter for the attribute <var>$author</var>.
* @param string $author the author for the file header of the generated file
Expand Down Expand Up @@ -224,7 +245,7 @@ public function main() {
new WSDLInterpreter($this->url, $this->soapClientClassName,
$this->classmap, $this->serviceName, $this->version, $this->author,
$this->package, $this->soapClientClassPath, $this->proxy,
$this->enablePseudoNamespaces);
$this->enablePseudoNamespaces, $this->skipClassNameCheckTypes);
$wsdlInterpreter->savePHP($this->outputDir);
print 'Done: ' . $this->url . "\n";
}
Expand Down

0 comments on commit 25d86b6

Please sign in to comment.