Author: David Grudl
Inheritance: extends Nette\Object
コード例 #1
0
ファイル: PresenterHelper.php プロジェクト: pepakriz/Console
 /**
  * @return \Nette\Application\IPresenter|\Nette\Application\UI\Presenter
  * @throws \Kdyby\Console\InvalidStateException
  */
 public function getPresenter()
 {
     if (!($presenter = $this->app->getPresenter())) {
         throw new Kdyby\Console\InvalidStateException("There is currently no presenter");
     }
     return $presenter;
 }
コード例 #2
0
ファイル: Redirector.php プロジェクト: rixxi/event
 /**
  * @param IRedirect $event
  */
 public function handle(IEvent $event)
 {
     Helper::assertRedirectInterface($event);
     if ($event->hasRedirect()) {
         $event->performRedirect($this->application->getPresenter());
     }
 }
コード例 #3
0
ファイル: LinkChecker.php プロジェクト: srigi/ipub-security
 /**
  * Format link to format array('module:submodule:presenter', 'action')
  *
  * @param string $destination
  *
  * @return array(presenter, action)
  */
 public function formatLink($destination)
 {
     if ($destination == 'this') {
         return array($this->application->getPresenter()->getName(), $this->application->getPresenter()->getAction());
     }
     $parts = explode(':', $destination);
     if ($destination[0] != ':') {
         $current = explode(':', $this->application->getPresenter()->getName());
         if (strpos($destination, ':') !== FALSE) {
             // Remove presenter
             array_pop($current);
         }
         $parts = array_merge($current, $parts);
     } else {
         // Remove empty
         array_shift($parts);
     }
     if ($destination[strlen($destination) - 1] == ':') {
         // Remove empty
         array_pop($parts);
         $action = UI\Presenter::DEFAULT_ACTION;
     } else {
         $action = array_pop($parts);
     }
     return array(implode(':', $parts), $action);
 }
コード例 #4
0
ファイル: Panel.php プロジェクト: meridius/yadup
    /**
     * Whole panel after hover or click on tab
     * @return string
     */
    public function getPanel()
    {
        $presenter = $this->app->getPresenter();
        $linkRun = !$presenter ? "" : $presenter->link("Yadup:Update:Run");
        $linkCreate = !$presenter ? "" : $presenter->link("Yadup:Update:Create");
        $linkShowSettings = !$presenter ? "" : $presenter->link("Yadup:Update:ShowSettings");
        return $this->renderStyles() . $this->renderJavascript() . '
			<div class="js-yadupPanel">
				<div class="yadup-heading">
					<h1>DB updates</h1> 
					<input name="show_all" type="checkbox" title="Show all updates / Only from last full" data-link="' . $linkShowSettings . '" />
				</div>
				<div class="yadup-controls">
					<div class="yadup-controls-header">
						<table>
							<thead>
								<tr>
									<th>timestamp</th>
									<th>in DB</th>
									<th>on disk</th>
									<th>is full</th>
									<th title="Toggle selected">run</th>
								</tr>
							</thead>
						</table>
					</div>
					<div class="yadup-controls-inner">' . $this->updatorRenderService->renderTable() . '
					</div>
					<div class="yadup-controls-buttons">
						<input type="button" name="createUpdate" value="Create new" />
						<input type="button" name="runUpdates" value="Run selected" data-link="' . $linkRun . '" />
						<input type="button" name="cancel" value="Cancel" />
						<input type="button" name="saveFile" value="Save file" data-link="' . $linkCreate . '" />
					</div>
				</div>
				<div class="yadup-sqlPanel">
					<div class="yadup-sqlPanel-heading">
						<p class="yadup-sqlPanel-heading-run">
							<span></span>
							<span title="in DB"></span>
							<span title="on disk"></span>
							<span title="is full"></span>
						</p>
						<p class="yadup-sqlPanel-heading-create">
							<span title="If SQL is full database dump">
								<input id="yadup-sqlPanel-heading-create_is-full" name="is_full" type="checkbox" value="" />
								<label for="yadup-sqlPanel-heading-create_is-full">is full</label>
							</span>
						</p>
					</div>
					<div class="yadup-sqlPanel-query">
						<div class="yadup-sqlPanel-query-inner">
							<code class="jush-sql"></code>
							<textarea class="jush-sql" name="newSql" placeholder="Paste here your query"></textarea>
						</div>
					</div>
				</div>
			</div>';
    }
