本文整理汇总了PHP中Nette\Reflection\ClassType::getProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassType::getProperty方法的具体用法?PHP ClassType::getProperty怎么用?PHP ClassType::getProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Reflection\ClassType
的用法示例。
在下文中一共展示了ClassType::getProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPropertyRule
/**
* Get BuilderDefinition from entity property
*
* @param string $propertyName
* @param bool $fillValues
* @return BuilderDefinition|null
* @throws InvalidStateException
*/
private function getPropertyRule($propertyName, $fillValues = TRUE)
{
$property = $this->entityReflection->getProperty($propertyName);
$annotations = $this->annotationReader->getPropertyAnnotations($property);
$rule = new BuilderDefinition($propertyName);
foreach ($annotations as $annotation) {
switch (get_class($annotation)) {
case 'Doctrine\\ORM\\Mapping\\Column':
if ($this->getEntityPrimaryKeyName($this->entity) === $propertyName) {
$rule->setComponentType(BuilderDefinition::COMPONENT_TYPE_HIDDEN);
$rule->setRequired(FALSE);
} else {
$type = BuilderDefinition::COMPONENT_TYPE_TEXT;
$rule->setRequired(!$annotation->nullable);
/** @var Column $annotation */
if ($annotation->type === 'boolean') {
$type = BuilderDefinition::COMPONENT_TYPE_CHECKBOX;
}
// is numeric?
if ($annotation->type === 'integer' || $annotation->type === 'float' || $annotation->type === 'bigint' || $annotation->type === 'decimal' || $annotation->type === 'smallint') {
$rule->addValidationRule(Form::NUMERIC, 'This is required in numeric format', TRUE);
}
$rule->setComponentType($type);
}
break;
case 'Doctrine\\ORM\\Mapping\\ManyToOne':
/** @var ManyToOne $annotation */
$rule->setComponentType(BuilderDefinition::COMPONENT_TYPE_SELECT);
if ($fillValues) {
$rule->setValues($this->getPossibleValues($annotation->targetEntity));
}
$rule->setTargetEntity($annotation->targetEntity);
$rule->setRequired(TRUE);
break;
case 'Doctrine\\ORM\\Mapping\\ManyToMany':
/** @var OneToMany $annotation */
$rule->setComponentType(BuilderDefinition::COMPONENT_TYPE_MULTI_SELECT);
if ($fillValues) {
$rule->setValues($this->getPossibleValues($annotation->targetEntity));
}
$rule->setRequired(TRUE);
$rule->setTargetEntity($annotation->targetEntity);
break;
case 'Doctrine\\ORM\\Mapping\\JoinColumn':
/** @var JoinColumn $annotation */
$rule->setRequired(!$annotation->nullable);
break;
}
}
return $rule->getComponentType() === NULL ? NULL : $rule;
}
示例2: assign
private function assign(array $data)
{
$errors = array();
foreach ($data as $propertyName => $value) {
$pr = new ClassType($this);
if (trim($value) == '') {
$value = NULL;
}
$propertyName = Strings::underdashToCamel($propertyName);
if ($pr->hasProperty($propertyName)) {
$property = $pr->getProperty($propertyName);
if ($property->getAnnotation('var') == 'DateTime' && $value !== NULL) {
$value = new DateTime($value);
}
$this->{$propertyName} = $value;
} else {
$errors[] = $propertyName;
}
}
}
示例3: __call
/**
* @param $name
* @param $arguments
* @throws LogicException
* @return mixed|void
*/
public function __call($name, $arguments)
{
$prefix = substr($name, 0, 3);
if ($prefix === 'get') {
return $this->{lcfirst(substr($name, 3))};
} elseif ($prefix === 'set') {
$reflection = new ClassType($this);
$propertyName = lcfirst(substr($name, 3));
if ($reflection->hasProperty($propertyName) && ($range = $reflection->getProperty($propertyName)->getAnnotation('range')) !== NULL) {
$dataLength = strlen($arguments[0]);
if ($range instanceof ArrayHash && count($range) == 2 && ($range[0] > $dataLength || $dataLength > $range[1])) {
throw new LogicException(sprintf('%s bad range <%d,%d> ... value %d', $propertyName, $range[0], $range[1], $dataLength));
} else {
if (is_integer($range) && $dataLength != $range) {
throw new LogicException('bad length ' . $propertyName . ' ' . strlen($name) . ' - ' . $range);
}
}
}
$this->{$propertyName} = reset($arguments);
}
}
示例4: testSetFieldValue
/**
* @dataProvider dataStringFields
*/
public function testSetFieldValue($class, $fields)
{
$metadata = $this->getMetadataFor($class);
foreach ($fields as $field) {
$className = 'Tests\\NForms\\Models\\' . $class;
$reflection = new Nette\Reflection\ClassType($className);
$object = new $className();
$metadata->setFieldValue($object, $field, "test string");
if ($reflection->hasProperty($field) && $reflection->getProperty($field)->isPublic()) {
$value = $object->{$field};
} else {
$value = $object->{'get' . ucfirst($field)}();
}
Assert::same('test string', $value);
$metadata->setFieldValue($object, $field, NULL);
if ($reflection->hasProperty($field) && $reflection->getProperty($field)->isPublic()) {
$value = $object->{$field};
} else {
$value = $object->{'get' . ucfirst($field)}();
}
Assert::same(NULL, $value);
}
}
示例5: readPropertyDataType
/**
* Read property information
* Read relations and base DB types for convert values to correct format
*
* @param object $baseEntity
* @param string $name
* @return array|NULL
*/
private function readPropertyDataType($baseEntity, $name)
{
$annotationReader = new AnnotationReader();
// read property information
$reflectionClass = new ClassType($baseEntity);
$property = $reflectionClass->getProperty($name);
// if property exists
if ($property !== NULL) {
/** @var Column $column */
$column = $annotationReader->getPropertyAnnotation($property, Column::class);
/** @var ManyToOne $manyToOne */
$manyToOne = $annotationReader->getPropertyAnnotation($property, ManyToOne::class);
/** @var ManyToMany $manyToMany */
$manyToMany = $annotationReader->getPropertyAnnotation($property, ManyToMany::class);
/** @var OneToMany $oneToMany */
$oneToMany = $annotationReader->getPropertyAnnotation($property, OneToMany::class);
$type = NULL;
$collection = FALSE;
$relation = FALSE;
if ($column !== NULL) {
$type = $column->type;
if (strrpos($type, 'array') !== FALSE) {
$type = \DateTime::class;
} else {
if ($type === 'dateinterval') {
$type = \DateInterval::class;
} else {
if (strrpos($type, 'array') !== FALSE) {
$type = 'array';
$collection = TRUE;
}
}
}
} else {
if ($manyToOne !== NULL) {
$type = $manyToOne->targetEntity;
$relation = TRUE;
} else {
if ($manyToMany !== NULL || $oneToMany !== NULL) {
$collection = TRUE;
$type = $manyToMany === NULL ? $oneToMany->targetEntity : $manyToMany->targetEntity;
$relation = TRUE;
}
}
}
return ['type' => $type, 'collection' => $collection, 'relation' => $relation];
}
return NULL;
}