Esempio n. 1
0
    public function testGenerationOfDocBlock()
    {
        $this->docBlockGenerator->setShortDescription('@var Foo this is foo bar');

        $expected = '/**' . DocBlockGenerator::LINE_FEED . ' * @var Foo this is foo bar'
            . DocBlockGenerator::LINE_FEED . ' */' . DocBlockGenerator::LINE_FEED;
        $this->assertEquals($expected, $this->docBlockGenerator->generate());
    }
Esempio n. 2
0
 /**
  * @param type $name
  * @param type $type
  * @param type $docString
  * @return PhpProperty
  */
 public function addProperty($name, $type, $docString)
 {
     $property = new PropertyGenerator();
     $docblock = new DocBlockGenerator();
     $property->setName($name);
     $property->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED);
     $docblock->setShortDescription($docString);
     $docblock->setTag(new Tag(array('name' => 'var', 'description' => $type)));
     $property->setDocblock($docblock);
     $this->addPropertyFromGenerator($property);
     return $property;
 }
Esempio n. 3
0
 /**
  * FileGenerator constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $mockTag = new GenericTag();
     $mockTag->setName('mock');
     $author = new AuthorTag('ClassMocker');
     $docBlock = new DocBlockGenerator();
     $docBlock->setShortDescription("Auto generated file by ClassMocker, do not change");
     $docBlock->setTag($author);
     $docBlock->setTag($mockTag);
     $this->setDocBlock($docBlock);
 }
Esempio n. 4
0
 /**
  * @param Tag $tagItem
  * @return ClassGenerator
  */
 protected function createClass(Tag $tagItem)
 {
     $className = ucfirst($this->stringToCamelCaseConverter->convert($tagItem->getName()));
     $class = new ClassGenerator();
     $class->setNamespaceName('Flex\\Code\\Html\\Tag');
     $class->setName($className);
     $class->addUse('Flex\\Code\\Html\\Tag\\Model\\AbstractTag');
     $class->setExtendedClass('AbstractTag');
     $implementedInterfaces = [];
     if ($tagItem->isGlobalAttributeAware()) {
         $implementedInterfaces[] = 'GlobalAttributeAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Attribute\\GlobalAttributeAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Attribute\\GlobalAttributeAwareTrait');
         $class->addTrait('GlobalAttributeAwareTrait');
     }
     if ($tagItem->isClipboardEventAware()) {
         $implementedInterfaces[] = 'ClipboardEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\ClipboardEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\ClipboardEventAwareTrait');
         $class->addTrait('ClipboardEventAwareTrait');
     }
     if ($tagItem->isFormEventAware()) {
         $implementedInterfaces[] = 'FormEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\FormEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\FormEventAwareTrait');
         $class->addTrait('FormEventAwareTrait');
     }
     if ($tagItem->isKeyboardEventAware()) {
         $implementedInterfaces[] = 'KeyboardEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\KeyboardEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\KeyboardEventAwareTrait');
         $class->addTrait('KeyboardEventAwareTrait');
     }
     if ($tagItem->isMediaEventAware()) {
         $implementedInterfaces[] = 'MediaEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MediaEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MediaEventAwareTrait');
         $class->addTrait('MediaEventAwareTrait');
     }
     if ($tagItem->isMiscEventAware()) {
         $implementedInterfaces[] = 'MiscEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MiscEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MiscEventAwareTrait');
         $class->addTrait('MiscEventAwareTrait');
     }
     if ($tagItem->isMouseEventAware()) {
         $implementedInterfaces[] = 'MouseEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MouseEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\MouseEventAwareTrait');
         $class->addTrait('MouseEventAwareTrait');
     }
     if ($tagItem->isWindowEventAware()) {
         $implementedInterfaces[] = 'WindowEventAwareInterface';
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\WindowEventAwareInterface');
         $class->addUse('Flex\\Code\\Html\\Tag\\Event\\WindowEventAwareTrait');
         $class->addTrait('WindowEventAwareTrait');
     }
     $class->setImplementedInterfaces($implementedInterfaces);
     $docBlock = new DocBlockGenerator();
     $docBlock->setTag(new GenericTag('author', 'elnebuloso/flex-code-html-generator'));
     $docBlock->setTag(new GenericTag('link', $tagItem->getLink()));
     if (!is_null($tagItem->getShortDescription())) {
         $docBlock->setShortDescription($tagItem->getShortDescription());
     }
     if (!is_null($tagItem->getLongDescription())) {
         $docBlock->setLongDescription($tagItem->getLongDescription());
     }
     $class->setDocBlock($docBlock);
     return $class;
 }