コード例 #5
0
ファイル: MethodHandler.php プロジェクト: lucien144/Restful
 /**
  * On application run
  * @param Application $application
  *
  * @throws BadRequestException
  */
 public function run(Application $application)
 {
     $router = $application->getRouter();
     $appRequest = $router->match($this->request);
     if (!$appRequest) {
         $this->checkAllowedMethods();
     }
 }
コード例 #6
0
ファイル: AjaxPanels.php プロジェクト: leonardoca/tools
 /**
  * @param Application $sender
  * @param \Exception  $e
  */
 public static function sendExceptionLogFile(Nette\Application\Application $sender, \Exception $e)
 {
     /** @var $presenter Presenter */
     if (Debugger::isEnabled() && Debugger::getBar() && ($presenter = $sender->getPresenter()) && preg_match('/exceptionLogFile/', $e->getMessage())) {
         echo file_exists($filename = $presenter->getParameter('file')) ? $presenter->payload->dibiPanel = file_get_contents($filename) : '"' . $presenter->getParameter('file') . '" not found.';
         //Debugger::$bar = false;
         die;
     }
 }
コード例 #7
0
ファイル: RoutingPanel.php プロジェクト: bazo/Tatami
 public static function initialize(Nette\Application\Application $application, Nette\Http\IRequest $httpRequest)
 {
     Debugger::$bar->addPanel(new self($application->getRouter(), $httpRequest));
     Debugger::$blueScreen->addPanel(function ($e) use($application) {
         if ($e === NULL) {
             return array('tab' => 'Nette Application', 'panel' => '<h3>Requests</h3>' . Nette\Diagnostics\Helpers::clickableDump($application->getRequests()) . '<h3>Presenter</h3>' . Nette\Diagnostics\Helpers::clickableDump($application->getPresenter()));
         }
     });
 }
コード例 #8
0
 public function generateHtml(InvoiceEntity $invoiceEntity)
 {
     /** @var NewsletterPresenter $presenter */
     $presenter = $this->application->getPresenterFactory()->createPresenter('Cms:Admin:Invoices');
     $presenter->autoCanonicalize = FALSE;
     $request = new \Nette\Application\Request('Cms:Admin:Invoices', 'GET', array('table-table-actions-show-item' => $invoiceEntity->id, 'do' => 'table-table-actions-show-click'));
     $response = $presenter->run($request);
     return (string) $response->getSource();
 }
コード例 #9
0
ファイル: RoutingPanel.php プロジェクト: nakoukal/fakturace
	public static function initializePanel(Nette\Application\Application $application)
	{
		Tracy\Debugger::getBlueScreen()->addPanel(function ($e) use ($application) {
			return $e ? NULL : array(
				'tab' => 'Nette Application',
				'panel' => '<h3>Requests</h3>' . Tracy\Dumper::toHtml($application->getRequests())
					. '<h3>Presenter</h3>' . Tracy\Dumper::toHtml($application->getPresenter()),
			);
		});
	}
