本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getBasePath方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getBasePath方法的具体用法?PHP Request::getBasePath怎么用?PHP Request::getBasePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getBasePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: thumbAction
public function thumbAction(Request $request, Application $app)
{
$source = $request->get('src', false);
$width = $request->get('width', 250);
// Do requested thumbnail in correct format already exists ?
if ($app['flysystems']['thumbs']->has($width . "/" . $source)) {
return $app->redirect($request->getBasePath() . '/thumbs/' . $width . '/' . $source, 301);
}
// Do requested file exists ?
if (!$source || !$app['flysystems']['local']->has($source)) {
return new Response("Source file not found.", 404);
}
try {
$contents = $app['flysystems']['local']->read($source);
$imageManager = new ImageManager();
$image = $imageManager->make($contents);
$image->resize($width, null, function ($constraint) {
$constraint->aspectRatio();
});
$info = $app['flysystems']['local']->getWithMetadata($source, ['mimetype']);
$image->encode($info['mimetype']);
$app['flysystems']['thumbs']->put($width . "/" . $source, $image);
return $app->redirect($request->getBasePath() . '/thumbs/' . $width . '/' . $source, 301);
} catch (\Exception $e) {
return new Response("Erreur !", 500);
}
// Should not happen, everything failed. Display not found image :(
return $app->redirect($request->getBasePath() . '/assets/img/' . $width . '_not-found.png', 302);
}
示例2: handle
/**
* Handles an access denied failure redirecting to home page
*
* @param Request $request
* @param AccessDeniedException $accessDeniedException
*
* @return Response may return null
*/
public function handle(Request $request, AccessDeniedException $accessDeniedException)
{
$this->logger->error('User tried to access: ' . $request->getUri());
if ($request->isXmlHttpRequest()) {
return new JsonResponse(['message' => $accessDeniedException->getMessage(), 'trace' => $accessDeniedException->getTraceAsString(), 'exception' => get_class($accessDeniedException)], Response::HTTP_SERVICE_UNAVAILABLE);
} else {
$url = $request->getBasePath() !== "" ? $request->getBasePath() : "/";
$response = new RedirectResponse($url);
$response->setStatusCode(Response::HTTP_FORBIDDEN);
$response->prepare($request);
return $response->send();
}
}
示例3: onNavigationConfigure
/**
* @param ConfigureMenuEvent $event
*/
public function onNavigationConfigure(ConfigureMenuEvent $event)
{
if (!$this->entryPoint || !$this->securityContext->getToken() || !$this->securityContext->isGranted('ROLE_ADMINISTRATOR')) {
return;
}
$uri = '/' . $this->entryPoint;
if ($this->request) {
$uri = $this->request->getBasePath() . $uri;
}
/** @var ItemInterface $systemTabMenuItem */
$systemTabMenuItem = $event->getMenu()->getChild('system_tab');
if ($systemTabMenuItem) {
$systemTabMenuItem->addChild('package_manager', ['label' => 'oro.distribution.package_manager.label', 'uri' => $uri, 'linkAttributes' => ['class' => 'no-hash'], 'extras' => ['position' => '110']]);
}
}
示例4: sendFileAction
public function sendFileAction(Request $request, Application $app)
{
$file = $request->query->get('file', '');
$locale = $request->getLocale();
$base_path = $request->getBasePath();
$base_path = $base_path . 'download/' . $locale;
$file_path = $base_path . '/' . $file;
$finder = new Finder();
$finder->files()->in($base_path)->name('*' . $file . '*');
$file = null;
foreach ($finder as $archivo) {
/** @var SplFileInfo $file */
$file = $archivo;
break;
}
if (null === $file) {
return $app->redirect('/');
}
$log = $app['monolog'];
$nombre = $file->getBasename('.' . $file->getExtension());
$nombre = $app['translator']->trans(sprintf("%s.%s", 'archivo', $nombre));
$nombre = $nombre . '.' . $file->getExtension();
$log->addInfo($nombre);
$log->addInfo(sprintf('Se ha solicitado el archivo: %s', $file_path));
return $app->sendFile($file)->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $nombre);
}
示例5: lostPasswordAction
/**
* @Route("/lostPassword", name="lost_password_route")
*/
public function lostPasswordAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$reset = false;
if ($request->request->get('reset') == "true") {
$reset = true;
}
if ($reset) {
$user = $em->getRepository('BackendBundle:User')->findOneByEmail($request->request->get('email'));
if (!is_null($user)) {
$rb = uniqid(rand(), true);
$random = md5($user->getEmail() . $rb);
//guardar en la base de datos
$restorer = $em->getRepository('BackendBundle:Restorer')->findOneByUser($user);
if (is_null($restorer)) {
$restorer = new Restorer();
}
$restorer->setUser($user);
$restorer->setTime(new \DateTime());
$restorer->setAuth(md5($random));
$em->persist($restorer);
$em->flush();
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$url = $baseurl . '/resetPassword?token=' . $random;
$message = \Swift_Message::newInstance()->setSubject('Recuperación de contraseña')->setFrom('gestionIPre@ing.puc.cl')->setTo(array($user->getEmail()))->setBody('<html>' . ' <head></head>' . ' <body>' . ' Hola, usa este link para recuperar tu contraseña: ' . '<a href="' . $url . '">' . $url . '</a></br>' . ' Si no pediste recuperar contraseña omite este email. (No responda este email)</body>' . '</html>', 'text/html');
$this->get('mailer')->send($message);
}
}
return $this->render('security/lostPassword.html.twig', array('reset' => $reset));
}
示例6: getPath
/**
* Returns the base path.
*
* @return string|null The base path
*/
private function getPath()
{
if (null === $this->request) {
return null;
}
return $this->request->getBasePath();
}
示例7: logoutAction
public function logoutAction(Request $request)
{
if ($this->getAuth()->hasAuthenticatedUser()) {
$this->getAuth()->deauthenticate();
}
return new RedirectResponse($request->getBasePath() . '/account/login');
}
示例8: startJsApplication
/**
* Generates JavaScript code that starts client side application.
*
* @param Request $request Incoming request.
* @param array $operator Current operator.
* @return string JavaScript code that starts "users" client side
* application.
*/
protected function startJsApplication(Request $request, $operator)
{
// Load dialogs style options
$chat_style = new ChatStyle(ChatStyle::getCurrentStyle());
$chat_style_config = $style_config = $chat_style->getConfigurations();
// Load page style options
$page_style_config = $style_config = $this->getStyle()->getConfigurations();
return sprintf('jQuery(document).ready(function() {Mibew.Application.start(%s);});', json_encode(array('server' => array('url' => $this->generateUrl('users_update'), 'requestsFrequency' => Settings::get('updatefrequency_operator')), 'agent' => array('id' => $operator['operatorid']), 'page' => array('mibewBasePath' => $request->getBasePath(), 'mibewBaseUrl' => $request->getBaseUrl(), 'showOnlineOperators' => Settings::get('showonlineoperators') == '1', 'showVisitors' => Settings::get('enabletracking') == '1', 'showPopup' => Settings::get('enablepopupnotification') == '1', 'threadTag' => $page_style_config['users']['thread_tag'], 'visitorTag' => $page_style_config['users']['visitor_tag'], 'agentLink' => $request->getBaseUrl() . '/operator/chat', 'geoLink' => Settings::get('geolink'), 'trackedLink' => $request->getBaseUrl() . '/operator/history/user-track', 'banLink' => $request->getBaseUrl() . '/operator/ban', 'inviteLink' => $request->getBaseUrl() . '/operator/invite', 'chatWindowParams' => $chat_style_config['chat']['window'], 'geoWindowParams' => Settings::get('geolinkparams'), 'trackedUserWindowParams' => $page_style_config['tracked']['user_window'], 'trackedVisitorWindowParams' => $page_style_config['tracked']['visitor_window'], 'banWindowParams' => $page_style_config['ban']['window'], 'inviteWindowParams' => $chat_style_config['chat']['window']))));
}
示例9: filter
/**
* This action applies a given filter to a given image, saves the image and
* outputs it to the browser at the same time
*
* @param string $path
* @param string $filter
*
* @return Response
*/
public function filter($path, $filter)
{
$path = '/' . ltrim($path, '/');
//TODO: find out why I need double urldecode to get a valid path
$browserPath = urldecode(urldecode($this->cachePathResolver->getBrowserPath($path, $filter)));
$basePath = $this->request->getBaseUrl();
if (!empty($basePath) && 0 === strpos($browserPath, $basePath)) {
$browserPath = substr($browserPath, strlen($basePath));
}
// if cache path cannot be determined, return 404
if (null === $browserPath) {
throw new NotFoundHttpException('Image doesn\'t exist');
}
$realPath = $this->webRoot . $browserPath;
$sourcePath = $this->sourceRoot . $path;
// if the file has already been cached, we're probably not rewriting
// correctly, hence make a 301 to proper location, so browser remembers
if (file_exists($realPath)) {
return new Response('', 301, array('location' => $this->request->getBasePath() . $browserPath));
}
if (!file_exists($sourcePath)) {
throw new NotFoundHttpException(sprintf('Source image not found in "%s"', $sourcePath));
}
$dir = pathinfo($realPath, PATHINFO_DIRNAME);
if (!is_dir($dir)) {
if (false === $this->filesystem->mkdir($dir)) {
throw new \RuntimeException(sprintf('Could not create directory %s', $dir));
}
}
ob_start();
try {
$format = $this->filterManager->getOption($filter, "format", "png");
// TODO: get rid of hard-coded quality and format
$this->filterManager->get($filter)->apply($this->imagine->open($sourcePath))->save($realPath, array('quality' => $this->filterManager->getOption($filter, "quality", 100), 'format' => $this->filterManager->getOption($filter, "format", null)))->show($format);
$type = 'image/' . $format;
$length = ob_get_length();
$content = ob_get_clean();
// TODO: add more media headers
return new Response($content, 201, array('content-type' => $type, 'content-length' => $length));
} catch (\Exception $e) {
ob_end_clean();
throw $e;
}
}
示例10: render
/**
* (non-PHPdoc)
*
* @see RenderInterface::render()
*/
public function render(Request $request, Response $response, ResponseContent $content)
{
$path = (string) Configuration::getInstance()->templates->path;
$template = $request->getBasePath();
if (!$template) {
$template = "index";
}
$response->setContent($this->getIncludeContents("{$path}/{$template}.phtml", $content));
return $response;
}
示例11: indexAction
/**
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function indexAction(Request $request)
{
if (null === $this->slider_id) {
return new Response();
}
/** @var \Doctrine\ORM\EntityManager $em */
$em = $this->get('doctrine.orm.entity_manager');
$slider = $em->find('SliderModule:Slider', $this->slider_id);
$this->node->addFrontControl('manage_slider')->setTitle('Управление слайдами')->setUri($this->generateUrl('smart_module.slider.admin_slider', ['id' => $this->slider_id]));
return $this->get('twig')->render('SliderModule::' . $slider->getLibrary() . '.html.twig', ['slider' => $slider, 'imgPath' => $request->getBasePath() . '/' . $this->get('smart_module.slider')->getWebPath()]);
}
示例12: checkDomainsValidity
public function checkDomainsValidity(Request $request)
{
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
//var_dump($baseurl);
switch (true) {
case $baseurl == 'http://agente3w.com':
return 'core_dashboard';
break;
}
return NULL;
}
示例13: setRequest
/**
* Sets all needed values from the request.
*
* @param Request $request A request to get values from.
*/
public function setRequest(Request $request)
{
$this->setScheme($request->getScheme());
$this->setHost($request->getHost());
$this->setBasePath($request->getBasePath());
if ($request->isSecure()) {
$this->setHttpsPort($request->getPort());
} else {
$this->setHttpPort($request->getPort());
}
}
示例14: appendRealmToName
protected function appendRealmToName(Request $request)
{
if (!$this->options->getBoolean('restrict_realm')) {
return;
}
$name = $this->session->getName();
$realm = '_' . md5($request->getHttpHost() . $request->getBasePath());
if (substr($name, -strlen($realm)) === $realm) {
// name ends with realm
return;
}
$this->session->setName($name . $realm);
}
示例15: render
/**
* (non-PHPdoc)
*
* @see RenderInterface::render()
*/
public function render(Request $request, Response $response, ResponseContent $content)
{
$renderer = new XMLRenderer();
$xml = $renderer->to_domdocument($content);
$xsl = new DOMDocument();
$path = Configuration::getInstance()->templates;
$template = $request->getBasePath();
$xsl->load("{$path}/{$template}.xsl");
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl);
$response->setContent($proc->transformToXML($xml));
return $response;
}