Get the type of a property
public getPropertyType ( string $propertyName ) : string | ||
$propertyName | string | |
return | string |
/** * formats the name of a property * * @param string $value * @param string $property * * @return string */ public function formatPropertyValue($value, $property) { $propertyHolder = new PropertyHolder(); switch ($propertyHolder->getPropertyType($property)) { case PropertyHolder::TYPE_STRING: $valueOutput = json_encode(trim($value)); break; case PropertyHolder::TYPE_BOOLEAN: if (true === $value || $value === 'true') { $valueOutput = 'true'; } elseif (false === $value || $value === 'false') { $valueOutput = 'false'; } else { $valueOutput = '""'; } break; case PropertyHolder::TYPE_IN_ARRAY: try { $valueOutput = json_encode($propertyHolder->checkValueInArray($property, $value)); } catch (\InvalidArgumentException $ex) { $valueOutput = '""'; } break; default: $valueOutput = json_encode($value); break; } if ('unknown' === $valueOutput || '"unknown"' === $valueOutput) { $valueOutput = '""'; } return $valueOutput; }
/** * formats the name of a property * * @param string $value * @param string $property * * @return string */ public function formatPropertyValue($value, $property) { $valueOutput = $value; $propertyHolder = new PropertyHolder(); switch ($propertyHolder->getPropertyType($property)) { case PropertyHolder::TYPE_BOOLEAN: if (true === $value || $value === 'true') { $valueOutput = 'true'; } elseif (false === $value || $value === 'false') { $valueOutput = 'false'; } else { $valueOutput = ''; } break; case PropertyHolder::TYPE_IN_ARRAY: try { $valueOutput = $propertyHolder->checkValueInArray($property, $value); } catch (\InvalidArgumentException $ex) { $valueOutput = ''; } break; default: // nothing t do here break; } if ('unknown' === $valueOutput) { $valueOutput = ''; } return '"' . str_replace('"', '""', $valueOutput) . '"'; }
/** * formats the name of a property * * @param string $value * @param string $property * * @return string */ public function formatPropertyValue($value, $property) { $valueOutput = $value; $propertyHolder = new PropertyHolder(); switch ($propertyHolder->getPropertyType($property)) { case PropertyHolder::TYPE_STRING: $valueOutput = '"' . trim($value) . '"'; break; case PropertyHolder::TYPE_BOOLEAN: if (true === $value || $value === 'true') { $valueOutput = '"true"'; } elseif (false === $value || $value === 'false') { $valueOutput = '"false"'; } else { $valueOutput = ''; } break; case PropertyHolder::TYPE_IN_ARRAY: try { $valueOutput = '"' . $propertyHolder->checkValueInArray($property, $value) . '"'; } catch (\InvalidArgumentException $ex) { $valueOutput = ''; } break; default: if (preg_match('/[^a-zA-Z0-9]/', $valueOutput)) { $valueOutput = '"' . $valueOutput . '"'; } // nothing t do here break; } return $valueOutput; }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Property Foobar did not have a defined property type * * @group data * @group sourcetest */ public function testGetPropertyTypeThrowsExceptionIfPropertyNameNotMapped() { $this->object->getPropertyType('Foobar'); }