コード例 #10
0
ファイル: TranslationBar.php プロジェクト: vbuilder/framework
 /**
  * Registers translation micro presenter
  * which handles translation saves
  *
  * This method is called from $app->onStartup() event
  */
 static function register(Nette\Application\Application $app)
 {
     if (isset(self::$registeredRoute)) {
         throw new Nette\InvalidStateException(__CLASS__ . "::register called twice?");
     }
     $routeList = $app->getRouter();
     self::$registeredRoute = new Nette\Application\Routers\Route('/<language [a-z]{2}>/vbuilder-translation-bar/<token [a-z0-9]{8}>', function (vBuilder\Localization\Translator $translator, Nette\Http\Session $session) use($app) {
         list($request) = $app->getRequests();
         $dictionary = NULL;
         foreach ($translator->getDictionaries() as $name => $dict) {
             if ($name == 'translationBar') {
                 $dictionary = $dict;
                 break;
             }
         }
         if ($dictionary === NULL) {
             throw new Nette\InvalidStateException("Missing translationBar dictionary");
         }
         if (!$dictionary->isFrozen()) {
             $dictionary->init($request->parameters['language']);
         }
         if (!$request->isPost()) {
             throw new Nette\Application\BadRequestException('Expected POST', 400);
         }
         // Check authorization token (basic CSRF prevention)
         $session = $session->getSection(strtr(__CLASS__, '\\', '.'));
         if (!isset($session->authToken) || $request->parameters['token'] != $session->authToken) {
             throw new Nette\Application\BadRequestException('Invalid token', 403);
         }
         // Process input
         $data = Nette\Utils\Json::decode(file_get_contents('php://input'), Nette\Utils\Json::FORCE_ARRAY);
         if (isset($data['translations'])) {
             foreach ($data['translations'] as $tr) {
                 if (!isset($tr['key']) || !isset($tr['value'])) {
                     continue;
                 }
                 $dictionary->addTranslation($tr['key'], (array) $tr['value']);
             }
         }
         // @note atomicity?
         $dictionary->save();
         $payload = array('ok' => TRUE);
         return new Nette\Application\Responses\JsonResponse($payload);
     });
     // Add our route as first
     $routeList[] = self::$registeredRoute;
     // Bypass the index check by expanding array
     for ($i = count($routeList) - 1; $i > 0; $i--) {
         $routeList[$i] = $routeList[$i - 1];
     }
     $routeList[0] = self::$registeredRoute;
 }
コード例 #11
0
ファイル: User.php プロジェクト: rixxi/user
 public function signIn(IUser $user)
 {
     $this->onSignIn($user);
     if ($this->expiration !== NULL) {
         $this->security->setExpiration($this->expiration);
     }
     if ($this->backlink !== NULL) {
         $presenter = $this->application->getPresenter();
         if (isset($presenter->{$this->backlink})) {
             $presenter->restoreRequest($presenter->{$this->backlink});
         }
     }
 }
コード例 #12
0
ファイル: Menu.php プロジェクト: FilipStryk/Nette-Menu
 /**
  * @param \Nette\Application\Application $application
  * @return \DK\Menu\Menu
  */
 public function init(Application $application)
 {
     if (($presenter = $application->getPresenter()) !== null) {
         /** @var $presenter \Nette\Application\UI\Presenter */
         $this->setPresenter($presenter);
     } else {
         $_this = $this;
         $application->onPresenter[] = function (Application $application, Presenter $presenter) use($_this) {
             $_this->setPresenter($presenter);
         };
     }
     return $this;
 }
コード例 #13
0
 public function __construct(IPresenterFactory $presenterFactory, IRouter $router, IRequest $httpRequest, IResponse $httpResponse)
 {
     parent::__construct($presenterFactory, $router, $httpRequest, $httpResponse);
     $this->presenterFactory = $presenterFactory;
     $this->router = $router;
     $this->httpRequest = $httpRequest;
     $this->httpResponse = $httpResponse;
 }
コード例 #14
0
ファイル: Application.php プロジェクト: norbe/framework
	public function run()
	{
		if (PHP_SAPI == "cli") {
			$this->context->console->run();
		} else {
			parent::run();
		}
	}
コード例 #15
0
ファイル: Panel.php プロジェクト: bauer01/unimapper-nette
 public function onResponse(NA\Application $application, NA\IResponse $response)
 {
     if ($this->config["panel"]["ajax"] && $application->getPresenter() instanceof \Nette\Application\UI\Presenter && $application->getPresenter()->isAjax()) {
         $debug = ["count" => count($this->_getElapsed())];
         if ($debug["count"]) {
             ob_start();
             include __DIR__ . "/panel/templates/results.phtml";
             $debug["template"] = ob_get_clean();
         }
         $data = base64_encode(json_encode($debug));
         // Workaround for Chrome header limit as https://github.com/Seldaek/monolog/issues/172
         if (strlen($data) > 240 * 1024) {
             $debug["template"] = "Incomplete logs, chrome header size limit reached!";
             $data = base64_encode(json_encode($debug));
         }
         $this->response->setHeader(self::HEADER_PREFIX, $data);
     }
 }
