本文整理汇总了PHP中Doctrine\Common\Util\ClassUtils::newReflectionObject方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassUtils::newReflectionObject方法的具体用法?PHP ClassUtils::newReflectionObject怎么用?PHP ClassUtils::newReflectionObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Util\ClassUtils
的用法示例。
在下文中一共展示了ClassUtils::newReflectionObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export
/**
* @param mixed $var
* @param int $maxDepth
*
* @return mixed
*/
public static function export($var, $maxDepth)
{
$return = null;
$isObj = is_object($var);
if ($isObj && in_array('Doctrine\\Common\\Collections\\Collection', class_implements($var))) {
$var = $var->toArray();
}
if ($maxDepth) {
if (is_array($var)) {
$return = array();
foreach ($var as $k => $v) {
$return[$k] = self::export($v, $maxDepth - 1);
}
} else {
if ($isObj) {
$return = new \stdclass();
if ($var instanceof \DateTime) {
$return->__CLASS__ = "DateTime";
$return->date = $var->format('c');
$return->timezone = $var->getTimeZone()->getName();
} else {
$reflClass = ClassUtils::newReflectionObject($var);
$return->__CLASS__ = ClassUtils::getClass($var);
if ($var instanceof Proxy) {
$return->__IS_PROXY__ = true;
$return->__PROXY_INITIALIZED__ = $var->__isInitialized();
}
if ($var instanceof \ArrayObject || $var instanceof \ArrayIterator) {
$return->__STORAGE__ = self::export($var->getArrayCopy(), $maxDepth - 1);
}
foreach ($reflClass->getProperties() as $reflProperty) {
$name = $reflProperty->getName();
$reflProperty->setAccessible(true);
$return->{$name} = self::export($reflProperty->getValue($var), $maxDepth - 1);
}
}
} else {
$return = $var;
}
}
} else {
$return = is_object($var) ? get_class($var) : (is_array($var) ? 'Array(' . count($var) . ')' : $var);
}
return $return;
}
示例2: testNewReflectionObject
/**
* @dataProvider dataGetClass
*/
public function testNewReflectionObject($className, $expectedClassName)
{
$object = new $className();
$reflClass = ClassUtils::newReflectionObject($object);
$this->assertEquals($expectedClassName, $reflClass->getName());
}
示例3: fillReturnWithClassAttributes
/**
* Fill the $return variable with class attributes
*
* @param object $var
* @param stdClass $return
* @param int $maxDepth
*
* @return mixed
*/
private static function fillReturnWithClassAttributes($var, \stdClass $return, $maxDepth)
{
$reflClass = ClassUtils::newReflectionObject($var);
$parsedAttributes = array();
do {
$currentClassName = $reflClass->getName();
foreach ($reflClass->getProperties() as $reflProperty) {
$attributeKey = $reflProperty->isPrivate() ? $currentClassName . '#' : '';
$attributeKey .= $reflProperty->getName();
if (isset($parsedAttributes[$attributeKey])) {
continue;
}
$parsedAttributes[$attributeKey] = true;
$name = $reflProperty->getName() . ($return->__CLASS__ !== $currentClassName || $reflProperty->isPrivate() ? ':' . $currentClassName : '') . ($reflProperty->isPrivate() ? ':private' : '') . ($reflProperty->isProtected() ? ':protected' : '');
$reflProperty->setAccessible(true);
$return->{$name} = self::export($reflProperty->getValue($var), $maxDepth - 1);
}
} while ($reflClass = $reflClass->getParentClass());
return $return;
}