示例#1
0
 /**
  * @param $name
  * @return Nette\ComponentModel\IComponent
  * to have translated even forms add this method too
  */
 protected function createComponent($name)
 {
     $component = parent::createComponent($name);
     if ($component instanceof Form) {
     }
     return $component;
 }
示例#2
0
 /**
  * @param string $name
  * @return \Nette\ComponentModel\IComponent
  */
 protected function createComponent($name = NULL)
 {
     $method = 'createComponent' . ucfirst($name);
     $rc = $this->getReflection()->getMethod($method);
     $this->checkRequirements($rc);
     return parent::createComponent($name);
 }
示例#3
0
 /**
  * @param string $name
  * @return IComponent
  */
 protected function createComponent($name)
 {
     $component = parent::createComponent($name);
     if ($component instanceof \Nette\Forms\Form) {
         $component->setTranslator($this->translator);
     }
     return $component;
 }
 public function createComponent($name)
 {
     $ucname = ucfirst($name);
     $method = 'createComponent' . $ucname;
     $presenterReflection = $this->getReflection();
     if ($presenterReflection->hasMethod($method)) {
         $reflection = $presenterReflection->getMethod($method);
         $this->checkRequirements($reflection);
         $annotations = (array) $reflection->getAnnotation('Action');
         if (!empty($annotations) && !in_array($this->getAction(), $annotations)) {
             throw new ForbiddenRequestException("Creation of component '{$name}' is forbidden for action '" . $this->getAction() . "'.");
         }
     }
     return parent::createComponent($name);
 }
示例#5
0
 protected function createComponent($name)
 {
     if (substr($name, -4) === 'Form') {
         $formClass = 'App\\Controls\\Forms\\' . ucFirst(substr($name, 0, -4));
         if (class_exists($formClass)) {
             return $this->context->createInstance(FormControl::class, [$formClass]);
         }
     } else {
         $controlClass = 'App\\Controls\\' . ucFirst($name);
         if (class_exists($controlClass)) {
             return $this->context->createInstance($controlClass);
         }
     }
     return parent::createComponent($name);
 }
示例#6
0
 /**
  * @author  Jiří Šifalda
  * @param string
  * @return \Nette\Application\UI\Multiplier|\Nette\ComponentModel\IComponent
  */
 protected function createComponent($name)
 {
     $method = 'createComponent' . ucfirst($name);
     if (method_exists($this, $method)) {
         $this->checkRequirements($this->getReflection()->getMethod($method));
         if (\Nette\Reflection\Method::from($this, $method)->hasAnnotation('multiple')) {
             $presenter = $this;
             return new \Nette\Application\UI\Multiplier(function ($id) use($presenter, $method) {
                 $defaultArgs = array($presenter, $id);
                 return call_user_func_array(array($presenter, $method), $defaultArgs);
             });
             # in PHP 5.4 factory for multiplied component can be protected
             # return new UI\Multiplier(function ($id) use ($name) {
             #	return $this->$method($this, $id, $this->getDataset($name));
             # });
         }
     }
     return parent::createComponent($name);
 }
 protected function createComponent($name)
 {
     $ucname = ucfirst($name);
     $method = 'createComponent' . $ucname;
     $presenterReflection = $this->getReflection();
     if ($presenterReflection->hasMethod($method)) {
         $methodReflection = $presenterReflection->getMethod($method);
         $this->checkRequirements($methodReflection);
         if ($methodReflection->hasAnnotation('Actions')) {
             $actions = explode(',', $methodReflection->getAnnotation('Actions'));
             foreach ($actions as $key => $action) {
                 $actions[$key] = trim($action);
             }
             if (!empty($actions) and !in_array($this->getAction(), $actions)) {
                 throw new Nette\Application\ForbiddenRequestException("Creation of component '{$name}' is forbidden for action '{$this->action}'.");
             }
         }
     }
     return parent::createComponent($name);
 }
示例#8
0
 /**
  * Component factory. Delegates the creation of components to a createComponent<Name> method.
  *
  * @param  string      component name
  * @return IComponent  the created component (optionally)
  */
 protected function createComponent($name)
 {
     // parent
     if (($control = parent::createComponent($name)) == TRUE) {
         return $control;
     }
     // widget from widgetManager
     if ($this->widgetManager->hasWidget($name)) {
         return $this->widgetManager->getWidget($name)->invoke();
     }
     throw new \Nette\InvalidArgumentException("Component or widget with name '{$name}' does not exist.");
 }
示例#9
0
	/**
	 * Component factory. Delegates the creation of components to a createComponent<Name> method.
	 * @param  string
	 * @return \Nette\ComponentModel\IComponent
	 */
	protected function createComponent($name)
	{
		$container = $this->getContext()->components;
		if ($container->hasComponent($name)) {
			return $container->getComponent($name, $this);
		}

		return parent::createComponent($name);
	}