本文整理汇总了PHP中Zend\Code\Generator\PropertyGenerator::fromReflection方法的典型用法代码示例。如果您正苦于以下问题:PHP PropertyGenerator::fromReflection方法的具体用法?PHP PropertyGenerator::fromReflection怎么用?PHP PropertyGenerator::fromReflection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\PropertyGenerator
的用法示例。
在下文中一共展示了PropertyGenerator::fromReflection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromReflection
/**
* Build a Code Generation Php Object from a Class Reflection
*
* @param ClassReflection $classReflection
* @return TraitGenerator
*/
public static function fromReflection(ClassReflection $classReflection)
{
// class generator
$cg = new static($classReflection->getName());
$cg->setSourceContent($cg->getSourceContent());
$cg->setSourceDirty(false);
if ($classReflection->getDocComment() != '') {
$cg->setDocBlock(DocBlockGenerator::fromReflection($classReflection->getDocBlock()));
}
// set the namespace
if ($classReflection->inNamespace()) {
$cg->setNamespaceName($classReflection->getNamespaceName());
}
$properties = array();
foreach ($classReflection->getProperties() as $reflectionProperty) {
if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) {
$properties[] = PropertyGenerator::fromReflection($reflectionProperty);
}
}
$cg->addProperties($properties);
$methods = array();
foreach ($classReflection->getMethods() as $reflectionMethod) {
$className = $cg->getNamespaceName() ? $cg->getNamespaceName() . '\\' . $cg->getName() : $cg->getName();
if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
$methods[] = MethodGenerator::fromReflection($reflectionMethod);
}
}
$cg->addMethods($methods);
return $cg;
}
示例2: fromReflection
/**
* fromReflection() - build a Code Generation Php Object from a Class Reflection
*
* @param ReflectionClass $classReflection
* @return ClassGenerator
*/
public static function fromReflection(ClassReflection $classReflection)
{
// class generator
$cg = new static($classReflection->getName());
$cg->setSourceContent($cg->getSourceContent());
$cg->setSourceDirty(false);
if ($classReflection->getDocComment() != '') {
$cg->setDocblock(DocblockGenerator::fromReflection($classReflection->getDocblock()));
}
$cg->setAbstract($classReflection->isAbstract());
// set the namespace
if ($classReflection->inNamespace()) {
$cg->setNamespaceName($classReflection->getNamespaceName());
}
/* @var $parentClass \Zend\Code\Reflection\ReflectionClass */
if ($parentClass = $classReflection->getParentClass()) {
$cg->setExtendedClass($parentClass->getName());
$interfaces = array_diff($classReflection->getInterfaces(), $parentClass->getInterfaces());
} else {
$interfaces = $classReflection->getInterfaces();
}
$interfaceNames = array();
foreach ($interfaces as $interface) {
/* @var $interface \Zend\Code\Reflection\ReflectionClass */
$interfaceNames[] = $interface->getName();
}
$cg->setImplementedInterfaces($interfaceNames);
$properties = array();
foreach ($classReflection->getProperties() as $reflectionProperty) {
/* @var $reflectionProperty \PropertyReflection\Code\Reflection\ReflectionProperty */
if ($reflectionProperty->getDeclaringClass()->getName() == $cg->getName()) {
$properties[] = PropertyGenerator::fromReflection($reflectionProperty);
}
}
$cg->setProperties($properties);
$methods = array();
foreach ($classReflection->getMethods() as $reflectionMethod) {
/* @var $reflectionMethod \MethodReflection\Code\Reflection\ReflectionMethod */
if ($reflectionMethod->getDeclaringClass()->getName() == $cg->getName()) {
$methods[] = MethodGenerator::fromReflection($reflectionMethod);
}
}
$cg->setMethods($methods);
return $cg;
}
示例3: fromReflection
/**
* Build a Code Generation Php Object from a Class Reflection
*
* @param ClassReflection $classReflection
* @return ClassGenerator
*/
public static function fromReflection(ClassReflection $classReflection)
{
$cg = new static($classReflection->getName());
$cg->setSourceContent($cg->getSourceContent());
$cg->setSourceDirty(false);
if ($classReflection->getDocComment() != '') {
$cg->setDocBlock(DocBlockGenerator::fromReflection($classReflection->getDocBlock()));
}
$cg->setAbstract($classReflection->isAbstract());
// set the namespace
if ($classReflection->inNamespace()) {
$cg->setNamespaceName($classReflection->getNamespaceName());
}
/* @var \Zend\Code\Reflection\ClassReflection $parentClass */
$parentClass = $classReflection->getParentClass();
$interfaces = $classReflection->getInterfaces();
if ($parentClass) {
$cg->setExtendedClass($parentClass->getName());
$interfaces = array_diff($interfaces, $parentClass->getInterfaces());
}
$interfaceNames = array();
foreach ($interfaces as $interface) {
/* @var \Zend\Code\Reflection\ClassReflection $interface */
$interfaceNames[] = $interface->getName();
}
$cg->setImplementedInterfaces($interfaceNames);
$properties = array();
foreach ($classReflection->getProperties() as $reflectionProperty) {
if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) {
$properties[] = PropertyGenerator::fromReflection($reflectionProperty);
}
}
$cg->addProperties($properties);
$constants = array();
foreach ($classReflection->getConstants() as $name => $value) {
$constants[] = array('name' => $name, 'value' => $value);
}
$cg->addConstants($constants);
$methods = array();
foreach ($classReflection->getMethods() as $reflectionMethod) {
$className = $cg->getNamespaceName() ? $cg->getNamespaceName() . "\\" . $cg->getName() : $cg->getName();
if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
$methods[] = MethodGenerator::fromReflection($reflectionMethod);
}
}
$cg->addMethods($methods);
return $cg;
}
示例4: testPropertyDocBlockWillLoadFromReflection
/**
* @3491
*/
public function testPropertyDocBlockWillLoadFromReflection()
{
$reflectionClass = new \Zend\Code\Reflection\ClassReflection('\\ZendTest\\Code\\Generator\\TestAsset\\TestClassWithManyProperties');
$reflProp = $reflectionClass->getProperty('fooProperty');
$cgProp = PropertyGenerator::fromReflection($reflProp);
$this->assertEquals('fooProperty', $cgProp->getName());
$docBlock = $cgProp->getDocBlock();
$this->assertInstanceOf('Zend\\Code\\Generator\\DocBlockGenerator', $docBlock);
$tags = $docBlock->getTags();
$this->assertInternalType('array', $tags);
$this->assertEquals(1, count($tags));
$tag = array_shift($tags);
$this->assertInstanceOf('Zend\\Code\\Generator\\DocBlock\\Tag', $tag);
$this->assertEquals('var', $tag->getName());
}
示例5: testPropertyWillLoadFromReflection
/**
* @group ZF-6444
*/
public function testPropertyWillLoadFromReflection()
{
$this->markTestSkipped('Skipped for now');
$reflectionClass = new \Zend\Code\Reflection\ReflectionClass('\\ZendTest\\Code\\Generator\\TestAsset\\TestClassWithManyProperties');
// test property 1
$reflProp = $reflectionClass->getProperty('_bazProperty');
$cgProp = PropertyGenerator::fromReflection($reflProp);
$this->assertEquals('_bazProperty', $cgProp->getName());
$this->assertEquals(array(true, false, true), $cgProp->getDefaultValue()->getValue());
$this->assertEquals('private', $cgProp->getVisibility());
$reflProp = $reflectionClass->getProperty('_bazStaticProperty');
// test property 2
$cgProp = PropertyGenerator::fromReflection($reflProp);
$this->assertEquals('_bazStaticProperty', $cgProp->getName());
$this->assertEquals(\ZendTest\Code\Generator\TestAsset\TestClassWithManyProperties::FOO, $cgProp->getDefaultValue()->getValue());
$this->assertTrue($cgProp->isStatic());
$this->assertEquals('private', $cgProp->getVisibility());
}
示例6: getGeneratorFromReflection
/**
* Copied from ClassGenerator::fromReflection and tweaked slightly
* @param ClassReflection $classReflection
*
* @return ClassGenerator
*/
public function getGeneratorFromReflection(ClassReflection $classReflection)
{
// class generator
$cg = new ClassGenerator($classReflection->getName());
$cg->setSourceContent($cg->getSourceContent());
$cg->setSourceDirty(false);
if ($classReflection->getDocComment() != '') {
$docblock = DocBlockGenerator::fromReflection($classReflection->getDocBlock());
$docblock->setIndentation(Generator::$indentation);
$cg->setDocBlock($docblock);
}
$cg->setAbstract($classReflection->isAbstract());
// set the namespace
if ($classReflection->inNamespace()) {
$cg->setNamespaceName($classReflection->getNamespaceName());
}
/* @var \Zend\Code\Reflection\ClassReflection $parentClass */
$parentClass = $classReflection->getParentClass();
if ($parentClass) {
$cg->setExtendedClass('\\' . ltrim($parentClass->getName(), '\\'));
$interfaces = array_diff($classReflection->getInterfaces(), $parentClass->getInterfaces());
} else {
$interfaces = $classReflection->getInterfaces();
}
$interfaceNames = array();
foreach ($interfaces as $interface) {
/* @var \Zend\Code\Reflection\ClassReflection $interface */
$interfaceNames[] = $interface->getName();
}
$cg->setImplementedInterfaces($interfaceNames);
$properties = array();
foreach ($classReflection->getProperties() as $reflectionProperty) {
if ($reflectionProperty->getDeclaringClass()->getName() == $classReflection->getName()) {
$property = PropertyGenerator::fromReflection($reflectionProperty);
$property->setIndentation(Generator::$indentation);
$properties[] = $property;
}
}
$cg->addProperties($properties);
$methods = array();
foreach ($classReflection->getMethods() as $reflectionMethod) {
$className = $cg->getNamespaceName() ? $cg->getNamespaceName() . "\\" . $cg->getName() : $cg->getName();
if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
$method = MethodGenerator::fromReflection($reflectionMethod);
$method->setBody(preg_replace("/^\\s+/m", '', $method->getBody()));
$method->setIndentation(Generator::$indentation);
$methods[] = $method;
}
}
$cg->addMethods($methods);
return $cg;
}