/**
  * 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');
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 /**
  * @param XSDMap $XSDMap
  * @param ClassTemplate $classTemplate
  * @param \SimpleXMLElement $element
  * @param string $documentation
  * @param string $maxOccurs
  * @return BasePropertyTemplate|null
  */
 public static function buildProperty(XSDMap $XSDMap, ClassTemplate $classTemplate, \SimpleXMLElement $element, $documentation = null, $maxOccurs = null)
 {
     $propertyTemplate = new BasePropertyTemplate();
     $attributes = $element->attributes();
     if (null === $documentation) {
         $propertyTemplate->setDocumentation(XMLUtils::getDocumentation($element));
     }
     if (null === $maxOccurs && isset($attributes['maxOccurs'])) {
         $maxOccurs = (string) $attributes['maxOccurs'];
     }
     if (null !== $maxOccurs && '' !== $maxOccurs) {
         $propertyTemplate->setCollection(self::determineIfCollection($maxOccurs));
     }
     $name = (string) $attributes['name'];
     $type = (string) $attributes['type'];
     $ref = (string) $attributes['ref'];
     if ('' === $name) {
         if ('' === $ref) {
             trigger_error(sprintf('Encountered property on FHIR object "%s" with no "name" or "ref" attribute, cannot create property for it.  Property definition: "%s"', $classTemplate->getElementName(), $element->saveXML()));
             return null;
         }
         if (0 === strpos($ref, 'xhtml')) {
             $propertyTemplate->setName(substr($ref, 6));
             $propertyTemplate->setFHIRElementType('html');
             $propertyTemplate->setHTML(true);
             $propertyTemplate->setPHPType('string');
             return $propertyTemplate;
         }
         $name = $ref;
         $type = $ref;
     }
     $propertyTemplate->setName($name);
     $propertyTemplate->setFHIRElementType($type);
     // TODO: Implement proper primitive types
     if (false !== strpos($type, '-primitive')) {
         $propertyTemplate->setPrimitive(true);
         $propertyTemplate->setPHPType('string');
     } else {
         if (false !== strpos($type, '-list')) {
             $propertyTemplate->setList(true);
             $propertyTemplate->setPHPType('string');
         } else {
             if (0 === strpos($type, 'xs:')) {
                 $propertyTemplate->setPHPType($XSDMap->getClassUseStatementForFHIRElementName(substr($type, 3)));
             } else {
                 $propertyTemplate->setPHPType($XSDMap->getClassUseStatementForFHIRElementName($type));
             }
         }
     }
     return $propertyTemplate;
 }
 /**
  * Constructor
  *
  * @param BasePropertyTemplate $propertyTemplate
  */
 public function __construct(BasePropertyTemplate $propertyTemplate)
 {
     parent::__construct($propertyTemplate->getName(), $propertyTemplate->getPHPType());
     $this->_property = $propertyTemplate;
 }
Example #6
0
 /**
  * @param ClassTemplate $classTemplate
  * @param XSDMap\XSDMapEntry $mapEntry
  */
 public static function addBaseClassProperties(ClassTemplate $classTemplate, XSDMap\XSDMapEntry $mapEntry)
 {
     // Add the source element name to each class...
     $property = new BasePropertyTemplate(new PHPScopeEnum(PHPScopeEnum::_PRIVATE), true, false);
     $property->setDefaultValue($mapEntry->fhirElementName);
     $property->setName('_fhirElementName');
     $property->setPHPType('string');
     $property->setPrimitive(true);
     $classTemplate->addProperty($property);
 }
Example #7
0
 /**
  * @param BasePropertyTemplate $property
  */
 public function addProperty(BasePropertyTemplate $property)
 {
     $this->_properties[$property->getName()] = $property;
 }