Exemplo n.º 1
0
 /**
  * @param  string  presenter name
  * @return string  class name
  * @throws InvalidPresenterException
  */
 public function getPresenterClass(&$name)
 {
     if (isset($this->cache[$name])) {
         list($class, $name) = $this->cache[$name];
         return $class;
     }
     if (!is_string($name) || !preg_match("#^[a-zA-Z-ÿ][a-zA-Z0-9-ÿ:]*\$#", $name)) {
         throw new InvalidPresenterException("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)) {
             LimitedScope::load($file);
         }
         if (!class_exists($class)) {
             throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' was not found in '{$file}'.");
         }
     }
     $reflection = new ClassReflection($class);
     $class = $reflection->getName();
     if (!$reflection->implementsInterface('IPresenter')) {
         throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is not Nette\\Application\\IPresenter implementor.");
     }
     if ($reflection->isAbstract()) {
         throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is abstract.");
     }
     // canonicalize presenter name
     $realName = $this->unformatPresenterClass($class);
     if ($name !== $realName) {
         if ($this->caseSensitive) {
             throw new InvalidPresenterException("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;
 }
Exemplo n.º 2
0
 /**
  * Test the recovery of the name.
  */
 public function testGetName()
 {
     $reflectedClass = new ClassReflection('TRex\\Reflection\\resources\\Foo');
     $this->assertSame('TRex\\Reflection\\resources\\Foo', $reflectedClass->getName());
 }