Esempio n. 5
0
 public function generate()
 {
     $method = $this->getMethodGenerator();
     $api = $this->getApi();
     $operation = $this->getOperation();
     $method->setName($operation->getNickname());
     $parameterClassGenerator = $this->getParameterClassGenerator();
     $parameterClassGenerator->setName($operation->getNickname());
     $parameterGenerator = $this->getParameterGenerator();
     $propertyGenerator = $this->getPropertyGenerator();
     $docBlockGenerator = $this->getDocblockGenerator();
     $docBlockGenerator->setShortDescription($operation->getSummary());
     $docBlockGenerator->setLongDescription(strip_tags($operation->getNotes()));
     $hasRequired = false;
     $routeParams = array();
     foreach ($operation->getParameters() as $swaggerParameter) {
         switch ($swaggerParameter->getParamType()) {
             case self::PARAM_TYPE_PATH:
                 if ($swaggerParameter->getRequired()) {
                     $hasRequired = true;
                 }
                 $parameters = $method->getParameters();
                 if (isset($parameters[$swaggerParameter->getName()])) {
                     continue;
                 }
                 $parameter = clone $parameterGenerator;
                 $parameter->setName($swaggerParameter->getName());
                 $method->setParameter($parameter);
                 $paramTag = new CodeGenerator\DocBlock\Tag\ParamTag();
                 $paramTag->setDataType($swaggerParameter::getType($swaggerParameter->getDataType()));
                 $paramTag->setParamName($swaggerParameter->getName());
                 $paramDescription = $swaggerParameter->getDescription();
                 $paramTag->setDescription($paramDescription);
                 $docBlockGenerator->setTag($paramTag);
                 $routeParams[] = $parameter;
                 break;
             case self::PARAM_TYPE_QUERY:
             case self::PARAM_TYPE_FORM:
                 $propertyName = lcfirst($swaggerParameter->getName());
                 if (($postParamStart = strpos($propertyName, '[')) !== false) {
                     $propertyPostParams = substr($propertyName, $postParamStart);
                     $propertyName = substr($propertyName, 0, $postParamStart);
                     echo "{$method->getName()}::\${$propertyName} has: {$propertyPostParams}" . PHP_EOL;
                 }
                 if ($parameterClassGenerator->hasProperty($propertyName)) {
                     continue;
                 }
                 $property = clone $propertyGenerator;
                 $property->setName($propertyName);
                 $propertyDocblock = new CodeGenerator\DocBlockGenerator();
                 $propertyDocblock->setShortDescription($swaggerParameter->getDescription());
                 $propertyDescription = '';
                 if ($allowableValues = $swaggerParameter->getAllowableValues()) {
                     if ($allowableValues->getValueType() == 'LIST') {
                         $propertyDescription .= 'Allowable values: [' . implode(', ', $allowableValues->getValues()) . ']' . PHP_EOL;
                     }
                 }
                 $propertyDocblock->setLongDescription($propertyDescription);
                 if (!$this->isDocBlockEmpty($propertyDocblock)) {
                     $property->setDocBlock($propertyDocblock);
                 }
                 $parameterClassGenerator->addPropertyFromGenerator($property);
                 $getterGenerator = $this->generateParameterGetter($propertyName, $swaggerParameter);
                 $setterGenerator = $this->generateParameterSetter($propertyName, $swaggerParameter);
                 $parameterClassGenerator->addMethods(array($getterGenerator, $setterGenerator));
                 break;
         }
     }
     if (count($parameterClassGenerator->getProperties())) {
         $queryParameter = clone $parameterGenerator;
         $queryParameter->setName($operation->getNickname());
         $queryParameter->setType(RestGenerator::REQUEST_NAMESPACE_ALIAS . '\\' . $operation->getNickname());
         if (!$hasRequired) {
             $queryParameter->setDefaultValue(new CodeGenerator\ValueGenerator(null));
         }
         $paramTag = new CodeGenerator\DocBlock\Tag\ParamTag();
         $paramTag->setDataType(RestGenerator::REQUEST_NAMESPACE_ALIAS . '\\' . $operation->getNickname());
         $paramTag->setParamName($operation->getNickname());
         if (!$hasRequired) {
             $paramTag->setDescription(' = null');
         }
         $docBlockGenerator->setTag($paramTag);
         $method->setParameter($queryParameter);
     } else {
         $queryParameter = null;
     }
     $method->setDocBlock($docBlockGenerator);
     $body = $this->getBody($routeParams, $queryParameter);
     $method->setBody($body);
 }
