コード例 #1
0
 /**
  * Implements the loading of the class object
  *
  * @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");
     }
     // Determine parent class
     $classBaseType = null;
     // If we have a base type which is different than the current class then extend that.
     // It is actually possible to have different classes with the same name as PHP SoapClient has a poor
     // understanding of namespaces. Two types with the same name but in different namespaces will have the same
     // identifier.
     if ($this->baseType !== null && $this->baseType !== $this) {
         $classBaseType = $this->baseType->getPhpIdentifier();
     }
     $class = new PhpClass($this->phpIdentifier, false, $classBaseType, null, false, $this->abstract);
     $constructorComment = new PhpDocComment();
     $constructorSource = '';
     $constructorParameters = array();
     $accessors = array();
     // Add base type members to constructor parameter list first and call base class constructor
     $parentMembers = $this->getBaseTypeMembers($this);
     if (!empty($parentMembers)) {
         foreach ($parentMembers as $member) {
             $type = Validator::validateType($member->getType());
             $name = Validator::validateAttribute($member->getName());
             if (!$member->getNullable()) {
                 $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
                 $constructorParameters[$name] = Validator::validateTypeHint($type);
             }
         }
         $constructorSource .= '  parent::__construct(' . $this->buildParametersString($constructorParameters, false) . ');' . PHP_EOL;
     }
     // Add member variables
     foreach ($this->members as $member) {
         $type = Validator::validateType($member->getType());
         $name = Validator::validateAttribute($member->getName());
         $typeHint = Validator::validateTypeHint($type);
         $comment = new PhpDocComment();
         $comment->setVar(PhpDocElementFactory::getVar($type, $name, ''));
         $var = new PhpVariable('protected', $name, 'null', $comment);
         $class->addVariable($var);
         if (!$member->getNullable()) {
             if ($type == '\\DateTime') {
                 if ($this->config->get('constructorParamsDefaultToNull')) {
                     $constructorSource .= '  $this->' . $name . ' = $' . $name . ' ? $' . $name . '->format(\\DateTime::ATOM) : null;' . PHP_EOL;
                 } else {
                     $constructorSource .= '  $this->' . $name . ' = $' . $name . '->format(\\DateTime::ATOM);' . PHP_EOL;
                 }
             } else {
                 $constructorSource .= '  $this->' . $name . ' = $' . $name . ';' . PHP_EOL;
             }
             $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
             $constructorParameters[$name] = $typeHint;
         }
         $getterComment = new PhpDocComment();
         $getterComment->setReturn(PhpDocElementFactory::getReturn($type, ''));
         $getterCode = '';
         if ($type == '\\DateTime') {
             $getterCode = '  if ($this->' . $name . ' == null) {' . PHP_EOL . '    return null;' . PHP_EOL . '  } else {' . PHP_EOL . '    try {' . PHP_EOL . '      return new \\DateTime($this->' . $name . ');' . PHP_EOL . '    } catch (\\Exception $e) {' . PHP_EOL . '      return false;' . PHP_EOL . '    }' . PHP_EOL . '  }' . PHP_EOL;
         } else {
             $getterCode = '  return $this->' . $name . ';' . PHP_EOL;
         }
         $getter = new PhpFunction('public', 'get' . ucfirst($name), '', $getterCode, $getterComment);
         $accessors[] = $getter;
         $setterComment = new PhpDocComment();
         $setterComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
         $setterComment->setReturn(PhpDocElementFactory::getReturn($this->phpNamespacedIdentifier, ''));
         $setterCode = '';
         if ($type == '\\DateTime') {
             if ($member->getNullable()) {
                 $setterCode = '  if ($' . $name . ' == null) {' . PHP_EOL . '   $this->' . $name . ' = null;' . PHP_EOL . '  } else {' . PHP_EOL . '    $this->' . $name . ' = $' . $name . '->format(\\DateTime::ATOM);' . PHP_EOL . '  }' . PHP_EOL;
             } else {
                 $setterCode = '  $this->' . $name . ' = $' . $name . '->format(\\DateTime::ATOM);' . PHP_EOL;
             }
         } else {
             $setterCode = '  $this->' . $name . ' = $' . $name . ';' . PHP_EOL;
         }
         $setterCode .= '  return $this;' . PHP_EOL;
         $setter = new PhpFunction('public', 'set' . ucfirst($name), $this->buildParametersString(array($name => $typeHint), true, $member->getNullable() && !empty($typeHint)), $setterCode, $setterComment);
         $accessors[] = $setter;
     }
     $constructor = new PhpFunction('public', '__construct', $this->buildParametersString($constructorParameters, true, $this->config->get('constructorParamsDefaultToNull')), $constructorSource, $constructorComment);
     $class->addFunction($constructor);
     foreach ($accessors as $accessor) {
         $class->addFunction($accessor);
     }
     $this->class = $class;
 }
コード例 #2
0
 /**
  * Implements the loading of the class object
  *
  * @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");
     }
     $class = new PhpClass($this->phpIdentifier, false, $this->baseType !== null ? $this->baseType->getPhpIdentifier() : '');
     $constructorComment = new PhpDocComment();
     $constructorSource = '';
     $constructorParameters = array();
     $accessors = array();
     // Add base type members to constructor parameter list first and call base class constructor
     $parentMembers = $this->getBaseTypeMembers($this);
     if (!empty($parentMembers)) {
         foreach ($parentMembers as $member) {
             $type = Validator::validateType($member->getType());
             $name = Validator::validateAttribute($member->getName());
             if (!$member->getNullable()) {
                 $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
                 $constructorParameters[$name] = Validator::validateTypeHint($type);
             }
         }
         $constructorSource .= '  parent::__construct(' . $this->buildParametersString($constructorParameters, false) . ');' . PHP_EOL;
     }
     // Add member variables
     foreach ($this->members as $member) {
         $type = Validator::validateType($member->getType());
         $name = Validator::validateAttribute($member->getName());
         $typeHint = Validator::validateTypeHint($type);
         $comment = new PhpDocComment();
         $comment->setVar(PhpDocElementFactory::getVar($type, $name, ''));
         $var = new PhpVariable('protected', $name, 'null', $comment);
         $class->addVariable($var);
         if (!$member->getNullable()) {
             if ($type == '\\DateTime') {
                 if ($this->config->get('constructorParamsDefaultToNull')) {
                     // GT Mod - removed DateTime::ATOM date (not compatible with apollo) with Y-m-d\TH:i:s .
                     $constructorSource .= '  $this->' . $name . ' = $' . $name . ' ? $' . $name . '->format(\'Y-m-d\\TH:i:s\\Z\') : null;' . PHP_EOL;
                 } else {
                     // GT Mod - removed DateTime::ATOM date (not compatible with apollo) with Y-m-d\TH:i:s .
                     $constructorSource .= '  $this->' . $name . ' = $' . $name . '->format(\'Y-m-d\\TH:i:s\\Z\');' . PHP_EOL;
                 }
             } else {
                 $constructorSource .= '  $this->' . $name . ' = $' . $name . ';' . PHP_EOL;
             }
             $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
             $constructorParameters[$name] = $typeHint;
         }
         $getterComment = new PhpDocComment();
         $getterComment->setReturn(PhpDocElementFactory::getReturn($type, ''));
         $getterCode = '';
         if ($type == '\\DateTime') {
             $getterCode = '  if ($this->' . $name . ' == null) {' . PHP_EOL . '    return null;' . PHP_EOL . '  } else {' . PHP_EOL . '    try {' . PHP_EOL . '      return new \\DateTime($this->' . $name . ');' . PHP_EOL . '    } catch (\\Exception $e) {' . PHP_EOL . '      return false;' . PHP_EOL . '    }' . PHP_EOL . '  }' . PHP_EOL;
         } else {
             $getterCode = '  return $this->' . $name . ';' . PHP_EOL;
         }
         $getter = new PhpFunction('public', 'get' . ucfirst($name), '', $getterCode, $getterComment);
         $accessors[] = $getter;
         $setterComment = new PhpDocComment();
         $setterComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
         $setterComment->setReturn(PhpDocElementFactory::getReturn($this->phpNamespacedIdentifier, ''));
         $setterCode = '';
         if ($type == '\\DateTime') {
             // GT Mod - removed DateTime::ATOM date (not compatible with apollo) with Y-m-d\TH:i:sZ .
             $setterCode = '  $this->' . $name . ' = $' . $name . '->format(\'Y-m-d\\TH:i:s\\Z\');' . PHP_EOL;
         } else {
             $setterCode = '  $this->' . $name . ' = $' . $name . ';' . PHP_EOL;
         }
         $setterCode .= '  return $this;' . PHP_EOL;
         $setter = new PhpFunction('public', 'set' . ucfirst($name), $this->buildParametersString(array($name => $typeHint)), $setterCode, $setterComment);
         $accessors[] = $setter;
     }
     $constructor = new PhpFunction('public', '__construct', $this->buildParametersString($constructorParameters, true, $this->config->get('constructorParamsDefaultToNull')), $constructorSource, $constructorComment);
     $class->addFunction($constructor);
     foreach ($accessors as $accessor) {
         $class->addFunction($accessor);
     }
     $this->class = $class;
 }
コード例 #3
0
   /**
    * Generates the class if not already generated
    */
   public function generateClass()
   {
       // Add prefix and suffix
       $name = $this->config->getPrefix() . $this->identifier . $this->config->getSuffix();
       // Generate a valid classname
       $name = Validator::validateClass($name);
       // uppercase the name
       $name = ucfirst($name);
       // Create the class object
       $comment = new PhpDocComment($this->description);
       $this->class = new PhpClass($name, $this->config->getClassExists(), '\\SoapClient', $comment);
       // Create the constructor
       $comment = new PhpDocComment();
       $comment->addParam(PhpDocElementFactory::getParam('array', 'options', 'A array of config values'));
       $comment->addParam(PhpDocElementFactory::getParam('string', 'wsdl', 'The wsdl file to use'));
       $comment->setAccess(PhpDocElementFactory::getPublicAccess());
       $source = '  foreach (self::$classmap as $key => $value) {
   if (!isset($options[\'classmap\'][$key])) {
     $options[\'classmap\'][$key] = $value;
   }
 }
 ' . $this->generateServiceOptions() . '
 parent::__construct($wsdl, $options);' . PHP_EOL;
       $function = new PhpFunction('public', '__construct', 'array $options = array(), $wsdl = \'' . $this->config->getInputFile() . '\'', $source, $comment);
       // Add the constructor
       $this->class->addFunction($function);
       // Generate the classmap
       $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 $type) {
           if ($type instanceof ComplexType) {
               $init .= "  '" . $type->getIdentifier() . "' => '" . $this->config->getNamespaceName() . "\\" . $type->getPhpIdentifier() . "'," . PHP_EOL;
           }
       }
       $init = substr($init, 0, strrpos($init, ','));
       $init .= ')';
       $var = new PhpVariable('private static', $name, $init, $comment);
       // Add the classmap variable
       $this->class->addVariable($var);
       // Add all methods
       foreach ($this->operations as $operation) {
           $name = Validator::validateOperation($operation->getName());
           $comment = new PhpDocComment($operation->getDescription());
           $comment->setAccess(PhpDocElementFactory::getPublicAccess());
           $comment->setReturn(PhpDocElementFactory::getReturn($operation->getReturns(), ''));
           foreach ($operation->getParams() as $param => $hint) {
               $arr = $operation->getPhpDocParams($param, $this->types);
               $comment->addParam(PhpDocElementFactory::getParam($arr['type'], $arr['name'], $arr['desc']));
           }
           $source = '  return $this->__soapCall(\'' . $operation->getName() . '\', array(' . $operation->getParamStringNoTypeHints() . '));' . PHP_EOL;
           $paramStr = $operation->getParamString($this->types);
           $function = new PhpFunction('public', $name, $paramStr, $source, $comment);
           if ($this->class->functionExists($function->getIdentifier()) == false) {
               $this->class->addFunction($function);
           }
       }
   }
コード例 #4
0
 /**
  * Implements the loading of the class object
  *
  * @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");
     }
     $class = new PhpClass($this->phpIdentifier, $this->config->getClassExists(), $this->baseType !== null ? $this->baseType->getPhpIdentifier() : '');
     // Add the base class as a dependency. Otherwise we risk referencing an undefined class.
     if (!empty($this->baseType) && !$this->config->getOneFile() && !$this->config->getNoIncludes()) {
         $class->addDependency($this->baseType->getIdentifier() . '.php');
     }
     $constructorComment = new PhpDocComment();
     $constructorComment->setAccess(PhpDocElementFactory::getPublicAccess());
     $constructorSource = '';
     $constructorParameters = '';
     $accessors = array();
     // Add base type members to constructor parameter list first and call base class constructor
     if ($this->baseType !== null) {
         foreach ($this->baseType->getMembers() as $member) {
             $type = Validator::validateType($member->getType());
             $name = Validator::validateAttribute($member->getName());
             if (!$member->getNillable()) {
                 $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
                 $constructorComment->setAccess(PhpDocElementFactory::getPublicAccess());
                 $constructorParameters .= ', $' . $name;
             }
         }
         $constructorSource .= '  parent::__construct(' . substr($constructorParameters, 2) . ');' . PHP_EOL;
     }
     // Add member variables
     foreach ($this->members as $member) {
         $type = Validator::validateType($member->getType());
         $name = Validator::validateAttribute($member->getName());
         $comment = new PhpDocComment();
         $comment->setVar(PhpDocElementFactory::getVar($type, $name, ''));
         $comment->setAccess(PhpDocElementFactory::getPublicAccess());
         $var = new PhpVariable('public', $name, 'null', $comment);
         $class->addVariable($var);
         if (!$member->getNillable()) {
             $constructorSource .= '  $this->' . $name . ' = $' . $name . ';' . PHP_EOL;
             $constructorComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
             $constructorComment->setAccess(PhpDocElementFactory::getPublicAccess());
             $constructorParameters .= ', $' . $name;
             if ($this->config->getConstructorParamsDefaultToNull()) {
                 $constructorParameters .= ' = null';
             }
             if ($this->config->getCreateAccessors()) {
                 $getterComment = new PhpDocComment();
                 $getterComment->setReturn(PhpDocElementFactory::getReturn($type, ''));
                 $getter = new PhpFunction('public', 'get' . ucfirst($name), '', '  return $this->' . $name . ';' . PHP_EOL, $getterComment);
                 $accessors[] = $getter;
                 $setterComment = new PhpDocComment();
                 $setterComment->addParam(PhpDocElementFactory::getParam($type, $name, ''));
                 $setter = new PhpFunction('public', 'set' . ucfirst($name), '$' . $name, '  $this->' . $name . ' = $' . $name . ';' . PHP_EOL, $setterComment);
                 $accessors[] = $setter;
             }
         }
     }
     $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);
     }
     foreach ($accessors as $accessor) {
         $class->addFunction($accessor);
     }
     $this->class = $class;
 }
コード例 #5
0
 /**
  * Generates the class if not already generated
  */
 public function generateClass()
 {
     $name = $this->identifier;
     // Generate a valid classname
     $name = Validator::validateClass($name, $this->config->get('namespaceName'));
     // uppercase the name
     $name = ucfirst($name);
     // Create the class object
     $comment = new PhpDocComment($this->description);
     $extends = $this->config->get('reactSoapClientClass');
     if (empty($extends)) {
         $extends = $this->config->get('soapClientClass');
     }
     $this->class = new PhpClass($name, false, $extends, $comment);
     // Create the constructor
     $comment = new PhpDocComment('Constructor which merges options from generator with runtime options.');
     $comment->addParam(PhpDocElementFactory::getParam('string', 'wsdl', 'The wsdl file to use'));
     $comment->addParam(PhpDocElementFactory::getParam('\\Clue\\React\\Buzz\\Browser', 'browser', 'The browser instance to communicate through'));
     $comment->addParam(PhpDocElementFactory::getParam('array', 'options', 'An array with SoapClient configuration values'));
     $source = '
 foreach (self::$classmap as $key => $value) {
     if (!isset($options[\'classmap\'][$key])) {
         $options[\'classmap\'][$key] = $value;
     }
 }' . PHP_EOL;
     $source .= '    $soapOptions = ' . str_replace('  ', '        ', var_export($this->config->get('soapClientOptions'), true)) . ';' . PHP_EOL;
     $source .= '    $options = array_merge($soapOptions, $options);' . PHP_EOL;
     $source .= '    parent::__construct($wsdl, $browser, $options);' . PHP_EOL;
     $function = new PhpFunction('public', '__construct', '$wsdl, \\Clue\\React\\Buzz\\Browser $browser, array $options = array()', $source, $comment);
     // Add the constructor
     $this->class->addFunction($function);
     $comment = new PhpDocComment('Name of WSDL file used by the generator');
     //$const = new PhpConst('WSDL_FILE', $this->config->get('inputFile'), $comment);
     $this->class->addConstant($this->config->get('inputFile'), 'WSDL_FILE');
     // Generate the classmap
     $name = 'classmap';
     $comment = new PhpDocComment();
     $comment->setVar(PhpDocElementFactory::getVar('array', $name, 'The defined classes'));
     $init = array();
     foreach ($this->types as $type) {
         if ($type instanceof ComplexType) {
             $init[$type->getIdentifier()] = $this->config->get('namespaceName') . "\\" . $type->getPhpIdentifier();
         }
     }
     $var = new PhpVariable('private static', $name, str_replace('  ', '    ', var_export($init, true)), $comment);
     // Add the classmap variable
     $this->class->addVariable($var);
     // Add all methods
     foreach ($this->operations as $operation) {
         $name = Validator::validateOperation($operation->getName());
         $comment = new PhpDocComment($operation->getDescription());
         $comment->setReturn(PhpDocElementFactory::getReturn('\\React\\Promise\\PromiseInterface', 'Resolves to ' . $operation->getReturns()));
         foreach ($operation->getParams() as $param => $hint) {
             $arr = $operation->getPhpDocParams($param, $this->types);
             $comment->addParam(PhpDocElementFactory::getParam($arr['type'], $arr['name'], $arr['desc']));
         }
         $source = '    return $this->soapCall(\'' . $operation->getName() . '\', array(' . $operation->getParamStringNoTypeHints() . '));' . PHP_EOL;
         $paramStr = $operation->getParamString($this->types);
         $function = new PhpFunction('public', $name, $paramStr, $source, $comment);
         if ($this->class->functionExists($function->getIdentifier()) == false) {
             $this->class->addFunction($function);
         }
     }
 }
コード例 #6
0
ファイル: Service.php プロジェクト: tbl0605/wsdl2phpgenerator
   /**
    * Generates the class if not already generated
    */
   public function generateClass()
   {
       $name = $this->identifier;
       // Generate a valid classname
       $name = Validator::validateClass($name, $this->config->get('namespaceName'));
       // uppercase the name
       $name = ucfirst($name);
       // Create the class object
       $comment = new PhpDocComment($this->description);
       $this->class = new PhpClass($name, false, $this->config->get('soapClientClass'), $comment);
       // Create the constructor
       $comment = new PhpDocComment();
       $comment->addParam(PhpDocElementFactory::getParam('array', 'options', 'A array of config values'));
       $comment->addParam(PhpDocElementFactory::getParam('string', 'wsdl', 'The wsdl file to use'));
       $source = '
 foreach (self::$classmap as $key => $value) {
   if (!isset($options[\'classmap\'][$key])) {
     $options[\'classmap\'][$key] = $value;
   }
 }' . PHP_EOL;
       $source .= '  $options = array_merge(' . var_export($this->config->get('soapClientOptions'), true) . ', $options);' . PHP_EOL;
       $source .= '  if (!$wsdl) {' . PHP_EOL;
       $source .= '    $wsdl = \'' . $this->config->get('inputFile') . '\';' . PHP_EOL;
       $source .= '  }' . PHP_EOL;
       $source .= '  parent::__construct($wsdl, $options);' . PHP_EOL;
       $function = new PhpFunction('public', '__construct', 'array $options = array(), $wsdl = null', $source, $comment);
       // Add the constructor
       $this->class->addFunction($function);
       // Generate the classmap
       $name = 'classmap';
       $comment = new PhpDocComment();
       $comment->setVar(PhpDocElementFactory::getVar('array', $name, 'The defined classes'));
       $init = array();
       foreach ($this->types as $type) {
           if ($type instanceof ComplexType) {
               $init[$type->getIdentifier()] = $this->config->get('namespaceName') . "\\" . $type->getPhpIdentifier();
           }
       }
       $var = new PhpVariable('private static', $name, var_export($init, true), $comment);
       // Add the classmap variable
       $this->class->addVariable($var);
       // Add all methods
       foreach ($this->operations as $operation) {
           $name = Validator::validateOperation($operation->getName());
           $comment = new PhpDocComment($operation->getDescription());
           $comment->setReturn(PhpDocElementFactory::getReturn($operation->getReturns(), ''));
           foreach ($operation->getParams() as $param => $hint) {
               $arr = $operation->getPhpDocParams($param, $this->types);
               $comment->addParam(PhpDocElementFactory::getParam($arr['type'], $arr['name'], $arr['desc']));
           }
           $source = '  return $this->__soapCall(\'' . $operation->getName() . '\', array(' . $operation->getParamStringNoTypeHints() . '));' . PHP_EOL;
           $paramStr = $operation->getParamString($this->types);
           $function = new PhpFunction('public', $name, $paramStr, $source, $comment);
           if ($this->class->functionExists($function->getIdentifier()) == false) {
               $this->class->addFunction($function);
           }
       }
   }