コード例 #16
0
ファイル: Presenter.php プロジェクト: ytnuk/web
 /**
  * @inheritDoc
  */
 public function loadState(array $params)
 {
     if (!($request = $params['request'] ?? $this->application->getRouter()->match($httpRequest = $this->getHttpRequest()))) {
         $request = $this->application->getRouter()->match(new Nette\Http\Request(new Nette\Http\UrlScript($httpRequest->getUrl()->getBaseUrl())));
     }
     if ($request) {
         $this->application->onRequest($this->application, $request);
         $params += $request->getParameters();
     }
     try {
         parent::loadState($params);
     } catch (Nette\Application\BadRequestException $exception) {
         if (!$this->web) {
             $this->web = new Ytnuk\Web\Entity();
             $this->web->menu = new Ytnuk\Menu\Entity();
         }
     }
 }
コード例 #17
0
ファイル: BasePresenter.php プロジェクト: castamir/sandbox
 protected function setErrorPresenter()
 {
     $errorPresenter = 'Error';
     $modules = explode(":", $this->name);
     unset($modules[count($modules) - 1]);
     while (count($modules) != 0) {
         $catched = FALSE;
         try {
             $errorPresenter = implode(":", $modules) . ':Error';
             $errorPresenterClass = $this->appl->getPresenterFactory()->getPresenterClass($errorPresenter);
         } catch (InvalidPresenterException $e) {
             $catched = TRUE;
         }
         if (!$catched) {
             break;
         }
         unset($modules[count($modules) - 1]);
     }
     $this->appl->errorPresenter = $errorPresenter;
 }
コード例 #18
0
 /**
  * @param MessageEntity $messageEntity
  * @return int
  */
 public function sendNewsletter(MessageEntity $messageEntity)
 {
     $newsletter = $messageEntity->newsletter;
     /** @var NewsletterPresenter $presenter */
     $presenter = $this->application->getPresenterFactory()->createPresenter('Vranovsko:Pages:Newsletter:Newsletter');
     $presenter->autoCanonicalize = FALSE;
     /** @var Message $message */
     $message = $this->mailFactory->invoke();
     $message->setSubject($newsletter->getSubject());
     $x = 0;
     foreach ($messageEntity->getAllUsers() ? $this->userRepository->findAll() : $messageEntity->users as $user) {
         $presenter->setMessageUser($user);
         $request = new \Nette\Application\Request('Vranovsko:Pages:Newsletter:Newsletter', 'GET', array('routeId' => $newsletter->route->id));
         $response = $presenter->run($request);
         $html = (string) $response->getSource();
         $userMessage = clone $message;
         $userMessage->addTo($user->email);
         $userMessage->setHtmlBody($html, FALSE);
         $userMessage->send();
         $x++;
     }
     return $x;
 }
コード例 #19
0
 /**
  * @param Application $app
  * @param IResponse $response
  */
 public function onResponse(Application $app, IResponse $response)
 {
     $_ENV['APP_RESPONSE_TIME_FLOAT'] = microtime(TRUE);
     $this->client->customTimeMetric('Nette/ResponseTime', $_ENV['APP_RESPONSE_TIME_FLOAT'], $_ENV['APP_REQUEST_TIME_FLOAT']);
     if (($presenter = $app->getPresenter()) && $presenter instanceof Presenter) {
         $module = $this->getModule($presenter->getName());
         $this->client->customTimeMetric("Presenter/{$module}/Shutdown", $_ENV['APP_PRESENTER_LEAVE'], $_ENV['APP_PRESENTER_SEND_RESPONSE']);
         $this->client->customTimeMetric("Presenter/{$module}/InitGlobals", $_ENV['APP_PRESENTER_REQUIREMENTS_BEGIN'], $_ENV['APP_PRESENTER_BEFORE_INIT']);
         $this->client->customTimeMetric("Presenter/{$module}/Startup", $_ENV['APP_PRESENTER_STARTUP_END'], $_ENV['APP_PRESENTER_REQUIREMENTS_BEGIN']);
         $this->client->customTimeMetric("Presenter/{$module}/Action", $_ENV['APP_PRESENTER_ACTION_END'], $_ENV['APP_PRESENTER_ACTION_BEGIN']);
         $this->client->customTimeMetric("Presenter/{$module}/Render", $_ENV['APP_PRESENTER_RENDER_END'], $_ENV['APP_PRESENTER_RENDER_BEGIN']);
         $this->client->customTimeMetric("Presenter/{$module}/BeforeRender", $_ENV['APP_PRESENTER_RENDER_BEGIN'], $_ENV['APP_PRESENTER_ACTION_END']);
         $this->client->customTimeMetric("Presenter/{$module}/ProcessSignal", $_ENV['APP_PRESENTER_SIGNAL_END'], $_ENV['APP_PRESENTER_SIGNAL_BEGIN']);
         $this->client->customTimeMetric("Presenter/{$module}/AfterRender", $_ENV['APP_PRESENTER_AFTER_RENDER_END'], $_ENV['APP_PRESENTER_RENDER_END']);
         $this->client->customTimeMetric("Presenter/{$module}/SendTemplate", $_ENV['APP_PRESENTER_SEND_TEMPLATE_END'], $_ENV['APP_PRESENTER_SEND_TEMPLATE_BEGIN']);
     }
 }
