本文整理汇总了PHP中Generic::getClass方法的典型用法代码示例。如果您正苦于以下问题:PHP Generic::getClass方法的具体用法?PHP Generic::getClass怎么用?PHP Generic::getClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Generic
的用法示例。
在下文中一共展示了Generic::getClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
/**
* Write a record
*
* @param lang.Generic object
* @param string[] fields if omitted, all fields will be written
*/
public function write(Generic $object, array $fields = array())
{
$values = array();
$class = $object->getClass();
if (!$fields) {
foreach ($class->getFields() as $f) {
$values[] = $class->getMethod('get' . ucfirst($f->getName()))->invoke($object);
}
} else {
foreach ($fields as $name) {
$values[] = $class->getMethod('get' . ucfirst($name))->invoke($object);
}
}
return $this->writeValues($values);
}
示例2: write
/**
* Write a record
*
* @param lang.Generic object
* @param string[] fields if omitted, all fields will be written
*/
public function write(Generic $object, array $fields = array())
{
$values = array();
$class = $object->getClass();
// Use the array-cast trick to access private and protected members
$array = (array) $object;
if ($fields) {
foreach ($fields as $name) {
$values[] = $this->fieldValue($array, $class->getField($name));
}
} else {
foreach ($class->getFields() as $f) {
$values[] = $this->fieldValue($array, $f);
}
}
return $this->writeValues($values);
}
示例3: marshalTo
/**
* Marshal an object to xml
*
* @param xml.Node target
* @param lang.Object instance
* @param [:var] inject
* @return xml.Node the given target
*/
public function marshalTo(Node $target = NULL, Generic $instance, $inject = array())
{
$class = $instance->getClass();
// Create node if not existant
if (NULL === $target) {
$target = new Node(NULL);
}
self::recurse($instance, $class, $target, $inject);
return $target;
}