Exemple #1
0
 function getPresenterClass(&$name)
 {
     if (isset($this->cache[$name])) {
         list($class, $name) = $this->cache[$name];
         return $class;
     }
     if (!is_string($name) || !NString::match($name, "#^[a-zA-Z-�][a-zA-Z0-9-�:]*\$#")) {
         throw new NInvalidPresenterException("Presenter name must be alphanumeric string, '{$name}' is invalid.");
     }
     $class = $this->formatPresenterClass($name);
     if (!class_exists($class)) {
         $file = $this->formatPresenterFile($name);
         if (is_file($file) && is_readable($file)) {
             NLimitedScope::load($file);
         }
         if (!class_exists($class)) {
             throw new NInvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' was not found in '{$file}'.");
         }
     }
     $reflection = new NClassReflection($class);
     $class = $reflection->getName();
     if (!$reflection->implementsInterface('IPresenter')) {
         throw new NInvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is not Nette\\Application\\IPresenter implementor.");
     }
     if ($reflection->isAbstract()) {
         throw new NInvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is abstract.");
     }
     $realName = $this->unformatPresenterClass($class);
     if ($name !== $realName) {
         if ($this->caseSensitive) {
             throw new NInvalidPresenterException("Cannot load presenter '{$name}', case mismatch. Real name is '{$realName}'.");
         } else {
             $this->cache[$name] = array($class, $realName);
             $name = $realName;
         }
     } else {
         $this->cache[$name] = array($class, $realName);
     }
     return $class;
 }
	/**
	 * @param  string  presenter name
	 * @return string  class name
	 * @throws NInvalidPresenterException
	 */
	public function getPresenterClass(& $name)
	{
		if (isset($this->cache[$name])) {
			list($class, $name) = $this->cache[$name];
			return $class;
		}

		if (!is_string($name) || !NStrings::match($name, "#^[a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff:]*$#")) {
			throw new NInvalidPresenterException("Presenter name must be alphanumeric string, '$name' is invalid.");
		}

		$class = $this->formatPresenterClass($name);

		if (!class_exists($class)) {
			// internal autoloading
			$file = $this->formatPresenterFile($name);
			if (is_file($file) && is_readable($file)) {
				NLimitedScope::load($file, TRUE);
			}

			if (!class_exists($class)) {
				throw new NInvalidPresenterException("Cannot load presenter '$name', class '$class' was not found in '$file'.");
			}
		}

		$reflection = new NClassReflection($class);
		$class = $reflection->getName();

		if (!$reflection->implementsInterface('IPresenter')) {
			throw new NInvalidPresenterException("Cannot load presenter '$name', class '$class' is not IPresenter implementor.");
		}

		if ($reflection->isAbstract()) {
			throw new NInvalidPresenterException("Cannot load presenter '$name', class '$class' is abstract.");
		}

		// canonicalize presenter name
		$realName = $this->unformatPresenterClass($class);
		if ($name !== $realName) {
			if ($this->caseSensitive) {
				throw new NInvalidPresenterException("Cannot load presenter '$name', case mismatch. Real name is '$realName'.");
			} else {
				$this->cache[$name] = array($class, $realName);
				$name = $realName;
			}
		} else {
			$this->cache[$name] = array($class, $realName);
		}

		return $class;
	}