コード例 #20
0
ファイル: Panel.php プロジェクト: carrooi/nette-translator
 /**
  * @return string
  */
 public function getPanel()
 {
     $groups = array();
     $empty = true;
     $translated = $this->translator->getTranslated();
     foreach ($this->groups as $name => $pattern) {
         $group = array();
         $translated = array_filter($translated, function ($translation) use(&$group, $pattern) {
             if (preg_match('/' . $pattern . '/', $translation)) {
                 $group[] = $translation;
                 return false;
             } else {
                 return true;
             }
         });
         if ($empty && !empty($group)) {
             $empty = false;
         }
         $groups[$name] = array('collapsed' => true, 'data' => $group);
     }
     $groups['Untranslated'] = array('collapsed' => false, 'data' => $this->translator->getUntranslated());
     $groups['Translated'] = array('collapsed' => false, 'data' => $translated);
     if (count($groups['Untranslated']['data']) === 0 && count($groups['Translated']['data']) === 0 && $empty) {
         return null;
     }
     $translator = $this->translator;
     $link = $this->application->getPresenter()->link('this');
     $xhrHeader = self::XHR_HEADER;
     $ajaxActionKey = self::AJAX_ACTION_KEY;
     $ajaxMessageKey = self::AJAX_MESSAGE_KEY;
     $ajaxTranslationKey = self::AJAX_TRANSLATION_KEY;
     $ajaxActionLoad = self::AJAX_ACTION_LOAD;
     $ajaxActionEdit = self::AJAX_ACTION_EDIT;
     $cookieDebugKey = self::COOKIE_DEBUG_KEY;
     $checkMessage = function ($message) {
         return preg_match('/^[a-zA-Z0-9._]+$/', $message) > 0;
     };
     ob_start();
     require __DIR__ . '/panel.phtml';
     return ob_get_clean();
 }
コード例 #21
0
 /**
  * Nastaví URL na kterou bude uživatel z Facebook.com přesměrován
  * Přijímá nette zápis odkazů (např.: Homepage:default) nebo absolutní URL
  * @param string $redirectUri
  * @throws \Nette\InvalidArgumentException
  * @return void
  */
 public function setRedirectUri($redirectUri)
 {
     /* @var $currentPresenter \Nette\Application\UI\Presenter */
     $currentPresenter = $this->application->getPresenter();
     $netteAbsoluteLinkPrexix = "//";
     try {
         if (\Nette\Utils\Strings::startsWith($redirectUri, "//")) {
             $netteAbsoluteLinkPrexix = "";
         }
         $absoluteUri = $currentPresenter->link($netteAbsoluteLinkPrexix . $redirectUri);
         if (\Nette\Utils\Strings::startsWith($absoluteUri, "error:")) {
             throw new \Nette\Application\UI\InvalidLinkException();
         }
     } catch (\Nette\Application\UI\InvalidLinkException $exc) {
         if (Validators::isUrl($redirectUri) === TRUE) {
             $absoluteUri = $redirectUri;
         } else {
             throw new Exceptions\InvalidRedirectUriException("Given \"" . $redirectUri . "\" is not valid absolute URL or nette link.");
         }
     }
     $this->redirectUri = $absoluteUri;
 }
