/** * Constructor * * @param \DCarbone\PHPFHIR\ClassGenerator\Template\Property\BasePropertyTemplate $propertyTemplate */ public function __construct(BasePropertyTemplate $propertyTemplate) { $name = sprintf('get%s', NameUtils::getPropertyMethodName($propertyTemplate->getName())); parent::__construct($name); $this->setDocumentation($propertyTemplate->getDocumentation()); $this->_property = $propertyTemplate; }
/** * Constructor * * @param \DCarbone\PHPFHIR\ClassGenerator\Template\Property\BasePropertyTemplate $propertyTemplate */ public function __construct(BasePropertyTemplate $propertyTemplate) { if ($propertyTemplate->isCollection()) { $name = sprintf('add%s', NameUtils::getPropertyMethodName($propertyTemplate->getName())); } else { $name = sprintf('set%s', NameUtils::getPropertyMethodName($propertyTemplate->getName())); } parent::__construct($name, new PHPScopeEnum(PHPScopeEnum::_PUBLIC)); $this->setDocumentation($propertyTemplate->getDocumentation()); $this->setReturnValueType('$this'); $this->setReturnStatement('$this'); }
/** * @param string $outputPath * @param string $outputNamespace * @param string $class */ public function __construct($outputPath, $outputNamespace, $class) { $this->outputPath = rtrim($outputPath, "\\/"); $this->outputNamespace = $outputNamespace; if (NameUtils::isValidClassName($class)) { $this->class = $class; } else { throw new \RuntimeException(sprintf('%s::__construct - Specified invalid class name %s.', get_called_class(), $class)); } $this->classPath = sprintf('%s/%s/%s.php', $this->outputPath, FileUtils::buildDirPathFromNS($this->outputNamespace), $class); $this->className = sprintf('%s\\%s', $this->outputNamespace, $class); }
/** * Constructor * * @param string $name * @param PHPScopeEnum $scope */ public function __construct($name, PHPScopeEnum $scope = null) { if (NameUtils::isValidFunctionName($name)) { $this->name = $name; } else { throw new \InvalidArgumentException('Function name "' . $name . '" is not valid.'); } if (null === $scope) { $this->scope = new PHPScopeEnum(PHPScopeEnum::_PUBLIC); } else { $this->scope = $scope; } }
/** * Constructor * * @param string $fhirElementName * @param string $className * @param string $namespace * @param ComplexClassTypesEnum $classType */ public function __construct($fhirElementName, $className, $namespace, ComplexClassTypesEnum $classType = null) { if (NameUtils::isValidClassName($className)) { $this->_className = $className; } else { throw new \InvalidArgumentException('Class Name "' . $className . '" is not valid.'); } if (NameUtils::isValidNSName($namespace)) { $this->_namespace = $namespace; } else { throw new \InvalidArgumentException('Namespace "' . $namespace . '" is not valid.'); } $this->_elementName = $fhirElementName; $this->_classType = $classType; }
/** * @param string $file * @param XSDMap $xsdMap * @param string $outputNS */ public static function parseClassesFromXSD($file, XSDMap $xsdMap, $outputNS) { $sxe = self::constructSXEWithFilePath($file); foreach ($sxe->children('xs', true) as $child) { /** @var \SimpleXMLElement $child */ $attributes = $child->attributes(); $fhirElementName = (string) $attributes['name']; if ('' === $fhirElementName) { continue; } if (ElementTypeEnum::COMPLEX_TYPE === strtolower($child->getName())) { $type = ClassTypeUtils::getComplexClassType($child); $xsdMap[$fhirElementName] = new XSDMap\XSDMapEntry($child, $fhirElementName, NSUtils::generateRootNamespace($outputNS, NSUtils::getComplexTypeNamespace($fhirElementName, $type)), NameUtils::getComplexTypeClassName($fhirElementName)); } } }
/** * @param string $xsdPath * @param string $outputPath * @param string $outputNamespace * @return array */ private static function _validateInput($xsdPath, $outputPath, $outputNamespace) { // Bunch'o validation if (false === is_dir($xsdPath)) { throw new \RuntimeException('Unable to locate XSD dir "' . $xsdPath . '"'); } if (false === is_readable($xsdPath)) { throw new \RuntimeException('This process does not have read access to directory "' . $xsdPath . '"'); } if (null === $outputPath) { $outputPath = PHPFHIR_DEFAULT_OUTPUT_DIR; } if (!is_dir($outputPath)) { throw new \RuntimeException('Unable to locate output dir "' . $outputPath . '"'); } if (!is_writable($outputPath)) { throw new \RuntimeException(sprintf('Specified output path "%s" is not writable by this process.', $outputPath)); } if (!is_readable($outputPath)) { throw new \RuntimeException(sprintf('Specified output path "%s" is not readable by this process.', $outputPath)); } if (null === $outputNamespace) { $outputNamespace = PHPFHIR_DEFAULT_NAMESPACE; } if (false === NameUtils::isValidNSName($outputNamespace)) { throw new \InvalidArgumentException(sprintf('Specified root namespace "%s" is not a valid PHP namespace.', $outputNamespace)); } return array($xsdPath, $outputPath, $outputNamespace); }
/** * @param \DCarbone\PHPFHIR\ClassGenerator\Template\Property\BasePropertyTemplate $propertyTemplate * @return SetterMethodTemplate */ public static function createSetter(BasePropertyTemplate $propertyTemplate) { $paramTemplate = new PropertyParameterTemplate($propertyTemplate); if ($propertyTemplate->isCollection()) { $methodBody = sprintf('$this->%s[] = %s;', $propertyTemplate->getName(), NameUtils::getPropertyVariableName($paramTemplate->getProperty()->getName())); } else { $methodBody = sprintf('$this->%s = %s;', $propertyTemplate->getName(), NameUtils::getPropertyVariableName($paramTemplate->getProperty()->getName())); } $setterTemplate = new SetterMethodTemplate($propertyTemplate); $setterTemplate->addParameter($paramTemplate); $setterTemplate->addLineToBody($methodBody); return $setterTemplate; }
/** * @return string */ public function compileTemplate() { return sprintf(" /**\n%s * @var %s%s%s\n */\n %s %s = %s;\n\n", $this->getDocBlockDocumentationFragment(), $this->isPrimitive() || $this->isList() ? '' : '\\', $this->getPHPType(), $this->isCollection() ? '[]' : '', (string) $this->getScope(), NameUtils::getPropertyVariableName($this->getName()), $this->isCollection() ? 'array()' : $this->determineDefaultValueOutput()); }
/** * @return string */ public function getParamDocBlockFragment() { $property = $this->getProperty(); return sprintf('@param %s%s%s %s', $property->isPrimitive() || $property->isList() ? '' : '\\', $property->getPHPType(), $property->isCollection() ? '[]' : '', NameUtils::getPropertyVariableName($property->getName())); }
/** * @return string */ public function compileTemplate() { if (is_string($this->defaultValue)) { return sprintf('%s = %s', NameUtils::getPropertyVariableName($this->getName()), $this->getDefaultValue()); } return NameUtils::getPropertyVariableName($this->getName()); }