Example #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");
     }
     $config = Generator::getInstance()->getConfig();
     $this->class = new PhpClass($this->phpIdentifier, $config->getClassExists());
     $first = true;
     foreach ($this->values as $value) {
         try {
             $name = Validator::validateNamingConvention($value);
         } catch (ValidationException $e) {
             $name = 'constant' . $name;
         }
         try {
             $name = Validator::validateType($name);
         } catch (ValidationException $e) {
             $name .= 'Custom';
         }
         if ($first) {
             $this->class->addConstant($name, '__default');
             $first = false;
         }
         $this->class->addConstant($value, $name);
     }
 }
 protected function setup()
 {
     $this->outputDir = __DIR__ . '/' . get_class($this) . 'Code';
     $this->generator = Generator::getInstance();
     $this->config = new Config($this->wsdl, $this->outputDir);
     // We do not execute the code generation here to allow individual test cases
     // to update the configuration further before generating.
 }
Example #3
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");
     }
     $config = Generator::getInstance()->getConfig();
     $class = new PhpClass($this->phpIdentifier, $config->getClassExists());
     $constructorComment = new PhpDocComment();
     $constructorComment->setAccess(PhpDocElementFactory::getPublicAccess());
     $constructorSource = '';
     $constructorParameters = '';
     $accessors = array();
     // Add member variables
     foreach ($this->members as $member) {
         $type = '';
         try {
             $type = Validator::validateType($member->getType());
         } catch (ValidationException $e) {
             $type .= 'Custom';
         }
         $name = Validator::validateNamingConvention($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 ($config->getConstructorParamsDefaultToNull()) {
                 $constructorParameters .= ' = null';
             }
             if ($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 ($config->getNoTypeConstructor() == false) {
         $class->addFunction($function);
     }
     foreach ($accessors as $accessor) {
         $class->addFunction($accessor);
     }
     $this->class = $class;
 }
Example #4
0
 /**
  * The minimum construction
  *
  * @param string $name The identifier for the type
  * @param string $datatype The restriction(DataType)
  */
 public function __construct($name, $datatype)
 {
     $this->class = null;
     $this->datatype = $datatype;
     $this->identifier = $name;
     $config = Generator::getInstance()->getConfig();
     // Add prefix and suffix
     $name = $config->getPrefix() . $this->identifier . $config->getSuffix();
     try {
         $name = Validator::validateClass($name);
     } catch (ValidationException $e) {
         $name .= 'Custom';
     }
     $this->phpIdentifier = $name;
 }
Example #5
0
   /**
    * Generates the class if not already generated
    */
   public function generateClass()
   {
       $config = Generator::getInstance()->getConfig();
       // Add prefix and suffix
       $name = $config->getPrefix() . $this->identifier . $config->getSuffix();
       // Generate a valid classname
       try {
           $name = Validator::validateClass($name);
       } catch (ValidationException $e) {
           $name .= 'Custom';
       }
       // Create the class object
       $comment = new PhpDocComment($this->description);
       $this->class = new PhpClass($name, $config->getClassExists(), 'SoapClient', $comment);
       // Create the constructor
       $comment = new PhpDocComment();
       $comment->addParam(PhpDocElementFactory::getParam('array', 'config', '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($config) . '
 parent::__construct($wsdl, $options);' . PHP_EOL;
       $function = new PhpFunction('public', '__construct', 'array $options = array(), $wsdl = \'' . $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() . "' => '" . $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::validateNamingConvention($operation->getName());
           $comment = new PhpDocComment($operation->getDescription());
           $comment->setAccess(PhpDocElementFactory::getPublicAccess());
           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(\'' . $name . '\', 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);
           }
       }
   }