コード例 #22
0
ファイル: Google.php プロジェクト: shailendra9/Google-2
 /**
  * @param AbstractDialog $dialog
  * @return Application\UI\Link|UrlScript
  */
 public function getReturnLink(AbstractDialog $dialog = NULL)
 {
     $destination = $this->config->getReturnDestination();
     if ($destination[0] instanceof Url) {
         return $destination[0];
     }
     $reset = array();
     /** @var Application\UI\Presenter $presenter */
     $presenter = $this->app->getPresenter();
     /** @var PresenterComponent $parent */
     $parent = $dialog ? $dialog->getParent() : $presenter;
     do {
         $prefix = $parent instanceof Application\IPresenter ? '' : $parent->lookupPath('Nette\\Application\\IPresenter');
         foreach ($parent->getReflection()->getPersistentParams() as $name => $meta) {
             $reset[($prefix ? $prefix . IComponent::NAME_SEPARATOR : '') . $name] = array_key_exists('def', $meta) ? $meta['def'] : NULL;
         }
     } while ($parent = $parent->getParent());
     $args = is_array($destination[1]) ? $destination[1] : array_slice($destination, 1);
     if ($dialog !== NULL) {
         $args['do'] = $dialog->lookupPath('Nette\\Application\\IPresenter') . IComponent::NAME_SEPARATOR . 'response';
     }
     return $presenter->lazyLink('//' . ltrim($destination[0], '/'), $args + $reset);
 }