Esempio n. 6
0
 /**
  * Generate method
  *
  * @param string $methodName
  * @return void
  */
 protected function generateMethod($methodName)
 {
     $methodReflection = $this->_method[$methodName];
     $docBlock = new DocBlockGenerator();
     $docBlock->setShortDescription("Delicate {$methodName}() to __call() method ");
     if ($methodReflection->getDocComment()) {
         $docBlockReflection = new DocBlockReflection($methodReflection);
         $docBlock->fromReflection($docBlockReflection);
     }
     $method = new MethodGenerator();
     $method->setName($methodName);
     $method->setDocBlock($docBlock);
     $method->setBody(sprintf(self::METHOD_TEMPLATE, $methodName));
     if ($methodReflection->isPublic()) {
         $method->setVisibility(MethodGenerator::VISIBILITY_PUBLIC);
     } else {
         if ($methodReflection->isProtected()) {
             $method->setVisibility(MethodGenerator::VISIBILITY_PROTECTED);
         } else {
             if ($methodReflection->isPrivate()) {
                 $method->setVisibility(MethodGenerator::VISIBILITY_PRIVATE);
             }
         }
     }
     foreach ($methodReflection->getParameters() as $parameter) {
         $parameterGenerator = new ParameterGenerator();
         $parameterGenerator->setPosition($parameter->getPosition());
         $parameterGenerator->setName($parameter->getName());
         $parameterGenerator->setPassedByReference($parameter->isPassedByReference());
         if ($parameter->isDefaultValueAvailable()) {
             $parameterGenerator->setDefaultValue($parameter->getDefaultValue());
         }
         if ($parameter->isArray()) {
             $parameterGenerator->setType('array');
         }
         if ($typeClass = $parameter->getClass()) {
             $parameterGenerator->setType($typeClass->getName());
         }
         $method->setParameter($parameterGenerator);
     }
     $this->addMethodFromGenerator($method);
 }
