Nette\PhpGenerator\PhpNamespace::unresolveName PHP Method

unresolveName() public method

public unresolveName ( $name ) : string
return string
    public function unresolveName($name)
    {
        if (in_array(strtolower($name), ['self', 'parent', 'array', 'callable', 'string', 'bool', 'float', 'int', ''], TRUE)) {
            return $name;
        }
        $name = ltrim($name, '\\');
        $res = NULL;
        $lower = strtolower($name);
        foreach ($this->uses as $alias => $for) {
            if (Strings::startsWith($lower . '\\', strtolower($for) . '\\')) {
                $short = $alias . substr($name, strlen($for));
                if (!isset($res) || strlen($res) > strlen($short)) {
                    $res = $short;
                }
            }
        }
        if (!$res && Strings::startsWith($lower, strtolower($this->name) . '\\')) {
            return substr($name, strlen($this->name) + 1);
        } else {
            return $res ?: ($this->name ? '\\' : '') . $name;
        }
    }

Usage Example

Example #1
0
 /**
  * @return string  PHP code
  */
 public function __toString()
 {
     $parameters = array();
     foreach ($this->parameters as $param) {
         $variadic = $this->variadic && $param === end($this->parameters);
         $hint = in_array($param->getTypeHint(), array('array', '')) ? $param->getTypeHint() : ($this->namespace ? $this->namespace->unresolveName($param->getTypeHint()) : $param->getTypeHint());
         $parameters[] = ($hint ? $hint . ' ' : '') . ($param->isReference() ? '&' : '') . ($variadic ? '...' : '') . '$' . $param->getName() . ($param->isOptional() && !$variadic ? ' = ' . Helpers::dump($param->defaultValue) : '');
     }
     $uses = array();
     foreach ($this->uses as $param) {
         $uses[] = ($param->isReference() ? '&' : '') . '$' . $param->getName();
     }
     return ($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . ($this->visibility ? $this->visibility . ' ' : '') . ($this->static ? 'static ' : '') . 'function' . ($this->returnReference ? ' &' : '') . ($this->name ? ' ' . $this->name : '') . '(' . implode(', ', $parameters) . ')' . ($this->uses ? ' use (' . implode(', ', $uses) . ')' : '') . ($this->abstract || $this->body === FALSE ? ';' : ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(trim($this->body), 1) . "\n}");
 }
All Usage Examples Of Nette\PhpGenerator\PhpNamespace::unresolveName