本文整理汇总了PHP中Zend\Code\Reflection\ClassReflection::getDocBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassReflection::getDocBlock方法的具体用法?PHP ClassReflection::getDocBlock怎么用?PHP ClassReflection::getDocBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Reflection\ClassReflection
的用法示例。
在下文中一共展示了ClassReflection::getDocBlock方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testToString
public function testToString()
{
$classReflection = new ClassReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass5');
$classDocBlock = $classReflection->getDocBlock();
$expectedString = 'DocBlock [ /* DocBlock */ ] {' . PHP_EOL . PHP_EOL . ' - Tags [3] {' . PHP_EOL . ' DocBlock Tag [ * @author ]' . PHP_EOL . ' DocBlock Tag [ * @method ]' . PHP_EOL . ' DocBlock Tag [ * @property ]' . PHP_EOL . ' }' . PHP_EOL . '}' . PHP_EOL;
$this->assertEquals($expectedString, (string) $classDocBlock);
}
示例2: 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;
}
示例3: fromReflection
/**
* Build a Code Generation Php Object from a Class Reflection
*
* @param ClassReflection $classReflection
* @return InterfaceGenerator
*/
public static function fromReflection(ClassReflection $classReflection)
{
if (!$classReflection->isInterface()) {
throw new Exception\InvalidArgumentException(sprintf('Class %s is not a interface', $classReflection->getName()));
}
// class generator
$cg = new static($classReflection->getName());
$methods = [];
$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());
}
foreach ($classReflection->getMethods() as $reflectionMethod) {
$className = $cg->getNamespaceName() ? $cg->getNamespaceName() . '\\' . $cg->getName() : $cg->getName();
if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
$methods[] = MethodGenerator::fromReflection($reflectionMethod);
}
}
foreach ($classReflection->getConstants() as $name => $value) {
$cg->addConstant($name, $value);
}
$cg->addMethods($methods);
return $cg;
}
示例4: isSatisfiedBy
/**
* @param ClassReflection $class
* @return bool
*/
public function isSatisfiedBy(ClassReflection $class)
{
$docBlock = $class->getDocBlock();
if ($docBlock) {
if ($docBlock->getTags('Annotation')) {
return true;
}
}
return false;
}
示例5: cache
/**
* Cache declared interfaces and classes to a single file
*
* @param \Zend\Mvc\MvcEvent $e
* @return void
*/
public function cache($e)
{
$request = $e->getRequest();
if ($request instanceof ConsoleRequest || $request->getQuery()->get('EDPSUPERLUMINAL_CACHE', null) === null) {
return;
}
if (file_exists(ZF_CLASS_CACHE)) {
$this->reflectClassCache();
$code = file_get_contents(ZF_CLASS_CACHE);
} else {
$code = "<?php\n";
}
$classes = array_merge(get_declared_interfaces(), get_declared_classes());
foreach ($classes as $class) {
// Skip non-Zend classes
if (0 !== strpos($class, 'Zend')) {
continue;
}
// Skip the autoloader factory and this class
if (in_array($class, array('Zend\\Loader\\AutoloaderFactory', __CLASS__))) {
continue;
}
if ($class === 'Zend\\Loader\\SplAutoloader') {
continue;
}
// Skip any classes we already know about
if (in_array($class, $this->knownClasses)) {
continue;
}
$this->knownClasses[] = $class;
$class = new ClassReflection($class);
// Skip any Annotation classes
$docBlock = $class->getDocBlock();
if ($docBlock) {
if ($docBlock->getTags('Annotation')) {
continue;
}
}
// Skip ZF2-based autoloaders
if (in_array('Zend\\Loader\\SplAutoloader', $class->getInterfaceNames())) {
continue;
}
// Skip internal classes or classes from extensions
// (this shouldn't happen, as we're only caching Zend classes)
if ($class->isInternal() || $class->getExtensionName()) {
continue;
}
$code .= static::getCacheCode($class);
}
file_put_contents(ZF_CLASS_CACHE, $code);
// minify the file
file_put_contents(ZF_CLASS_CACHE, php_strip_whitespace(ZF_CLASS_CACHE));
}
示例6: 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;
}
示例7: _processComplexType
/**
* Retrieve complex type information from class public properties.
*
* @param string $class
* @return array
* @throws \InvalidArgumentException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _processComplexType($class)
{
$typeName = $this->translateTypeName($class);
$this->_types[$typeName] = [];
if ($this->isArrayType($class)) {
$this->register($this->getArrayItemType($class));
} else {
if (!(class_exists($class) || interface_exists($class))) {
throw new \InvalidArgumentException(sprintf('Could not load the "%s" class as parameter type.', $class));
}
$reflection = new ClassReflection($class);
$docBlock = $reflection->getDocBlock();
$this->_types[$typeName]['documentation'] = $docBlock ? $this->getDescription($docBlock) : '';
/** @var \Zend\Code\Reflection\MethodReflection $methodReflection */
foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodReflection) {
if ($methodReflection->class === "Magento\\Framework\\Model\\AbstractModel") {
continue;
}
$this->_processMethod($methodReflection, $typeName);
}
}
return $this->_types[$typeName];
}
示例8: 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;
}