本文整理汇总了PHP中Symfony\Component\HttpFoundation\RequestStack::getCurrentRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestStack::getCurrentRequest方法的具体用法?PHP RequestStack::getCurrentRequest怎么用?PHP RequestStack::getCurrentRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\RequestStack
的用法示例。
在下文中一共展示了RequestStack::getCurrentRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* @return array The Render Array
*/
public function search()
{
$formSubmitted = $this->currentRequest->getCurrentRequest()->get('search-button');
$queryString = $this->currentRequest->getCurrentRequest()->get('search-value');
$currentPage = $this->currentRequest->getCurrentRequest()->get('search-page');
if (!isset($currentPage) || empty($currentPage)) {
$currentPage = 1;
}
if (!isset($formSubmitted) || empty($formSubmitted) || $formSubmitted != SearchResultsController::FORM_SUBMITTED_VALUE || !isset($queryString) || empty($queryString)) {
return ['#type' => 'markup', '#markup' => $this->t("No Search was performed")];
}
$config = $this->config('google_site_search.settings');
$key = $config->get('google_site_search_key');
$index = $config->get('google_site_search_index');
if (empty($key) || !isset($key) || empty($index) || !isset($index)) {
return ['#type' => 'markup', '#markup' => $this->t("The google site search is not configured correctly")];
}
/* @var $gssService \Drupal\google_site_search\GoogleSiteSearchSearch */
$gssService = \Drupal::service('google_site_search.search');
$currentLanguage = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
$results = $gssService->getSearchResults($currentLanguage, $queryString, $key, $index, $currentPage);
// check for errors or no results
if ($results instanceof TranslatableMarkup || !isset($results['items']) || count($results['items']) === 0) {
return ['#theme' => 'google_no_search_results', '#title' => t('No Search Results'), '#content' => ['query' => $queryString]];
}
return ['#theme' => 'google_search_results', '#title' => t('Search Results'), '#content' => ['items' => $results['items'], 'total' => $results['queries']['request'][0]['totalResults'], 'count' => $results['queries']['request'][0]['count'], 'start' => ($currentPage - 1) * 10 + 1, 'nextPage' => isset($results['queries']['nextPage']) ? $currentPage + 1 : 0, 'prevPage' => isset($results['queries']['prevPage']) ? $currentPage - 1 : 0, 'query' => $queryString], '#cache' => ['contexts' => $this->getCacheContexts()]];
}
示例2: getConfiguration
/**
* @param $instance
* @return array
*/
public function getConfiguration($instance)
{
$request = $this->requestStack->getCurrentRequest();
$efParameters = $this->parameters;
$parameters = $efParameters['instances'][$instance];
$options = array();
$options['corsSupport'] = $parameters['cors_support'];
$options['debug'] = $parameters['connector']['debug'];
$options['bind'] = $parameters['connector']['binds'];
$options['plugins'] = $parameters['connector']['plugins'];
$options['roots'] = array();
foreach ($parameters['connector']['roots'] as $parameter) {
$path = $parameter['path'];
$homeFolder = $this->container->get('security.token_storage')->getToken()->getUser()->getUsername();
// var_dump($path.$homeFolder);
$driver = $this->container->has($parameter['driver']) ? $this->container->get($parameter['driver']) : null;
$driverOptions = array('driver' => $parameter['driver'], 'service' => $driver, 'glideURL' => $parameter['glide_url'], 'glideKey' => $parameter['glide_key'], 'plugin' => $parameter['plugins'], 'path' => $path . '/' . $homeFolder, 'startPath' => $parameter['start_path'], 'URL' => $this->getURL($parameter, $request, $homeFolder, $path), 'alias' => $parameter['alias'], 'mimeDetect' => $parameter['mime_detect'], 'mimefile' => $parameter['mimefile'], 'imgLib' => $parameter['img_lib'], 'tmbPath' => $parameter['tmb_path'], 'tmbPathMode' => $parameter['tmb_path_mode'], 'tmbUrl' => $parameter['tmb_url'], 'tmbSize' => $parameter['tmb_size'], 'tmbCrop' => $parameter['tmb_crop'], 'tmbBgColor' => $parameter['tmb_bg_color'], 'copyOverwrite' => $parameter['copy_overwrite'], 'copyJoin' => $parameter['copy_join'], 'copyFrom' => $parameter['copy_from'], 'copyTo' => $parameter['copy_to'], 'uploadOverwrite' => $parameter['upload_overwrite'], 'uploadAllow' => $parameter['upload_allow'], 'uploadDeny' => $parameter['upload_deny'], 'uploadMaxSize' => $parameter['upload_max_size'], 'defaults' => $parameter['defaults'], 'attributes' => $parameter['attributes'], 'acceptedName' => $parameter['accepted_name'], 'disabled' => $parameter['disabled_commands'], 'treeDeep' => $parameter['tree_deep'], 'checkSubfolders' => $parameter['check_subfolders'], 'separator' => $parameter['separator'], 'timeFormat' => $parameter['time_format'], 'archiveMimes' => $parameter['archive_mimes'], 'archivers' => $parameter['archivers']);
if (!$parameter['show_hidden']) {
$driverOptions['accessControl'] = array($this, 'access');
}
if ($parameter['driver'] == 'Flysystem') {
$driverOptions['filesystem'] = $filesystem;
}
$options['roots'][] = array_merge($driverOptions, $this->configureDriver($parameter));
}
return $options;
}
示例3: handleRequestStack
/**
* Handle the request stack
*/
protected function handleRequestStack()
{
$currentRequest = $this->requestStack->getCurrentRequest();
if ($currentRequest) {
$this->add('request.locale', $currentRequest->getLocale());
}
}
示例4: process
/**
* @param BreadcrumbItem $item
* @param array $variables
* @return ProcessedBreadcrumbItem
*/
public function process(BreadcrumbItem $item, $variables)
{
// Process the label
if ($item->getLabel()[0] === '$') {
$processedLabel = $this->parseValue($item->getLabel(), $variables);
} else {
$processedLabel = $this->translator->trans($item->getLabel());
}
// Process the route
// TODO: cache parameters extracted from current request
$params = [];
foreach ($this->requestStack->getCurrentRequest()->attributes as $key => $value) {
if ($key[0] !== '_') {
$params[$key] = $value;
}
}
foreach ($item->getRouteParams() ?: [] as $key => $value) {
if ($value[0] === '$') {
$params[$key] = $this->parseValue($value, $variables);
} else {
$params[$key] = $value;
}
}
if ($item->getRoute() !== null) {
$processedUrl = $this->router->generate($item->getRoute(), $params);
} else {
$processedUrl = null;
}
return new ProcessedBreadcrumbItem($processedLabel, $processedUrl);
}
示例5: getUriForPage
/**
* @param $page
*
* @return string
*/
protected function getUriForPage($page)
{
$request = $this->requestStack->getCurrentRequest();
$request->query->set('page', $page);
$query = urldecode(http_build_query($request->query->all()));
return $request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . '?' . $query;
}
示例6: prepareRequest
protected function prepareRequest(array $params)
{
// Get action
$action = $this->popParameter($params, "action");
// Then get and filter query, request and method
$query = $this->popParameter($params, "query");
$query = $this->filterArrayStrParam($query);
$request = $this->popParameter($params, "request");
$request = $this->filterArrayStrParam($request);
$method = strtoupper($this->popParameter($params, "method", "GET"));
// Then build the request
$requestObject = clone $this->requestStack->getCurrentRequest();
$requestObject->query = new ParameterBag($query);
$requestObject->request = new ParameterBag($request);
$requestObject->attributes = new ParameterBag(["_controller" => $action]);
// Apply the method
if (!empty($request) && "GET" === $method) {
$requestObject->setMethod("POST");
} else {
$requestObject->setMethod($method);
}
// Then all the attribute parameters
foreach ($params as $key => $attribute) {
$requestObject->attributes->set($key, $attribute);
}
return $requestObject;
}
示例7: createForm
/**
* @param string $name
* @param string $type
* @param array $data
* @param array $options
* @return \Thelia\Form\BaseForm
*/
public function createForm($name, $type = "form", array $data = array(), array $options = array())
{
if (!isset($this->formDefinition[$name])) {
throw new \OutOfBoundsException(sprintf("The form '%s' doesn't exist", $name));
}
return new $this->formDefinition[$name]($this->requestStack->getCurrentRequest(), $type, $data, $options, $this->container);
}
示例8: createDocument
/**
* {@inheritdoc}
*/
public function createDocument(array $options = [])
{
$document = new PdfDocument();
$params = $this->params;
$request = $this->requestStack->getCurrentRequest();
$document->setOptions($this->getWkHtmlToPdfOptions($request->getUri(), $params['pdf_wkhtmltopdf_bin']));
$document->outputSelector(function () use($request) {
return $request->query->get('do');
});
$head = $document->element('head');
$bootstrap = new HtmlElement('link');
$bootstrap->attr('rel', 'stylesheet');
$bootstrap->attr('type', 'text/css');
$bootstrap->attr('href', $request->getSchemeAndHttpHost() . $this->appPaths->url("web") . '/pdf/css/bootstrap.min.css');
$bootstrap->insertTo($head);
$style = new HtmlElement('link');
$style->attr('rel', 'stylesheet');
$style->attr('type', 'text/css');
$style->attr('href', $request->getSchemeAndHttpHost() . $this->appPaths->url("web") . '/pdf/css/pdf.css');
$style->insertTo($head);
$filename = $this->appPaths->getRootDir() . '/../pdf/' . $request->getPathInfo();
$dir = dirname($filename);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$document->setFilename($filename);
return $document;
}
示例9: configureOptions
public function configureOptions(OptionsResolver $resolver)
{
$locale = $this->requestStack->getCurrentRequest()->getLocale();
$resolver->setDefaults(array('class' => 'ChillActivityBundle:ActivityReasonCategory', 'property' => 'name[' . $locale . ']', 'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c')->where('c.active = true');
}));
}
示例10: log
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = array())
{
if ($this->callDepth == self::MAX_CALL_DEPTH) {
return;
}
$this->callDepth++;
// Merge in defaults.
$context += array('channel' => $this->channel, 'link' => '', 'user' => NULL, 'uid' => 0, 'request_uri' => '', 'referer' => '', 'ip' => '', 'timestamp' => time());
// Some context values are only available when in a request context.
if ($this->requestStack && ($request = $this->requestStack->getCurrentRequest())) {
$context['request_uri'] = $request->getUri();
$context['referer'] = $request->headers->get('Referer', '');
$context['ip'] = $request->getClientIP();
try {
if ($this->currentUser) {
$context['user'] = $this->currentUser;
$context['uid'] = $this->currentUser->id();
}
} catch (\Exception $e) {
// An exception might be thrown if the database connection is not
// available or due to another unexpected reason. It is more important
// to log the error that we already have so any additional exceptions
// are ignored.
}
}
if (is_string($level)) {
// Convert to integer equivalent for consistency with RFC 5424.
$level = $this->levelTranslation[$level];
}
// Call all available loggers.
foreach ($this->sortLoggers() as $logger) {
$logger->log($level, $message, $context);
}
$this->callDepth--;
}
示例11: getUrl
/**
* Returns the canonical url for the current request,
* or null if called outside of the request cycle.
*
* @return string|null
*/
public function getUrl()
{
if (($request = $this->requestStack->getCurrentRequest()) === null) {
return null;
}
return $this->urlGenerator->generate($request->attributes->get('_route'), $request->attributes->get('_route_params'), UrlGeneratorInterface::ABSOLUTE_URL);
}
示例12: theliaModule
/**
* Process theliaModule template inclusion function
*
* This function accepts two parameters:
*
* - location : this is the location in the admin template. Example: folder-edit'. The function will search for
* AdminIncludes/<location>.html file, and fetch it as a Smarty template.
* - countvar : this is the name of a template variable where the number of found modules includes will be assigned.
*
* @param array $params
* @param \Smarty_Internal_Template $template
* @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty
*
* @return string
*/
public function theliaModule($params, \Smarty_Internal_Template $template)
{
$content = null;
$count = 0;
if (false !== ($location = $this->getParam($params, 'location', false))) {
if ($this->debug === true && $this->requestStack->getCurrentRequest()->get('SHOW_INCLUDE')) {
echo sprintf('<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">%s</div>', $location);
}
$moduleLimit = $this->getParam($params, 'module', null);
$modules = ModuleQuery::getActivated();
/** @var \Thelia\Model\Module $module */
foreach ($modules as $module) {
if (null !== $moduleLimit && $moduleLimit != $module->getCode()) {
continue;
}
$file = $module->getAbsoluteAdminIncludesPath() . DS . $location . '.html';
if (file_exists($file)) {
$output = trim(file_get_contents($file));
if (!empty($output)) {
$content .= $output;
$count++;
}
}
}
}
if (false !== ($countvarname = $this->getParam($params, 'countvar', false))) {
$template->assign($countvarname, $count);
}
if (!empty($content)) {
return $template->fetch(sprintf("string:%s", $content));
}
return "";
}
示例13: __construct
/**
* __construct
* @param RequestStack $requestStack
* @return void
**/
public function __construct(RequestStack $requestStack)
{
$scheme = $requestStack->getCurrentRequest()->getScheme();
$host = $requestStack->getCurrentRequest()->getHost();
$port = $requestStack->getCurrentRequest()->getPort();
$this->u2f = new \u2flib_server\U2F($scheme . '://' . $host . (80 !== $port && 443 !== $port ? ':' . $port : ''));
}
示例14: localeDate
/**
* Returns formatted and translated date.
*
* @param string $route The route of the current link
* @param string $classes Classes of the current element
*
* @return string The attribute of the element
*/
public function localeDate($date, $formatType = null, $timezone = null)
{
$request = $this->requestStack->getCurrentRequest();
$locale = $request->get('_locale');
$localeFormats = $this->localesConfig[$locale];
if (null === $formatType || !isset($localeFormats[$formatType])) {
$result = twig_date_format_filter($this->twig, $date, null, $timezone);
} else {
$format = $localeFormats[$formatType];
if (!preg_match('/[DlMF]/', $format)) {
$result = twig_date_format_filter($this->twig, $date, $format, $timezone);
} else {
$pattern = '/[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/';
$length = mb_strlen($format, 'UTF-8');
$result = '';
for ($i = 0; $i < $length; $i++) {
$symbol = mb_substr($format, $i, 1, 'UTF-8');
if (preg_match($pattern, $symbol)) {
$value = twig_date_format_filter($this->twig, $date, $symbol, $timezone);
if (preg_match('/[DlMF]/', $symbol)) {
$value = $this->translator->trans($value);
}
} else {
$value = $symbol;
}
$result .= $value;
}
}
}
return $result;
}
示例15: validateForm
/**
* {@inheritdoc}
*/
public function validateForm($form_id, &$form, FormStateInterface &$form_state)
{
// If this form is flagged to always validate, ensure that previous runs of
// validation are ignored.
if (!empty($form_state['must_validate'])) {
$form_state['validation_complete'] = FALSE;
}
// If this form has completed validation, do not validate again.
if (!empty($form_state['validation_complete'])) {
return;
}
// If the session token was set by self::prepareForm(), ensure that it
// matches the current user's session.
if (isset($form['#token'])) {
if (!$this->csrfToken->validate($form_state['values']['form_token'], $form['#token'])) {
$url = $this->requestStack->getCurrentRequest()->getRequestUri();
// Setting this error will cause the form to fail validation.
$form_state->setErrorByName('form_token', $this->t('The form has become outdated. Copy any unsaved work in the form below and then <a href="@link">reload this page</a>.', array('@link' => $url)));
// Stop here and don't run any further validation handlers, because they
// could invoke non-safe operations which opens the door for CSRF
// vulnerabilities.
$this->finalizeValidation($form, $form_state, $form_id);
return;
}
}
// Recursively validate each form element.
$this->doValidateForm($form, $form_state, $form_id);
$this->finalizeValidation($form, $form_state, $form_id);
$this->handleErrorsWithLimitedValidation($form, $form_state, $form_id);
}