作者:vrtak-c
项目:newrelic-nett
/**
* @param \Nette\Application\Application $application
* @param \Nette\Application\Request $request
*/
public function __invoke(Application $application, Request $request)
{
if (PHP_SAPI === 'cli') {
newrelic_background_job(TRUE);
}
$params = $request->getParameters();
$action = $request->getPresenterName();
if (isset($params[$this->actionKey])) {
$action = sprintf('%s:%s', $action, $params[$this->actionKey]);
}
if (!empty($this->map)) {
foreach ($this->map as $pattern => $appName) {
if ($pattern === '*') {
continue;
}
if (Strings::endsWith($pattern, '*')) {
$pattern = Strings::substring($pattern, 0, -1);
}
if (Strings::startsWith($pattern, ':')) {
$pattern = Strings::substring($pattern, 1);
}
if (Strings::startsWith($action, $pattern)) {
\VrtakCZ\NewRelic\Tracy\Bootstrap::setup($appName, $this->license);
break;
}
}
}
newrelic_name_transaction($action);
newrelic_disable_autorum();
}
作者:bauer0
项目:unimapper-nett
public function constructUrl(Request $appRequest, Url $refUrl)
{
// Module prefix not match.
if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
return null;
}
$params = $appRequest->getParameters();
$urlStack = [];
// Module prefix
$moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName()));
$resourceName = array_pop($moduleFrags);
$urlStack += $moduleFrags;
// Resource
$urlStack[] = Strings::lower($resourceName);
// Id
if (isset($params['id']) && is_scalar($params['id'])) {
$urlStack[] = $params['id'];
unset($params['id']);
}
// Set custom action
if (isset($params['action']) && $this->_isApiAction($params['action'])) {
unset($params['action']);
}
$url = $refUrl->getBaseUrl() . implode('/', $urlStack);
// Add query parameters
if (!empty($params)) {
$url .= "?" . http_build_query($params);
}
return $url;
}
作者:luminousinfoway
项目:pccfoa
/**
* Constructs absolute URL from Request object.
* @return string|NULL
*/
public function constructUrl(Application\Request $appRequest, Nette\Http\Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return NULL;
}
$params = $appRequest->getParameters();
// presenter name
$presenter = $appRequest->getPresenterName();
if (strncmp($presenter, $this->module, strlen($this->module)) === 0) {
$params[self::PRESENTER_KEY] = substr($presenter, strlen($this->module));
} else {
return NULL;
}
// remove default values; NULL values are retain
foreach ($this->defaults as $key => $value) {
if (isset($params[$key]) && $params[$key] == $value) {
// intentionally ==
unset($params[$key]);
}
}
$url = ($this->flags & self::SECURED ? 'https://' : 'http://') . $refUrl->getAuthority() . $refUrl->getPath();
$sep = ini_get('arg_separator.input');
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
if ($query != '') {
// intentionally ==
$url .= '?' . $query;
}
return $url;
}
作者:hrac
项目:nette-applicatio
/**
* Constructs absolute URL from Request object.
* @return string|NULL
*/
public function constructUrl(Nette\Application\Request $appRequest, Nette\Http\Url $refUrl)
{
if ($this->cachedRoutes === NULL) {
$this->warmupCache();
}
if ($this->module) {
if (strncmp($tmp = $appRequest->getPresenterName(), $this->module, strlen($this->module)) === 0) {
$appRequest = clone $appRequest;
$appRequest->setPresenterName(substr($tmp, strlen($this->module)));
} else {
return NULL;
}
}
$presenter = $appRequest->getPresenterName();
if (!isset($this->cachedRoutes[$presenter])) {
$presenter = '*';
}
foreach ($this->cachedRoutes[$presenter] as $route) {
$url = $route->constructUrl($appRequest, $refUrl);
if ($url !== NULL) {
return $url;
}
}
return NULL;
}
作者:ark
项目:securit
/**
* @param \Ark8\Security\Authorizators\Request $request
* @return array
* @throws \Nette\InvalidStateException
*/
private function getSignal(Request $request)
{
$params = $request->getParameters();
if ($this->httpRequest->isAjax()) {
$params += $request->getPost();
} elseif (($tmp = $request->getPost(Presenter::SIGNAL_KEY)) !== NULL) {
$params[self::SIGNAL_KEY] = $tmp;
}
$signal = NULL;
$signalReceiver = '';
if (isset($params[Presenter::SIGNAL_KEY])) {
$param = $params[Presenter::SIGNAL_KEY];
$pos = strrpos($param, '-');
if ($pos) {
$signalReceiver = substr($param, 0, $pos);
$signal = substr($param, $pos + 1);
} else {
$signalReceiver = $this->getUniqueId();
$signal = $param;
}
if ($signal == NULL) {
// intentionally ==
$signal = NULL;
}
}
return [$signal, explode('-', $signalReceiver)];
}
作者:minetr
项目:micro-website-modul
/**
* @param Application\Request $appRequest
* @param Nette\Http\Url $refUrl
* @return NULL|string
*/
public function constructUrl(Application\Request $appRequest, Nette\Http\Url $refUrl)
{
$parameters = $appRequest->getParameters();
if (isset($parameters['action']) && $parameters['action'] == FALSE) {
$parameters['action'] = NULL;
}
$appRequest->setParameters($parameters);
return parent::constructUrl($appRequest, $refUrl);
}
作者:librett
项目:doctrine-migration
public function handleApplicationRequest(Application\Application $application, Application\Request $request)
{
if ($request->getPresenterName() === 'Kdyby:Cli') {
$parameters = $request->getParameters();
if (isset($parameters['output']) && ($output = $parameters['output']) instanceof OutputInterface) {
$this->outputWriter->setOutputInterface($output);
}
}
}
作者:fuchc
项目:generator-myprojec
public function run(Nette\Application\Request $request)
{
$exception = $request->getParameter('exception');
if ($exception instanceof Nette\Application\BadRequestException) {
return new Responses\ForwardResponse($request->setPresenterName('Error4xx'));
}
$this->logger->log($exception, ILogger::EXCEPTION);
return new Responses\CallbackResponse(function () {
require __DIR__ . '/templates/Error/500.phtml';
});
}
作者:ublabo
项目:api-doc
/**
* Event thatis firex when particular ApiRoute is matched
* @param ApiRoute $route
* @param Request $request
* @return void
*/
public function routeMatched(ApiRoute $route, Request $request)
{
if (NULL !== ($format = $request->getParameter(self::API_DOCU_STARTER_QUERY_KEY_GENERATE))) {
$this->generator->generateAll($this->router);
exit(0);
}
if (NULL !== ($format = $request->getParameter(self::API_DOCU_STARTER_QUERY_KEY_TARGET))) {
$this->generator->generateTarget($route, $request);
exit(0);
}
}
作者:venn
项目:venn
/**
* @param \Nette\Application\Request $appRequest
* @param \Nette\Http\Url $refUrl
* @return string|null
*/
public function constructUrl(Request $appRequest, Url $refUrl)
{
$presenter = $appRequest->getPresenterName();
if (!Strings::startsWith($presenter, self::SUBMODULE_NAME . ':')) {
return null;
}
if (Strings::endsWith($presenter, ':' . self::DEFAULT_PRESENTER)) {
$presenter = substr($presenter, 0, -strlen(':' . self::DEFAULT_PRESENTER));
}
$appRequest->setPresenterName(substr($presenter, strlen(self::SUBMODULE_NAME . ':')));
return parent::constructUrl($appRequest, $refUrl);
}
作者:tripomati
项目:nette-ap
/**
* @param Request $request
* @return IResponse
* @throws BadRequestException
*/
public function run(Request $request)
{
$method = strtolower($request->getMethod());
if (!method_exists($this, $method)) {
throw new BadRequestException("Method '{$request->getMethod()}' not supported.");
}
$response = $this->{$method}($request);
if (!$response instanceof IResponse) {
throw new InvalidStateException("Presenter '{$request->getPresenterName()}' did not return any response for method '{$request->getMethod()}'.");
}
return $response;
}
作者:TomasVotrub
项目:lekarna-se-skol
/**
* @return Nette\Application\IResponse
*/
public function run(Nette\Application\Request $request)
{
$e = $request->getParameter('exception');
if ($e instanceof Nette\Application\BadRequestException) {
// $this->logger->log("HTTP code {$e->getCode()}: {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", 'access');
return new Nette\Application\Responses\ForwardResponse($request->setPresenterName('Error4xx'));
}
$this->logger->log($e, ILogger::EXCEPTION);
return new Nette\Application\Responses\CallbackResponse(function () {
require __DIR__ . '/templates/Error/500.phtml';
});
}
作者:lohin
项目:webloade
/**
* Constructs absolute URL from Request object
*
* @param \Nette\Application\Request $appRequest
* @param \Nette\Http\Url $refUrl
* @return string|NULL
*/
public function constructUrl(Application\Request $appRequest, \Nette\Http\Url $refUrl)
{
if ($appRequest->getPresenterName() != $this->getTargetPresenter()) {
return NULL;
}
$params = $appRequest->getParameters();
if (!isset($params['id']) && isset($params[0])) {
$params['id'] = $params[0];
unset($params[0]);
$appRequest->setParameters($params);
}
return parent::constructUrl($appRequest, $refUrl);
}
作者:martinmaye
项目:noteja
/**
* This method is usually implemented by the more complex UI\Presenter
* But since an unhandled exception might have occurred,
* it should be processed as simply as possible to avoid any further problems or even another exception.
*
* @param Nette\Application\Request $request
* @return Responses\CallbackResponse|Responses\ForwardResponse
*/
public function run(Nette\Application\Request $request)
{
$exception = $request->getParameter('exception');
// if it's a simple BadRequestException, use the more powerful presenter
if ($exception instanceof Nette\Application\BadRequestException) {
return new Responses\ForwardResponse($request->setPresenterName('Error4xx'));
}
$this->logger->log($exception, ILogger::EXCEPTION);
// the 500 means unhandled exception, which should translate to the simplest page possible
return new Responses\CallbackResponse(function () {
require __DIR__ . '/templates/Error/500.phtml';
});
}
作者:enuma
项目:newrelic-nette-
public function onRequest(Application $app, Request $request)
{
if (!extension_loaded('newrelic')) {
return;
}
if (PHP_SAPI === 'cli') {
newrelic_name_transaction('$ ' . basename($_SERVER['argv'][0]) . ' ' . implode(' ', array_slice($_SERVER['argv'], 1)));
newrelic_background_job(TRUE);
return;
}
$params = $request->getParameters();
newrelic_name_transaction($request->getPresenterName() . (isset($params['action']) ? ':' . $params['action'] : ''));
}
作者:consumer
项目:nett
/**
* @param Nette\Application\Application $app
* @param Nette\Application\Request $request
*/
public function onRequest(Nette\Application\Application $app, Nette\Application\Request $request)
{
if (Consumerr::isConsole()) {
Consumerr::setBackgroundJob(TRUE);
Consumerr::setName('$ ' . basename($_SERVER['argv'][0]) . ' ' . implode(' ', array_slice($_SERVER['argv'], 1)));
} else {
$params = $request->getParameters();
if ($request->method === 'FORWARD' && $request->getPresenterName() === $app->errorPresenter) {
return;
//do not replace presenter name with error presenter
}
Consumerr::setName($request->getPresenterName() . (isset($params['action']) ? ':' . $params['action'] : ''));
}
}
作者:hrac
项目:nette-applicatio
/**
* @return Application\IResponse
*/
public function run(Application\Request $request)
{
$e = $request->getParameter('exception');
if ($e instanceof Application\BadRequestException) {
$code = $e->getCode();
} else {
$code = 500;
if ($this->logger) {
$this->logger->log($e, ILogger::EXCEPTION);
}
}
return new Application\Responses\CallbackResponse(function () use($code) {
require __DIR__ . '/templates/error.phtml';
});
}
作者:svobodn
项目:we
/**
* Template factory.
* @param string
* @param callable
* @return Nette\Templating\ITemplate
*/
public function createTemplate($class = NULL, $latteFactory = NULL)
{
$template = $class ? new $class() : new Nette\Templating\FileTemplate();
$template->setParameters($this->request->getParameters());
$template->presenter = $this;
$template->context = $context = $this->context;
$url = $context->getByType('Nette\\Http\\IRequest')->getUrl();
$template->baseUrl = rtrim($url->getBaseUrl(), '/');
$template->basePath = rtrim($url->getBasePath(), '/');
$template->registerHelperLoader('Nette\\Templating\\Helpers::loader');
$template->setCacheStorage($context->getService('nette.templateCacheStorage'));
$template->onPrepareFilters[] = function ($template) use($latteFactory) {
$template->registerFilter($latteFactory ? $latteFactory() : new Nette\Latte\Engine());
};
return $template;
}
作者:venca-
项目:nette-newreli
public function onRequest(Application $app, Request $request)
{
if (!extension_loaded('newrelic')) {
return;
}
if (PHP_SAPI === 'cli') {
// uložit v čitelném formátu
newrelic_name_transaction('$ ' . basename($_SERVER['argv'][0]) . ' ' . implode(' ', array_slice($_SERVER['argv'], 1)));
// označit jako proces na pozadí
newrelic_background_job(TRUE);
return;
}
// pojmenování požadavku podle presenteru a akce
$params = $request->getParameters();
newrelic_name_transaction($_SERVER['HTTP_HOST'] . " | " . $request->getPresenterName() . (isset($params['action']) ? ':' . $params['action'] : ''));
}
作者:prcharo
项目:w-pps-realit
/**
* @return Nette\Application\IResponse
*/
public function run(Application\Request $request)
{
$this->request = $request;
if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $this->httpRequest->getUrl();
$url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
if ($url !== NULL && !$this->httpRequest->getUrl()->isEqual($url)) {
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
}
$params = $request->getParameters();
if (!isset($params['callback'])) {
throw new Application\BadRequestException('Parameter callback is missing.');
}
$params['presenter'] = $this;
$callback = $params['callback'];
$reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback));
$params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params);
foreach ($reflection->getParameters() as $param) {
if ($param->getClassName()) {
unset($params[$param->getPosition()]);
}
}
if ($this->context) {
$params = Nette\DI\Helpers::autowireArguments($reflection, $params, $this->context);
}
$response = call_user_func_array($callback, $params);
if (is_string($response)) {
$response = array($response, array());
}
if (is_array($response)) {
$response = $this->createTemplate()->setParameters($response[1]);
if ($response[0] instanceof \SplFileInfo) {
$response->setFile($response[0]);
} else {
$response->setSource($response[0]);
// TODO
}
}
if ($response instanceof Application\UI\ITemplate) {
return new Responses\TextResponse($response);
} else {
return $response;
}
}