Esempio n. 7
0
 private function handleAdder(Generator\ClassGenerator $generator, PHPProperty $prop, PHPClass $class)
 {
     $type = $prop->getType();
     $propName = $type->getArg()->getName();
     $docblock = new DocBlockGenerator();
     $docblock->setShortDescription("Adds as {$propName}");
     if ($prop->getDoc()) {
         $docblock->setLongDescription($prop->getDoc());
     }
     $return = new ReturnTag();
     $return->setTypes("self");
     $docblock->setTag($return);
     $patramTag = new ParamTag($propName, $this->getPhpType($type->getArg()->getType()));
     $docblock->setTag($patramTag);
     $method = new MethodGenerator("addTo" . Inflector::classify($prop->getName()));
     $parameter = new ParameterGenerator($propName);
     $tt = $type->getArg()->getType();
     if (!$this->isNativeType($tt)) {
         if ($p = $this->isOneType($tt)) {
             if ($t = $p->getType()) {
                 $patramTag->setTypes($this->getPhpType($t));
                 if (!$this->isNativeType($t)) {
                     $parameter->setType($this->getPhpType($t));
                 }
             }
         } elseif (!$this->isNativeType($tt)) {
             $parameter->setType($this->getPhpType($tt));
         }
     }
     $methodBody = "\$this->" . $prop->getName() . "[] = \$" . $propName . ";" . PHP_EOL;
     $methodBody .= "return \$this;";
     $method->setBody($methodBody);
     $method->setDocBlock($docblock);
     $method->setParameter($parameter);
     $generator->addMethodFromGenerator($method);
 }
 /**
  * writes module config
  *
  * @param array $config
  * @param string $path
  */
 protected function writeModuleConfig(array $config, $path)
 {
     $moduleName = $this->params->getParam('moduleName');
     $generatorConfig = new FileGenerator();
     $docBlock = new DocBlockGenerator();
     $docBlock->setTag(new GenericTag('author', $this->params->getParam('author')));
     $docBlock->setTag(new GenericTag('project', $this->params->getParam('project')));
     $docBlock->setTag(new GenericTag('license', $this->params->getParam('license')));
     $docBlock->setTag(new GenericTag('copyright', $this->params->getParam('copyright')));
     $docBlock->setShortDescription(sprintf($this->codeLibrary()->get('module.generatedConfigDescription'), $moduleName));
     $generatorConfig->setDocBlock($docBlock);
     $configString = var_export($config, true);
     $configString = str_replace("'/../view'", '__DIR__ . \'/../view\'', $configString);
     $generatorConfig->setBody('return ' . $configString . ';');
     file_put_contents($path, $generatorConfig->generate());
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function createService(SimpleXMLElement $service)
 {
     // read the service name
     $serviceName = (string) $service['name'];
     $serviceClassName = $serviceName;
     $serviceClassName = filter_var($serviceClassName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeVariableName')));
     $serviceClassName = filter_var($serviceClassName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeConstantName')));
     /*
      * CLASS CREATION
      */
     // create the class
     $class = ClassGenerator::fromReflection(new ClassReflection('\\Sapone\\Template\\ServiceTemplate'));
     $class->setName($serviceClassName);
     $class->setNamespaceName($this->namespaceInflector->inflectNamespace($service));
     // set the correct inheritance
     if ($this->config->isBesimpleClient()) {
         $class->setExtendedClass('BeSimpleSoapClient');
         $class->addUse('BeSimple\\SoapClient\\SoapClient');
     } else {
         $class->setExtendedClass('\\SoapClient');
     }
     // read the service documentation
     $serviceDoc = new DocBlockGenerator();
     $serviceDoc->setTag(new GenericTag('xmlns', '@todo'));
     $documentation = new Html2Text((string) current($service->xpath('./wsdl:documentation')));
     if ($documentation->getText()) {
         $serviceDoc->setShortDescription($documentation->getText());
     }
     $class->setDocBlock($serviceDoc);
     /*
      * METHODS CREATION
      */
     foreach ($service->xpath('.//wsdl:operation') as $operation) {
         $operationName = (string) $operation['name'];
         $operationName = filter_var($operationName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeVariableName')));
         $operationName = filter_var($operationName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeConstantName')));
         $inputMessageType = $this->getTypeFromQualifiedString((string) current($operation->xpath('.//wsdl:input/@message')), $operation);
         $outputMessageType = $this->getTypeFromQualifiedString((string) current($operation->xpath('.//wsdl:output/@message')), $operation);
         // read the service documentation
         $messageDoc = new DocBlockGenerator();
         $documentation = new Html2Text((string) current($operation->xpath('./wsdl:documentation')));
         $param = new ParameterGenerator('parameters', $inputMessageType);
         $messageDoc->setTag(new ParamTag($param->getName(), $this->namespaceInflector->inflectDocBlockQualifiedName($inputMessageType)));
         $messageDoc->setTag(new ReturnTag($this->namespaceInflector->inflectDocBlockQualifiedName($outputMessageType)));
         if ($documentation->getText()) {
             $messageDoc->setShortDescription($documentation->getText());
         }
         // create the method
         $method = new MethodGenerator($operationName);
         $method->setDocBlock($messageDoc);
         $method->setParameter($param);
         $method->setBody("return \$this->__soapCall('{$operation['name']}', array(\$parameters));");
         $class->addMethodFromGenerator($method);
     }
     $this->serializeClass($class);
     // register the class in the classmap
     $this->classmap[$class->getName()] = $class->getNamespaceName() . '\\' . $class->getName();
     return $class->getName();
 }