Zephir\Utils::getFullName PHP Method

getFullName() public static method

Transform class/interface name to FQN format
public static getFullName ( string $className, string $currentNamespace, zephir\AliasManager $aliasManager = null ) : string
$className string
$currentNamespace string
$aliasManager zephir\AliasManager
return string
    public static function getFullName($className, $currentNamespace, AliasManager $aliasManager = null)
    {
        if (!is_string($className)) {
            throw new \InvalidArgumentException('Class name must be a string ' . print_r($className, true));
        }
        if ($className[0] !== '\\') {
            // If class/interface name not begin with \ maybe a alias or a sub-namespace
            $firstSepPos = strpos($className, '\\');
            if (false !== $firstSepPos) {
                $baseName = substr($className, 0, $firstSepPos);
                if ($aliasManager->isAlias($baseName)) {
                    return $aliasManager->getAlias($baseName) . '\\' . substr($className, $firstSepPos + 1);
                }
            } else {
                if ($aliasManager->isAlias($className)) {
                    return $aliasManager->getAlias($className);
                }
            }
            // Relative class/interface name
            if ($currentNamespace) {
                return $currentNamespace . '\\' . $className;
            } else {
                return $className;
            }
        }
        // Absolute class/interface name
        return substr($className, 1);
    }

Usage Example

示例#1
0
 /**
  * @param CompilationContext $compilationContext
  * @throws CompilerException
  */
 public function compile(CompilationContext $compilationContext)
 {
     $compilationContext->headersManager->add('kernel/exception');
     $codePrinter = $compilationContext->codePrinter;
     $statement = $this->_statement;
     $expr = $statement['expr'];
     /**
      * This optimizes throw new Exception("hello")
      */
     if (!$compilationContext->insideTryCatch) {
         if (isset($expr['class']) && isset($expr['parameters']) && count($expr['parameters']) == 1 && $expr['parameters'][0]['parameter']['type'] == 'string') {
             $className = Utils::getFullName($expr['class'], $compilationContext->classDefinition->getNamespace(), $compilationContext->aliasManager);
             if ($compilationContext->compiler->isClass($className)) {
                 $classDefinition = $compilationContext->compiler->getClassDefinition($className);
                 $message = $expr['parameters'][0]['parameter']['value'];
                 $class = $classDefinition->getClassEntry();
                 $this->throwStringException($codePrinter, $class, $message, $statement['expr']);
                 return;
             } else {
                 if ($compilationContext->compiler->isBundledClass($className)) {
                     $classEntry = $compilationContext->classDefinition->getClassEntryByClassName($className, $compilationContext, true);
                     if ($classEntry) {
                         $message = $expr['parameters'][0]['parameter']['value'];
                         $this->throwStringException($codePrinter, $classEntry, $message, $statement['expr']);
                         return;
                     }
                 }
             }
         } else {
             if (in_array($expr['type'], array('string', 'char', 'int', 'double'))) {
                 $class = $compilationContext->classDefinition->getClassEntryByClassName('Exception', $compilationContext);
                 $this->throwStringException($codePrinter, $class, $expr['value'], $expr);
                 return;
             }
         }
     }
     $throwExpr = new Expression($expr);
     $resolvedExpr = $throwExpr->compile($compilationContext);
     if (!in_array($resolvedExpr->getType(), array('variable', 'string'))) {
         throw new CompilerException("Expression '" . $resolvedExpr->getType() . '" cannot be used as exception', $expr);
     }
     $variableVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $expr);
     if (!in_array($variableVariable->getType(), array('variable', 'string'))) {
         throw new CompilerException("Variable '" . $variableVariable->getType() . "' cannot be used as exception", $expr);
     }
     $variableCode = $compilationContext->backend->getVariableCode($variableVariable);
     $codePrinter->output('zephir_throw_exception_debug(' . $variableCode . ', "' . Compiler::getShortUserPath($statement['expr']['file']) . '", ' . $statement['expr']['line'] . ' TSRMLS_CC);');
     if (!$compilationContext->insideTryCatch) {
         $codePrinter->output('ZEPHIR_MM_RESTORE();');
         $codePrinter->output('return;');
     } else {
         $codePrinter->output('goto try_end_' . $compilationContext->currentTryCatch . ';');
         $codePrinter->outputBlankLine();
     }
     if ($variableVariable->isTemporal()) {
         $variableVariable->setIdle(true);
     }
 }
All Usage Examples Of Zephir\Utils::getFullName