本文整理汇总了PHP中Zend\Code\Reflection\ClassReflection::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassReflection::getName方法的具体用法?PHP ClassReflection::getName怎么用?PHP ClassReflection::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Reflection\ClassReflection
的用法示例。
在下文中一共展示了ClassReflection::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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: getCacheCode
/**
* Generate code to cache from class reflection.
* This is a total mess, I know. Just wanted to flesh out the logic.
*
* @todo Refactor into a class, clean up logic, DRY it up, maybe move
* some of this into Zend\Code
* @param ClassReflection $r
* @return string
*/
protected static function getCacheCode(ClassReflection $r)
{
$useString = '';
$usesNames = array();
if (count($uses = $r->getDeclaringFile()->getUses())) {
foreach ($uses as $use) {
$usesNames[$use['use']] = $use['as'];
$useString .= "use {$use['use']}";
if ($use['as']) {
$useString .= " as {$use['as']}";
}
$useString .= ";\n";
}
}
$declaration = '';
if ($r->isAbstract() && !$r->isInterface()) {
$declaration .= 'abstract ';
}
if ($r->isFinal()) {
$declaration .= 'final ';
}
if ($r->isInterface()) {
$declaration .= 'interface ';
}
if (!$r->isInterface()) {
$declaration .= 'class ';
}
$declaration .= $r->getShortName();
$parentName = false;
if (($parent = $r->getParentClass()) && $r->getNamespaceName()) {
$parentName = array_key_exists($parent->getName(), $usesNames) ? $usesNames[$parent->getName()] ?: $parent->getShortName() : (0 === strpos($parent->getName(), $r->getNamespaceName()) ? substr($parent->getName(), strlen($r->getNamespaceName()) + 1) : '\\' . $parent->getName());
} else {
if ($parent && !$r->getNamespaceName()) {
$parentName = '\\' . $parent->getName();
}
}
if ($parentName) {
$declaration .= " extends {$parentName}";
}
$interfaces = array_diff($r->getInterfaceNames(), $parent ? $parent->getInterfaceNames() : array());
if (count($interfaces)) {
foreach ($interfaces as $interface) {
$iReflection = new ClassReflection($interface);
$interfaces = array_diff($interfaces, $iReflection->getInterfaceNames());
}
$declaration .= $r->isInterface() ? ' extends ' : ' implements ';
$declaration .= implode(', ', array_map(function ($interface) use($usesNames, $r) {
$iReflection = new ClassReflection($interface);
return array_key_exists($iReflection->getName(), $usesNames) ? $usesNames[$iReflection->getName()] ?: $iReflection->getShortName() : (0 === strpos($iReflection->getName(), $r->getNamespaceName()) ? substr($iReflection->getName(), strlen($r->getNamespaceName()) + 1) : '\\' . $iReflection->getName());
}, $interfaces));
}
$classContents = $r->getContents(false);
$classFileDir = dirname($r->getFileName());
$classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents));
$return = "\nnamespace " . $r->getNamespaceName() . " {\n" . $useString . $declaration . "\n" . $classContents . "\n}\n";
return $return;
}
示例4: dumpClass
/**
* Returns class' code inside namespace
*
* @param ClassReflection $class
*/
private function dumpClass(ClassReflection $class)
{
if (array_search($class->getName(), $this->cachedClasses) !== false) {
return;
}
if ($class->isInternal()) {
return;
}
if ($class->getParentClass()) {
$this->dumpClass($class->getParentClass());
}
foreach ($class->getInterfaces() as $interface) {
$this->dumpClass($interface);
}
if ($class->getTraits()) {
foreach ($class->getTraits() as $trait) {
$this->dumpClass($trait);
}
}
$classContents = $class->getContents(false);
$classFileDir = dirname($class->getFileName());
$classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents));
$uses = implode("\n", $this->codeGenerator->getUseLines($class));
$this->cache[] = "namespace " . $class->getNamespaceName() . " {\n" . ($uses ? $uses . "\n" : '') . $this->codeGenerator->getDeclarationLine($class) . "\n" . $classContents . "\n}\n";
$this->cachedClasses[] = $class->getName();
}
示例5: addContent
/**
* Generate view content
*
* @param string $moduleName
* @param ClassReflection $loadedEntity
*/
protected function addContent($moduleName, ClassReflection $loadedEntity)
{
// prepare some params
$moduleIdentifier = $this->filterCamelCaseToUnderscore($moduleName);
$entityName = $loadedEntity->getShortName();
$entityParam = lcfirst($entityName);
$formParam = lcfirst(str_replace('Entity', '', $loadedEntity->getShortName())) . 'DataForm';
$moduleRoute = $this->filterCamelCaseToDash($moduleName);
// set action body
$body = [];
$body[] = 'use ' . $loadedEntity->getName() . ';';
$body[] = '';
$body[] = '/** @var ' . $entityName . ' $' . $entityParam . ' */';
$body[] = '$' . $entityParam . ' = $this->' . $entityParam . ';';
$body[] = '';
$body[] = '$this->h1(\'' . $moduleIdentifier . '_title_update\');';
$body[] = '';
$body[] = '$this->' . $formParam . '->setAttribute(\'action\', $this->url(\'' . $moduleRoute . '/update\', [\'id\' => $' . $entityParam . '->getIdentifier()]));';
$body[] = '';
$body[] = 'echo $this->bootstrapForm($this->' . $formParam . ');';
$body[] = '?>';
$body[] = '<p>';
$body[] = ' <a class="btn btn-primary" href="<?php echo $this->url(\'' . $moduleRoute . '\'); ?>">';
$body[] = ' <i class="fa fa-table"></i>';
$body[] = ' <?php echo $this->translate(\'' . $moduleIdentifier . '_action_index\'); ?>';
$body[] = ' </a>';
$body[] = '</p>';
$body = implode(AbstractGenerator::LINE_FEED, $body);
// add method
$this->setContent($body);
}
示例6: addContent
/**
* Generate view content
*
* @param string $moduleName
* @param ClassReflection $loadedEntity
*/
protected function addContent($moduleName, ClassReflection $loadedEntity)
{
// prepare some params
$moduleIdentifier = $this->filterCamelCaseToUnderscore($moduleName);
$entityName = $loadedEntity->getShortName();
$entityParam = lcfirst($entityName);
$listParam = lcfirst(str_replace('Entity', '', $entityName)) . 'List';
$moduleRoute = $this->filterCamelCaseToDash($moduleName);
// set action body
$body = [];
$body[] = 'use ' . $loadedEntity->getName() . ';';
$body[] = '';
$body[] = '$this->h1(\'' . $moduleIdentifier . '_title_index\');';
$body[] = '?>';
$body[] = '<table class="table table-bordered table-striped">';
$body[] = ' <thead>';
$body[] = ' <tr>';
foreach ($loadedEntity->getProperties() as $property) {
$body[] = ' <th><?php echo $this->translate(\'' . $moduleIdentifier . '_label_' . $this->filterCamelCaseToUnderscore($property->getName()) . '\'); ?></th>';
}
$body[] = ' <th width="95">';
$body[] = ' <a class="btn btn-default btn-xs" href="<?php echo $this->url(\'' . $moduleRoute . '/create\'); ?>" title="<?php echo $this->translate(\'' . $moduleIdentifier . '_action_create\'); ?>">';
$body[] = ' <i class="fa fa-plus"></i>';
$body[] = ' </a>';
$body[] = ' </th>';
$body[] = ' </tr>';
$body[] = ' </thead>';
$body[] = ' <tbody>';
$body[] = ' <?php /** @var ' . $entityName . ' $' . $entityParam . ' */ ?>';
$body[] = ' <?php foreach ($this->' . $listParam . ' as $' . $entityParam . '): ?>';
$body[] = ' <tr>';
foreach ($loadedEntity->getProperties() as $property) {
$methodName = 'get' . ucfirst($property->getName());
$body[] = ' <td><?php echo $' . $entityParam . '->' . $methodName . '() ?></td>';
}
$body[] = ' <td>';
$body[] = ' <a class="btn btn-default btn-xs" href="<?php echo $this->url(\'' . $moduleRoute . '/show\', [\'id\' => $' . $entityParam . '->getIdentifier()]); ?>" title="<?php echo $this->translate(\'' . $moduleIdentifier . '_action_show\'); ?>">';
$body[] = ' <i class="fa fa-search"></i>';
$body[] = ' </a>';
$body[] = ' <a class="btn btn-default btn-xs" href="<?php echo $this->url(\'' . $moduleRoute . '/update\', [\'id\' => $' . $entityParam . '->getIdentifier()]); ?>" title="<?php echo $this->translate(\'' . $moduleIdentifier . '_action_update\'); ?>">';
$body[] = ' <i class="fa fa-pencil"></i>';
$body[] = ' </a>';
$body[] = ' <a class="btn btn-default btn-xs" href="<?php echo $this->url(\'' . $moduleRoute . '/delete\', [\'id\' => $' . $entityParam . '->getIdentifier()]); ?>" title="<?php echo $this->translate(\'' . $moduleIdentifier . '_action_delete\'); ?>">';
$body[] = ' <i class="fa fa-trash"></i>';
$body[] = ' </a>';
$body[] = ' </td>';
$body[] = ' </tr>';
$body[] = ' <?php endforeach; ?>';
$body[] = ' </tbody>';
$body[] = '</table>';
$body = implode(AbstractGenerator::LINE_FEED, $body);
// add method
$this->setContent($body);
}
示例7: shouldSkip
private function shouldSkip(ClassReflection $class)
{
if ($class->isInternal()) {
return true;
}
foreach ($this->skip as $prefix) {
if (strpos($class->getName(), $prefix) === 0) {
return true;
}
}
return false;
}
示例8: getClassNameInContext
/**
* @param ClassReflection $class
* @param string $namespaceName
* @param array $useArray
* @return string
*/
private function getClassNameInContext(ClassReflection $class, $namespaceName, $useArray)
{
if (!$namespaceName) {
return '\\' . $class->getName();
}
return array_key_exists($class->getName(), $useArray) ? $useArray[$class->getName()] ?: $class->getShortName() : (0 === strpos($class->getName(), $namespaceName) ? substr($class->getName(), strlen($namespaceName) + 1) : '\\' . $class->getName());
}
示例9: addContent
/**
* Generate view content
*
* @param string $moduleName
* @param ClassReflection $loadedEntity
*/
protected function addContent($moduleName, ClassReflection $loadedEntity)
{
// prepare some params
$moduleIdentifier = $this->filterCamelCaseToUnderscore($moduleName);
$entityName = $loadedEntity->getShortName();
$entityParam = lcfirst($entityName);
$formParam = lcfirst(str_replace('Entity', '', $loadedEntity->getShortName())) . 'DeleteForm';
$moduleRoute = $this->filterCamelCaseToDash($moduleName);
$deleteMessage = $moduleRoute . '_message_' . $moduleRoute . '_deleting_possible';
// set action body
$body = [];
$body[] = 'use ' . $loadedEntity->getName() . ';';
$body[] = '';
$body[] = '/** @var ' . $entityName . ' $' . $entityParam . ' */';
$body[] = '$' . $entityParam . ' = $this->' . $entityParam . ';';
$body[] = '';
$body[] = '$this->h1(\'' . $moduleIdentifier . '_title_delete\');';
$body[] = '';
$body[] = '$this->' . $formParam . '->setAttribute(\'action\', $this->url(\'' . $moduleRoute . '/delete\', [\'id\' => $' . $entityParam . '->getIdentifier()]));';
$body[] = '';
$body[] = '?>';
$body[] = '<div class="well">';
$body[] = ' <table class="table">';
$body[] = ' <tbody>';
foreach ($loadedEntity->getProperties() as $property) {
$methodName = 'get' . ucfirst($property->getName());
$body[] = ' <tr>';
$body[] = ' <th class="col-sm-2 text-right"><?php echo $this->translate(\'' . $moduleIdentifier . '_label_' . $this->filterCamelCaseToUnderscore($property->getName()) . '\'); ?></th>';
$body[] = ' <td class="col-sm-10"><?php echo $' . $entityParam . '->' . $methodName . '() ?></td>';
$body[] = ' </tr>';
}
$body[] = ' <tr>';
$body[] = ' <th class="col-sm-2 text-right"> </th>';
$body[] = ' <td class="col-sm-10"><?php echo $this->form($this->' . $formParam . '); ?></td>';
$body[] = ' </tr>';
$body[] = ' </tbody>';
$body[] = ' </table>';
$body[] = '</div>';
$body[] = '<p>';
$body[] = ' <a class="btn btn-primary" href="<?php echo $this->url(\'' . $moduleRoute . '\'); ?>">';
$body[] = ' <i class="fa fa-table"></i>';
$body[] = ' <?php echo $this->translate(\'' . $moduleIdentifier . '_action_index\'); ?>';
$body[] = ' </a>';
$body[] = '</p>';
$body = implode(AbstractGenerator::LINE_FEED, $body);
// add method
$this->setContent($body);
}
示例10: 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;
}
示例11: getClassUseName
public function getClassUseName(ClassReflection $currentClass, ClassReflection $useClass)
{
$useNames = $this->fileReflectionUseStatementService->getUseNames($currentClass->getDeclaringFile());
$fullUseClassName = $useClass->getName();
$classUseName = null;
if (array_key_exists($fullUseClassName, $useNames)) {
$classUseName = $useNames[$fullUseClassName] ?: $useClass->getShortName();
} else {
if (0 === strpos($fullUseClassName, $currentClass->getNamespaceName())) {
$classUseName = substr($fullUseClassName, strlen($currentClass->getNamespaceName()) + 1);
} else {
$classUseName = '\\' . $fullUseClassName;
}
}
return $classUseName;
}
示例12: 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;
}
示例13: addContent
/**
* Generate view content
*
* @param string $moduleName
* @param ClassReflection $loadedEntity
*/
protected function addContent($moduleName, ClassReflection $loadedEntity)
{
// prepare some params
$moduleIdentifier = $this->filterCamelCaseToUnderscore($moduleName);
$entityName = $loadedEntity->getShortName();
$entityParam = lcfirst($entityName);
$moduleRoute = $this->filterCamelCaseToDash($moduleName);
// set action body
$body = [];
$body[] = 'use ' . $loadedEntity->getName() . ';';
$body[] = '';
$body[] = '/** @var ' . $entityName . ' $' . $entityParam . ' */';
$body[] = '$' . $entityParam . ' = $this->' . $entityParam . ';';
$body[] = '';
$body[] = '$this->h1(\'' . $moduleIdentifier . '_title_show\');';
$body[] = '?>';
$body[] = '<table class="table table-bordered">';
$body[] = ' <tbody>';
foreach ($loadedEntity->getProperties() as $property) {
$methodName = 'get' . ucfirst($property->getName());
$body[] = ' <tr>';
$body[] = ' <th><?php echo $this->translate(\'' . $moduleIdentifier . '_label_' . $this->filterCamelCaseToUnderscore($property->getName()) . '\'); ?></th>';
$body[] = ' <td><?php echo $' . $entityParam . '->' . $methodName . '() ?></td>';
$body[] = ' </tr>';
}
$body[] = ' </tbody>';
$body[] = '</table>';
$body[] = '<p>';
$body[] = ' <a class="btn btn-primary" href="<?php echo $this->url(\'' . $moduleRoute . '\'); ?>">';
$body[] = ' <i class="fa fa-table"></i>';
$body[] = ' <?php echo $this->translate(\'' . $moduleIdentifier . '_action_index\'); ?>';
$body[] = ' </a>';
$body[] = '</p>';
$body = implode(AbstractGenerator::LINE_FEED, $body);
// add method
$this->setContent($body);
}
示例14: isSatisfiedBy
/**
* @param ClassReflection $class
* @return bool
*/
public function isSatisfiedBy(ClassReflection $class)
{
$className = $class->getName();
return $className === 'Zend\\Loader\\AutoloaderFactory' || $className === 'Zend\\Loader\\SplAutoloader';
}
示例15: processClassIntoCacheFile
/**
* Makes several checks.
*
* 1. Exclude blacklisted namespaces
* 2. Exclude blacklisted classes
* 3. Skip Internal classes
*
* @param Reflection\ClassReflection $class
*/
protected function processClassIntoCacheFile(Reflection\ClassReflection $class)
{
if ($this->classList[$class->getName()] === true) {
return;
}
if ($class->isInternal() === true) {
return;
}
// Make the string regex compactible
$excludeNamespaces = array_map(function ($namespace) {
return str_replace('\\', '[\\\\]', $namespace);
}, $this->getConfig()->getIgnoreNamespaces());
// Make the regex
$excludeNamespaceRegex = '/^(' . implode('|', $excludeNamespaces) . ')(.*)/';
if (preg_match($excludeNamespaceRegex, $class->getName())) {
return;
}
$this->classList[$class->getName()] = true;
$this->buildNamespace($class);
}