Nette\Loaders\RobotLoader::tryLoad PHP Method

tryLoad() public method

Handles autoloading of classes, interfaces or traits.
public tryLoad ( $type ) : void
return void
    public function tryLoad($type)
    {
        $type = $orig = ltrim($type, '\\');
        // PHP namespace bug #49143
        $type = strtolower($type);
        $info =& $this->classes[$type];
        if (isset($this->missing[$type]) || is_int($info) && $info >= self::RETRY_LIMIT) {
            return;
        }
        if ($this->autoRebuild) {
            if (!is_array($info) || !is_file($info['file'])) {
                $info = is_int($info) ? $info + 1 : 0;
                if (!$this->refreshed) {
                    $this->refresh();
                }
                $this->saveCache();
            } elseif (!$this->refreshed && filemtime($info['file']) !== $info['time']) {
                $this->updateFile($info['file']);
                if (!isset($this->classes[$type])) {
                    $this->classes[$type] = 0;
                }
                $this->saveCache();
            }
        }
        if (isset($this->classes[$type]['file'])) {
            if ($this->classes[$type]['orig'] !== $orig) {
                trigger_error("Case mismatch on class name '{$orig}', correct name is '{$this->classes[$type]['orig']}'.", E_USER_WARNING);
            }
            call_user_func(function ($file) {
                require $file;
            }, $this->classes[$type]['file']);
        } else {
            $this->missing[$type] = TRUE;
        }
    }

Usage Example

Beispiel #1
0
 public function tryLoad($type)
 {
     if (!$this->initialized) {
         $this->initialize();
     }
     parent::tryLoad($type);
 }
All Usage Examples Of Nette\Loaders\RobotLoader::tryLoad