コード例 #23
0
ファイル: Presenter.php プロジェクト: pdostal/nette-blog
 /**
  * Request/URL factory.
  * @param  PresenterComponent  base
  * @param  string   destination in format "[[module:]presenter:]action" or "signal!" or "this"
  * @param  array    array of arguments
  * @param  string   forward|redirect|link
  * @return string   URL
  * @throws InvalidLinkException
  * @internal
  */
 protected function createRequest($component, $destination, array $args, $mode)
 {
     // note: createRequest supposes that saveState(), run() & tryCall() behaviour is final
     // cached services for better performance
     static $presenterFactory, $router, $refUrl;
     if ($presenterFactory === NULL) {
         $presenterFactory = $this->application->getPresenterFactory();
         $router = $this->application->getRouter();
         $refUrl = new Http\Url($this->httpRequest->getUrl());
         $refUrl->setPath($this->httpRequest->getUrl()->getScriptPath());
     }
     $this->lastCreatedRequest = $this->lastCreatedRequestFlag = NULL;
     // PARSE DESTINATION
     // 1) fragment
     $a = strpos($destination, '#');
     if ($a === FALSE) {
         $fragment = '';
     } else {
         $fragment = substr($destination, $a);
         $destination = substr($destination, 0, $a);
     }
     // 2) ?query syntax
     $a = strpos($destination, '?');
     if ($a !== FALSE) {
         parse_str(substr($destination, $a + 1), $args);
         // requires disabled magic quotes
         $destination = substr($destination, 0, $a);
     }
     // 3) URL scheme
     $a = strpos($destination, '//');
     if ($a === FALSE) {
         $scheme = FALSE;
     } else {
         $scheme = substr($destination, 0, $a);
         $destination = substr($destination, $a + 2);
     }
     // 4) signal or empty
     if (!$component instanceof Presenter || substr($destination, -1) === '!') {
         $signal = rtrim($destination, '!');
         $a = strrpos($signal, ':');
         if ($a !== FALSE) {
             $component = $component->getComponent(strtr(substr($signal, 0, $a), ':', '-'));
             $signal = (string) substr($signal, $a + 1);
         }
         if ($signal == NULL) {
             // intentionally ==
             throw new InvalidLinkException("Signal must be non-empty string.");
         }
         $destination = 'this';
     }
     if ($destination == NULL) {
         // intentionally ==
         throw new InvalidLinkException("Destination must be non-empty string.");
     }
     // 5) presenter: action
     $current = FALSE;
     $a = strrpos($destination, ':');
     if ($a === FALSE) {
         $action = $destination === 'this' ? $this->action : $destination;
         $presenter = $this->getName();
         $presenterClass = get_class($this);
     } else {
         $action = (string) substr($destination, $a + 1);
         if ($destination[0] === ':') {
             // absolute
             if ($a < 2) {
                 throw new InvalidLinkException("Missing presenter name in '{$destination}'.");
             }
             $presenter = substr($destination, 1, $a - 1);
         } else {
             // relative
             $presenter = $this->getName();
             $b = strrpos($presenter, ':');
             if ($b === FALSE) {
                 // no module
                 $presenter = substr($destination, 0, $a);
             } else {
                 // with module
                 $presenter = substr($presenter, 0, $b + 1) . substr($destination, 0, $a);
             }
         }
         try {
             $presenterClass = $presenterFactory->getPresenterClass($presenter);
         } catch (Application\InvalidPresenterException $e) {
             throw new InvalidLinkException($e->getMessage(), NULL, $e);
         }
     }
     // PROCESS SIGNAL ARGUMENTS
     if (isset($signal)) {
         // $component must be IStatePersistent
         $reflection = new PresenterComponentReflection(get_class($component));
         if ($signal === 'this') {
             // means "no signal"
             $signal = '';
             if (array_key_exists(0, $args)) {
                 throw new InvalidLinkException("Unable to pass parameters to 'this!' signal.");
             }
         } elseif (strpos($signal, self::NAME_SEPARATOR) === FALSE) {
             // counterpart of signalReceived() & tryCall()
             $method = $component->formatSignalMethod($signal);
             if (!$reflection->hasCallableMethod($method)) {
                 throw new InvalidLinkException("Unknown signal '{$signal}', missing handler {$reflection->name}::{$method}()");
             }
             if ($args) {
                 // convert indexed parameters to named
                 self::argsToParams(get_class($component), $method, $args);
             }
         }
         // counterpart of IStatePersistent
         if ($args && array_intersect_key($args, $reflection->getPersistentParams())) {
             $component->saveState($args);
         }
         if ($args && $component !== $this) {
             $prefix = $component->getUniqueId() . self::NAME_SEPARATOR;
             foreach ($args as $key => $val) {
                 unset($args[$key]);
                 $args[$prefix . $key] = $val;
             }
         }
     }
     // PROCESS ARGUMENTS
     if (is_subclass_of($presenterClass, __CLASS__)) {
         if ($action === '') {
             $action = self::DEFAULT_ACTION;
         }
         $current = ($action === '*' || strcasecmp($action, $this->action) === 0) && $presenterClass === get_class($this);
         $reflection = new PresenterComponentReflection($presenterClass);
         if ($args || $destination === 'this') {
             // counterpart of run() & tryCall()
             $method = $presenterClass::formatActionMethod($action);
             if (!$reflection->hasCallableMethod($method)) {
                 $method = $presenterClass::formatRenderMethod($action);
                 if (!$reflection->hasCallableMethod($method)) {
                     $method = NULL;
                 }
             }
             // convert indexed parameters to named
             if ($method === NULL) {
                 if (array_key_exists(0, $args)) {
                     throw new InvalidLinkException("Unable to pass parameters to action '{$presenter}:{$action}', missing corresponding method.");
                 }
             } elseif ($destination === 'this') {
                 self::argsToParams($presenterClass, $method, $args, $this->params);
             } else {
                 self::argsToParams($presenterClass, $method, $args);
             }
         }
         // counterpart of IStatePersistent
         if ($args && array_intersect_key($args, $reflection->getPersistentParams())) {
             $this->saveState($args, $reflection);
         }
         if ($mode === 'redirect') {
             $this->saveGlobalState();
         }
         $globalState = $this->getGlobalState($destination === 'this' ? NULL : $presenterClass);
         if ($current && $args) {
             $tmp = $globalState + $this->params;
             foreach ($args as $key => $val) {
                 if (http_build_query(array($val)) !== (isset($tmp[$key]) ? http_build_query(array($tmp[$key])) : '')) {
                     $current = FALSE;
                     break;
                 }
             }
         }
         $args += $globalState;
     }
     // ADD ACTION & SIGNAL & FLASH
     if ($action) {
         $args[self::ACTION_KEY] = $action;
     }
     if (!empty($signal)) {
         $args[self::SIGNAL_KEY] = $component->getParameterId($signal);
         $current = $current && $args[self::SIGNAL_KEY] === $this->getParameter(self::SIGNAL_KEY);
     }
     if (($mode === 'redirect' || $mode === 'forward') && $this->hasFlashSession()) {
         $args[self::FLASH_KEY] = $this->getParameter(self::FLASH_KEY);
     }
     $this->lastCreatedRequest = new Application\Request($presenter, Application\Request::FORWARD, $args, array(), array());
     $this->lastCreatedRequestFlag = array('current' => $current);
     if ($mode === 'forward' || $mode === 'test') {
         return;
     }
     // CONSTRUCT URL
     $url = $router->constructUrl($this->lastCreatedRequest, $refUrl);
     if ($url === NULL) {
         unset($args[self::ACTION_KEY]);
         $params = urldecode(http_build_query($args, NULL, ', '));
         throw new InvalidLinkException("No route for {$presenter}:{$action}({$params})");
     }
     // make URL relative if possible
     if ($mode === 'link' && $scheme === FALSE && !$this->absoluteUrls) {
         $hostUrl = $refUrl->getHostUrl() . '/';
         if (strncmp($url, $hostUrl, strlen($hostUrl)) === 0) {
             $url = substr($url, strlen($hostUrl) - 1);
         }
     }
     return $url . $fragment;
 }
