本文整理匯總了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;
}