本文整理汇总了PHP中Nette\Reflection\ClassType::hasProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassType::hasProperty方法的具体用法?PHP ClassType::hasProperty怎么用?PHP ClassType::hasProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Reflection\ClassType
的用法示例。
在下文中一共展示了ClassType::hasProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
/**
* Call to undefined method.
* @param string method name
* @param array arguments
* @return mixed
* @throws MemberAccessException
*/
public function __call($name, $args)
{
$class = new Nette\Reflection\ClassType($this);
if ($name === '') {
throw new Nette\MemberAccessException("Call to class '{$class->name}' method without name.");
}
// event functionality
if ($class->hasProperty($name)) {
if (!$this->_eventSetupCalled) {
$this->_eventSetupCalled = true;
$this->eventSetup();
$this->onEventSetup($this);
}
if (is_array($list = $this->{$name}) || $list instanceof \Traversable) {
foreach ($list as $handler) {
callback($handler)->invokeArgs($args);
}
}
return NULL;
}
// extension methods
if ($cb = Nette\ObjectMixin::getExtensionMethod(get_class($this), $name)) {
array_unshift($args, $this);
return $cb->invokeArgs($args);
}
throw new Nette\MemberAccessException("Call to undefined method {$class->name}::{$name}().");
}
示例2: setValues
public function setValues($values)
{
$values = (array) $values;
$refl = new ClassType($this->getClassName());
foreach ($values as $key => $value) {
if ($refl->hasProperty($key)) {
$setterName = 'set' . ucfirst($key);
if ($refl->hasMethod($setterName)) {
$this->{$setterName}($value);
} else {
$this->{$key} = $value;
}
}
}
}
示例3: 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;
}
}
}
示例4: __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);
}
}
示例5: 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);
}
}