Exemple #1
0
 public function __call($name, $args)
 {
     if (Strings::startsWith($name, 'render')) {
         $this->doRenderView($this->getViewByRenderMethod($name), $args);
     } else {
         return parent::__call($name, $args);
     }
 }
 public function __call($name, $args)
 {
     if (strpos($name, 'render') !== 0) {
         return parent::__call($name, $args);
     }
     $this->wrapRender(lcFirst(substr($name, 6)));
     return NULL;
 }
Exemple #3
0
 public function __call($name, $args)
 {
     if (preg_match('#([[:alnum:]]+)Command#', $name, $matches)) {
         $commandClassName = 'Bubo\\Commanding\\PageCommands\\' . ucfirst($matches[0]);
         if (class_exists($commandClassName)) {
             $reflector = new \ReflectionClass($commandClassName);
             $command = $reflector->newInstanceArgs($args);
             return $command->setPageManager($this->pageManager)->execute();
         }
     }
     parent::__call($name, $args);
 }
Exemple #4
0
 /**
  * @param string $name
  * @param string $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     if ($name === 'render') {
         if (isset($args[0]) && is_array($args[0]) && isset($args[0]['config'])) {
             $this->configureControl($args[0]['config']);
         }
         if (method_exists($this, 'renderDefault')) {
             call_user_func_array(array($this, 'renderDefault'), $args);
         }
         $this->template->setFile($this->formatTemplateFile());
         $this->template->render();
         if (method_exists($this, 'afterRender')) {
             call_user_func_array(array($this, 'afterRender'), array());
         }
         if (isset($args[0]) && is_array($args[0]) && isset($args[0]['config'])) {
             $this->unconfigureControl();
         }
         return;
     }
     return parent::__call($name, $args);
 }
Exemple #5
0
 /**
  * @param string $methodName
  * @param array $args
  *
  * @return mixed
  * @throws Nette\Application\BadRequestException
  */
 public function __call($methodName, $args)
 {
     if (Strings::startsWith($methodName, 'render')) {
         $subMethod = lcfirst(Strings::replace($methodName, '~render(\\w*)~', '\\1'));
         $files = $this->formatTemplateFiles($subMethod);
         foreach ($files as $file) {
             if (is_file($file)) {
                 $this->template->setFile($file);
                 break;
             }
         }
         if (!$this->template->getFile()) {
             $file = preg_replace('#^.*([/\\\\].{1,70})\\z#U', "…\$1", reset($files));
             $file = strtr($file, '/', DIRECTORY_SEPARATOR);
             throw new Nette\Application\BadRequestException("Page not found. Missing template '{$file}'.");
         }
         $this->tryCall("prepare{$subMethod}", (array) @$args[0]);
         $this->tryCall('beforeRender', []);
         $this->template->render();
     } else {
         return parent::__call($methodName, $args);
     }
 }
