Wsdl2PhpGenerator\Validator::validateOperation PHP Method

validateOperation() public static method

Validates an operation name against PHP naming conventions.
public static validateOperation ( string $name ) : string
$name string the name of the operation to test
return string The validated version of the submitted operation name
    public static function validateOperation($name)
    {
        $name = self::validateNamingConvention($name);
        if (self::isKeyword($name)) {
            $name = self::NAME_PREFIX . ucfirst($name);
        }
        return $name;
    }

Usage Example

Exemplo n.º 1
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);
         }
     }
 }
All Usage Examples Of Wsdl2PhpGenerator\Validator::validateOperation