Пример #1
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);
           }
       }
   }
Пример #2
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);
         }
     }
 }
Пример #3
0
 /**
  * Adds a function to the class
  * Overwrites
  *
  * @param PhpFunction $function The function object to add
  * @access public
  * @throws Exception If the function name already exists
  */
 public function addFunction(PhpFunction $function)
 {
     if ($this->functionExists($function->getIdentifier())) {
         throw new Exception('A function of the name (' . $function->getIdentifier() . ') does already exist.');
     }
     $this->functions[$function->getIdentifier()] = $function;
 }
Пример #4
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);
       $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);
           }
       }
   }