Exemple #6
0
 public function __call($name, $arguments = [])
 {
     if (Nette\Utils\Strings::startsWith($name, self::RENDER_METHOD)) {
         $rendering = $this->isRendering();
         $arguments = current($arguments) ?: $arguments;
         $arguments = (array) $arguments + ['snippet' => !$rendering, 'echo' => TRUE];
         $name = lcfirst(Nette\Utils\Strings::substring($name, strlen(self::RENDER_METHOD))) ?: $this->view;
         $isAjax = $this->getPresenter()->isAjax();
         $payload = $this->getPresenter()->getPayload();
         $defaultView = $this->view;
         $defaultSnippetMode = $this->snippetMode;
         $views = $this->views;
         if ($rendering || !$isAjax) {
             $views = array_intersect_key($views, [$name => TRUE]);
         } elseif ($this->snippetMode) {
             $views = array_intersect_key($views, $this->invalidViews);
         }
         $this->isRendering(TRUE);
         foreach (array_diff_key($views, $this->rendered) as $view => $snippetMode) {
             $this->view = $view;
             $this->snippetMode = $isAjax && !$snippetMode;
             if ($this->cache && is_callable($snippetMode)) {
                 $dependencies = [Nette\Caching\Cache::TAGS => [], Nette\Caching\Cache::FILES => []];
                 $key = $this->getCacheKey();
                 $providers = [];
                 foreach ($snippetMode(...[&$dependencies]) as $dependency) {
                     if ($dependency instanceof Ytnuk\Cache\Provider) {
                         $providers[] = $dependency;
                         $key[] = $dependency->getCacheKey();
                     } else {
                         $key[] = $dependency;
                     }
                 }
                 list($output, $this->related) = $this->cache->load($key, function (&$dp) use(&$dependencies, $providers) {
                     foreach ($providers as $provider) {
                         if ($provider instanceof Ytnuk\Cache\Provider) {
                             $dependencies[Nette\Caching\Cache::TAGS] = array_merge($dependencies[Nette\Caching\Cache::TAGS], $provider->getCacheTags());
                         }
                     }
                     $dependencies[Nette\Caching\Cache::TAGS] = array_merge($dependencies[Nette\Caching\Cache::TAGS], $this->getCacheTags());
                     $dependencies[Nette\Caching\Cache::TAGS][] = static::class;
                     $output = $this->render();
                     $dependencies[Nette\Caching\Cache::FILES][] = $this->getTemplate()->getFile();
                     $dp = $dependencies;
                     return [$output, $this->related];
                 });
             } else {
                 $output = $this->render();
             }
             if ($snippetMode && $isAjax) {
                 $payload->snippets[$this->getSnippetId()] = $output;
             }
             if ($control = $this->lookupRendering()) {
                 $control->setRelated($this, $this->view);
             }
             $this->rendered[$view] = $output;
         }
         $this->view = $defaultView;
         foreach ($this->related[$this->view] as $subName => $subViews) {
             $related = $this[$subName] ?? NULL;
             if ($related instanceof Nette\Application\UI\IRenderable) {
                 $related->redrawControl();
             }
         }
         $output = NULL;
         if ($this->snippetMode = $defaultSnippetMode) {
             Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($this);
         } elseif (array_key_exists($this->view = $name, $this->rendered)) {
             $output = $this->rendered[$this->view];
             if (!$isAjax) {
                 foreach ($this->related[$this->view] as $relatedName => $relatedViews) {
                     $related = $this->getComponent($relatedName);
                     if ($related instanceof self) {
                         foreach ($relatedViews as $relatedView => $relatedSnippetId) {
                             $relatedSnippet = Nette\Utils\Html::el(is_string($arguments['snippet']) ? $arguments['snippet'] : 'div', ['id' => $relatedSnippetId]);
                             if (strpos($output, (string) $relatedSnippet) !== FALSE) {
                                 $output = str_replace((string) $relatedSnippet, $relatedSnippet->setHtml($related->__call(self::RENDER_METHOD . ucfirst($relatedView), ['echo' => FALSE, 'snippet' => FALSE])), $output);
                             }
                         }
                     }
                 }
             }
             if ($arguments['snippet'] && $this->views[$this->view] && ($snippetId = $this->getSnippetId())) {
                 $snippet = Nette\Utils\Html::el(is_string($arguments['snippet']) ? $arguments['snippet'] : 'div', ['id' => $snippetId]);
                 if ($isAjax && $this->related[$this->view]) {
                     $snippetMode = $this->snippetMode;
                     Nette\Bridges\ApplicationLatte\UIRuntime::renderSnippets($this);
                     $this->snippetMode = $snippetMode;
                 }
                 if ($isAjax && !isset($payload->snippets[$snippetId]) || !$isAjax && !$this->lookupRendering()) {
                     $snippet->setHtml($output);
                 }
                 $output = $snippet->render();
             }
             if ($arguments['echo']) {
                 echo $output;
             }
             $this->view = $defaultView;
         }
         $this->isRendering(FALSE);
         return $output;
     }
     return parent::__call($name, $arguments);
 }
Exemple #7
0
 /**
  * render method hook
  *
  * @param       $func
  * @param array $args
  * @return mixed|void
  */
 public function __call($func, $args = [])
 {
     if (Strings::startsWith($func, 'render')) {
         $tmp = @array_reduce($args, 'array_merge', []);
         // @ - intentionally
         if ($tmp === NULL) {
             $tmp = $args;
         }
         return $this->run(Strings::substring($func, 6), $tmp);
     }
     return parent::__call($func, $args);
 }
Exemple #8
0
 /**
  *
  * @param string $name
  * @param array $args
  */
 public function __call($methodName, $args)
 {
     if (Nette\Utils\Strings::startsWith($methodName, 'render')) {
         // Signaly maji prednost pred view ze sablony
         if (!$this->actionHandled) {
             $this->changeView(lcfirst(substr($methodName, 6)));
             return call_user_func_array(array($this, 'render'), $args);
         } else {
             $this->render();
         }
         return;
     }
     return parent::__call($methodName, $args);
 }
Exemple #9
0
 /**
  * Mediates standard functions from \Nette\Application\UI\Form
  *
  * @param $name
  * @param $arguments
  *
  * @return mixed|void
  */
 public function __call($name, $arguments)
 {
     if (method_exists($this->form, $name)) {
         return call_user_func_array($this->form->{$name}, $arguments);
     }
     parent::__call($name, $arguments);
 }