コード例 #24
0
ファイル: stopWatch.php プロジェクト: BroukPytlik/agility
 /**
  * Constructor
  * @author Pavel Železný <*****@*****.**>
  * @param \Nette\Application\Application $application
  * @return void
  */
 public function __construct(\Nette\Application\Application $application)
 {
     parent::__construct($application->getPresenter(), $this->getId());
 }
コード例 #25
0
ファイル: RoutingPanel.php プロジェクト: svobodni/web
 public static function initializePanel(Nette\Application\Application $application)
 {
     Debugger::$blueScreen->addPanel(function ($e) use($application) {
         return $e ? NULL : array('tab' => 'Nette Application', 'panel' => '<h3>Requests</h3>' . Nette\Diagnostics\Helpers::clickableDump($application->getRequests()) . '<h3>Presenter</h3>' . Nette\Diagnostics\Helpers::clickableDump($application->getPresenter()));
     });
 }
コード例 #26
0
ファイル: Configurator.php プロジェクト: JPalounek/IconStore
 /**
  * @return Nette\Application\Application
  */
 public static function createApplication()
 {
     if (Environment::getVariable('baseUri', NULL) === NULL) {
         Environment::setVariable('baseUri', Environment::getHttpRequest()->getUri()->getBasePath());
     }
     $context = clone Environment::getContext();
     $context->addService('Nette\\Application\\IRouter', 'Nette\\Application\\MultiRouter');
     if (!$context->hasService('Nette\\Application\\IPresenterLoader')) {
         $context->addService('Nette\\Application\\IPresenterLoader', function () {
             return new Nette\Application\PresenterLoader(Environment::getVariable('appDir'));
         });
     }
     $application = new Nette\Application\Application();
     $application->setContext($context);
     $application->catchExceptions = Environment::isProduction();
     return $application;
 }
コード例 #27
0
ファイル: Container.php プロジェクト: webchemistry/forms
 /**
  * @return IPresenter|Presenter|null
  */
 protected function getPresenter()
 {
     if ($this->application) {
         return $this->application->getPresenter();
     }
 }
コード例 #28
0
ファイル: LatteHelper.php プロジェクト: svobodni/web
 /**
  * @param $text
  * @return string
  */
 public function run($text)
 {
     $template = $this->application->getPresenter()->createTemplate("\\Nette\\Templating\\Template");
     $template->setSource($text);
     return $template->__toString();
 }
コード例 #29
0
ファイル: Strategy.php プロジェクト: zaxxx/zaxcms
 public function __construct(Nette\Application\Application $application)
 {
     $this->application = $application;
     $this->request = $application->createInitialRequest();
 }
コード例 #30
0
ファイル: Presenter.php プロジェクト: vbuilder/framework
 /**
  * Returns absolute URL for given resource path
  *
  * @internal
  *
  * @param string resource path
  * @param array of parameters
  *
  * @return string absolute url
  */
 public function link($path = NULL, array $parameters = array())
 {
     $r = new Nette\Application\Request($this->appRequest->getPresenterName(), $this->appRequest->getMethod(), array_merge(array('action' => 'default', self::PARAM_KEY_PATH => ltrim($path, '/')), $parameters));
     return $this->application->getRouter()->constructUrl($r, $this->httpRequest->getUrl());
 }