Nette\ComponentModel\Component::lookup PHP Метод

lookup() публичный Метод

Lookup hierarchy for component specified by class or interface name.
public lookup ( $type, $need = TRUE ) : Nette\ComponentModel\IComponent
Результат Nette\ComponentModel\IComponent
    public function lookup($type, $need = TRUE)
    {
        if (!isset($this->monitors[$type])) {
            // not monitored or not processed yet
            $obj = $this->parent;
            $path = self::NAME_SEPARATOR . $this->name;
            $depth = 1;
            while ($obj !== NULL) {
                $parent = $obj->getParent();
                if ($type ? $obj instanceof $type : $parent === NULL) {
                    break;
                }
                $path = self::NAME_SEPARATOR . $obj->getName() . $path;
                $depth++;
                $obj = $parent;
                // IComponent::getParent()
                if ($obj === $this) {
                    $obj = NULL;
                    // prevent cycling
                }
            }
            if ($obj) {
                $this->monitors[$type] = [$obj, $depth, substr($path, 1), FALSE];
            } else {
                $this->monitors[$type] = [NULL, NULL, NULL, FALSE];
                // not found
            }
        }
        if ($need && $this->monitors[$type][0] === NULL) {
            throw new Nette\InvalidStateException("Component '{$this->name}' is not attached to '{$type}'.");
        }
        return $this->monitors[$type][0];
    }

Usage Example

Пример #1
0
 /**
  * Start download of the file!
  * @param IDownloader $downloader
  */
 function download(IDownloader $downloader = null)
 {
     $this->downloader = $downloader;
     // Call sendResponse on presenter (used since 2.0 instead of terminate)
     if ($this->parent instanceof Presenter) {
         $presenter = $this->parent;
     } else {
         $presenter = $this->parent->lookup("Nette/Application/UI/Presenter", true);
     }
     $presenter->sendResponse($this);
 }