/**
  * Returns a filter matching the provided configuration.
  *
  * @param ConfigInterface $config The configuration to create a filter for.
  * @return FilterInterface A matching filter.
  */
 public function create(ConfigInterface $config)
 {
     $operationNames = $config->get('operationNames');
     if (!empty($operationNames)) {
         return new ServiceOperationFilter($config);
     } else {
         return new DefaultFilter();
     }
 }
 public function __construct(ConfigInterface $config, $wsdlUrl)
 {
     $this->config = $config;
     try {
         $this->soapClient = new SoapClient($wsdlUrl, $this->config->getOptionFeatures());
         parent::__construct($wsdlUrl);
     } catch (SoapFault $e) {
         throw new Exception('Unable to load WSDL: ' . $e->getMessage(), $e->getCode(), $e);
     }
 }
Ejemplo n.º 3
0
 /**
  * The minimum construction
  *
  * @param ConfigInterface $config The configuration
  * @param string $name The identifier for the type
  * @param string $datatype The restriction(DataType)
  */
 public function __construct(ConfigInterface $config, $name, $datatype)
 {
     $this->config = $config;
     $this->class = null;
     $this->datatype = $datatype;
     $this->identifier = $name;
     // Add prefix and suffix
     $name = $this->config->getPrefix() . $this->identifier . $this->config->getSuffix();
     $name = Validator::validateClass($name);
     $this->phpIdentifier = $name;
 }
Ejemplo n.º 4
0
 /**
  * The minimum construction
  *
  * @param ConfigInterface $config The configuration
  * @param string $name The identifier for the type
  * @param string $datatype The restriction(DataType)
  */
 public function __construct(ConfigInterface $config, $name, $datatype)
 {
     $this->config = $config;
     $this->class = null;
     $this->datatype = $datatype;
     $this->identifier = $name;
     $this->phpIdentifier = Validator::validateClass($name, $this->config->get('namespaceName'));
     $this->phpNamespacedIdentifier = $name;
     if ($this->config->get('namespaceName')) {
         $this->phpNamespacedIdentifier = '\\' . $this->config->get('namespaceName') . '\\' . $name;
     }
 }
Ejemplo n.º 5
0
 public function __construct(ConfigInterface $config, $wsdlUrl)
 {
     $this->config = $config;
     // Never use PHP WSDL cache to when creating the SoapClient instance used to extract information.
     // Otherwise we risk generating code for a WSDL that is no longer valid.
     $options = array_merge($this->config->get('soapClientOptions'), array('cache_wsdl' => WSDL_CACHE_NONE));
     try {
         $soapClientClass = new \ReflectionClass($this->config->get('soapClientClass'));
         $this->soapClient = $soapClientClass->newInstance($wsdlUrl, $options);
         parent::__construct($config, $wsdlUrl);
         // we need to pass $config for proxy settings
     } catch (SoapFault $e) {
         throw new Exception('Unable to load WSDL: ' . $e->getMessage(), $e->getCode(), $e);
     }
 }
Ejemplo n.º 6
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);
           }
       }
   }
Ejemplo n.º 7
0
 /**
  * Loads all type classes
  */
 protected function loadTypes()
 {
     $this->log('Loading types');
     $types = $this->wsdl->getTypes();
     foreach ($types as $typeNode) {
         $type = null;
         if ($typeNode->isComplex()) {
             if ($typeNode->isArray()) {
                 $type = new ArrayType($this->config, $typeNode->getName());
             } else {
                 $type = new ComplexType($this->config, $typeNode->getName());
             }
             $this->log('Loading type ' . $type->getPhpIdentifier());
             $type->setAbstract($typeNode->isAbstract());
             foreach ($typeNode->getParts() as $name => $typeName) {
                 // There are 2 ways a wsdl can indicate that a field accepts the null value -
                 // by setting the "nillable" attribute to "true" or by setting the "minOccurs" attribute to "0".
                 // See http://www.ibm.com/developerworks/webservices/library/ws-tip-null/index.html
                 $nullable = $typeNode->isElementNillable($name) || $typeNode->getElementMinOccurs($name) === 0;
                 $type->addMember($typeName, $name, $nullable);
             }
         } elseif ($enumValues = $typeNode->getEnumerations()) {
             $type = new Enum($this->config, $typeNode->getName(), $typeNode->getRestriction());
             array_walk($enumValues, function ($value) use($type) {
                 $type->addValue($value);
             });
         } elseif ($pattern = $typeNode->getPattern()) {
             $type = new Pattern($this->config, $typeNode->getName(), $typeNode->getRestriction());
             $type->setValue($pattern);
         }
         if ($type != null) {
             $already_registered = false;
             if ($this->config->get('sharedTypes')) {
                 foreach ($this->types as $registered_types) {
                     if ($registered_types->getIdentifier() == $type->getIdentifier()) {
                         $already_registered = true;
                         break;
                     }
                 }
             }
             if (!$already_registered) {
                 $this->types[$typeNode->getName()] = $type;
             }
         }
     }
     // Loop through all types again to setup class inheritance.
     // We can only do this once all types have been loaded. Otherwise we risk referencing types which have not been
     // loaded yet.
     foreach ($types as $type) {
         if (($baseType = $type->getBase()) && isset($this->types[$baseType]) && $this->types[$baseType] instanceof ComplexType) {
             $this->types[$type->getName()]->setBaseType($this->types[$baseType]);
         }
     }
     $this->log('Done loading types');
 }
Ejemplo n.º 8
0
 /**
  * Save all the loaded classes to the configured output dir
  *
  * @throws Exception If no service is loaded
  */
 private function savePhp()
 {
     $service = $this->service->getClass();
     if ($service == null) {
         throw new Exception('No service loaded');
     }
     $output = new OutputManager($this->config);
     // Generate all type classes
     $types = array();
     foreach ($this->types as $type) {
         $class = $type->getClass();
         if ($class != null) {
             $types[] = $class;
             if (!$this->config->getOneFile() && !$this->config->getNoIncludes()) {
                 $service->addDependency($class->getIdentifier() . '.php');
             }
         }
     }
     $output->save($service, $types);
 }
Ejemplo n.º 9
0
 /**
  * @return string Returns the string for the options array
  */
 private function generateServiceOptions()
 {
     $ret = '';
     if (count($this->config->getOptionFeatures()) > 0) {
         $i = 0;
         $ret .= "\n  if (isset(\$options['features']) == false) {\n    \$options['features'] = ";
         foreach ($this->config->getOptionFeatures() as $option) {
             if ($i++ > 0) {
                 $ret .= ' | ';
             }
             $ret .= $option;
         }
         $ret .= ";\n  }" . PHP_EOL;
     }
     if (strlen($this->config->getWsdlCache()) > 0) {
         $ret .= "\n  if (isset(\$options['wsdl_cache']) == false) {\n    \$options['wsdl_cache'] = " . $this->config->getWsdlCache();
         $ret .= ";\n  }" . PHP_EOL;
     }
     if (strlen($this->config->getCompression()) > 0) {
         $ret .= "\n  if (isset(\$options['compression']) == false) {\n    \$options['compression'] = " . $this->config->getCompression();
         $ret .= ";\n  }" . PHP_EOL;
     }
     return $ret;
 }
Ejemplo n.º 10
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);
         }
     }
 }
 /**
  * @param ConfigInterface $config
  */
 public function __construct($config)
 {
     $this->config = $config;
     $this->methods = $config->get('operationNames');
 }