Example #1
0
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     if (strpos($request->getRequestUri(), 'installer') !== false || !$this->isInstalled()) {
         define('MAUTIC_INSTALLER', 1);
     } else {
         //set the table prefix before boot
         $localParams = $this->getLocalParams();
         $prefix = isset($localParams['db_table_prefix']) ? $localParams['db_table_prefix'] : '';
         define('MAUTIC_TABLE_PREFIX', $prefix);
     }
     if (false === $this->booted) {
         $this->boot();
     }
     //the context is not populated at this point so have to do it manually
     $router = $this->getContainer()->get('router');
     $requestContext = new \Symfony\Component\Routing\RequestContext();
     $requestContext->fromRequest($request);
     $router->setContext($requestContext);
     if (strpos($request->getRequestUri(), 'installer') === false && !$this->isInstalled()) {
         //the context is not populated at this point so have to do it manually
         $router = $this->getContainer()->get('router');
         $requestContext = new \Symfony\Component\Routing\RequestContext();
         $requestContext->fromRequest($request);
         $router->setContext($requestContext);
         $base = $requestContext->getBaseUrl();
         //check to see if the .htaccess file exists or if not running under apache
         if (strpos(strtolower($_SERVER["SERVER_SOFTWARE"]), 'apache') === false || !file_exists(__DIR__ . '../.htaccess') && strpos($base, 'index') === false) {
             $base .= '/index.php';
         }
         //return new RedirectResponse();
         return new RedirectResponse($base . '/installer');
     }
     // Check for an an active db connection and die with error if unable to connect
     if (!defined('MAUTIC_INSTALLER')) {
         $db = $this->getContainer()->get('database_connection');
         try {
             $db->connect();
         } catch (\Exception $e) {
             error_log($e);
             throw new \Mautic\CoreBundle\Exception\DatabaseConnectionException($this->getContainer()->get('translator')->trans('mautic.core.db.connection.error', array('%code%' => $e->getCode())));
         }
     }
     return parent::handle($request, $type, $catch);
 }
Example #2
0
 /**
  * handle()
  *
  * Function to start the application and the framework behind it
  */
 public final function handle(\Symfony\Component\HttpFoundation\Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     // Set up environment
     $this->setUpEnvironment();
     // Init request stack and request
     $this->requestStack = new \Symfony\Component\HttpFoundation\RequestStack();
     $this->requestStack->push($request);
     // Init response from HttpFoundation
     $this->response = \Symfony\Component\HttpFoundation\Response::create()->prepare($this->requestStack->getCurrentRequest());
     // Start session
     $this->startSessionHandler();
     // Request context for routing
     $context = new \Symfony\Component\Routing\RequestContext();
     $context->fromRequest($this->requestStack->getCurrentRequest());
     // Setup routing
     $this->setUpRouting($context);
     // Setup twig
     $this->setUpTwig();
     // Allow access to symfony component form views
     $this->templateRender->addGlobal("request", $this->requestStack->getCurrentRequest());
     $this->templateRender->addGlobal("response", $this->response);
     $this->templateRender->addGlobal("routing", $this->routing);
     $this->templateRender->addGlobal("session", $this->session);
     $this->templateRender->addGlobal("flash", $this->session->getFlashBag());
     // Pre hook
     $this->preApplicationStart();
     // Find controller and action
     try {
         // Match path
         $currentRoute = $this->routing->match($this->requestStack->getCurrentRequest()->getPathInfo());
     } catch (\Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
         // Use default route
         $currentRoute = $this->defaultRoute;
     }
     // Set action
     if (!isset($currentRoute['_action'])) {
         $currentRoute['_action'] = 'index';
     }
     // Set request parameters
     $this->requestStack->getCurrentRequest()->attributes = new \Symfony\Component\HttpFoundation\ParameterBag($currentRoute);
     // Try to load the requested controller and action
     $data = $this->performAction($currentRoute['_controller'], $currentRoute['_action']);
     // Render json directly
     if ($this->response instanceof \Symfony\Component\HttpFoundation\JsonResponse) {
         return $this->response;
     }
     // Render template
     if (!isset($this->response->template) || false !== $this->response->template) {
         // Generate template name if not set
         if (!isset($this->response->template)) {
             $this->response->template = strtolower($currentRoute['_controller'] . '/' . $currentRoute['_action']);
         }
         // Load and render template
         $data = $this->templateRender->loadTemplate($this->response->template . '.html.twig')->render($data);
     }
     // Add content
     $this->response->setContent($data);
     // Return response
     return $this->response;
 }
    $transport = \Swift_MailTransport::newInstance();
    if ($c['config']['debug']) {
        // Debug mode will write all sent emails to cache dir
        $transport = \Swift_SpoolTransport::newInstance(new \Swift_FileSpool($c['res_dir'] . '/cache/mailspool'));
    }
    return \Swift_Mailer::newInstance($transport);
};
$c['router.routes'] = function ($c) {
    $routes = (require $c['app_dir'] . '/routing.php');
    return $routes;
};
$c['router'] = function ($c) {
    if (isset($c['request'])) {
        // If the request is set, use it
        // http://symfony.com/doc/current/components/routing/introduction.html#components-routing-http-foundation
        $context = new Symfony\Component\Routing\RequestContext();
        $context->fromRequest($c['request']);
    } else {
        $context = new Symfony\Component\Routing\RequestContext(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '');
    }
    $matcher = new Symfony\Component\Routing\Matcher\UrlMatcher($c['router.routes'], $context);
    return $matcher;
};
$c['dispather'] = function ($c) {
    return new \Symfony\Component\EventDispatcher\EventDispatcher();
};
$c['request'] = function ($c) {
    return \Symfony\Component\HttpFoundation\Request::createFromGlobals();
};
$c['util.uri'] = function ($c) {
    return new \Eng\Core\Util\Uri($c);
Example #4
0
 /**
  * Inspects the request and determines what to serve.
  */
 public function dispatch(Request $request)
 {
     // This is a crappy place for this, but it has to come AFTER the packages because sometimes packages
     // want to replace legacy "tools" URLs with the new MVC, and the tools paths are so greedy they don't
     // work unless they come at the end.
     $this->registerLegacyRoutes();
     $path = rawurldecode($request->getPathInfo());
     if (substr($path, 0, 3) == '../' || substr($path, -3) == '/..' || strpos($path, '/../') || substr($path, 0, 3) == '..\\' || substr($path, -3) == '\\..' || strpos($path, '\\..\\')) {
         throw new \RuntimeException(t('Invalid path traversal. Please make this request with a valid HTTP client.'));
     }
     if ($this->installed) {
         $response = $this->getEarlyDispatchResponse();
     }
     if (!isset($response)) {
         $collection = Route::getList();
         $context = new \Symfony\Component\Routing\RequestContext();
         $context->fromRequest($request);
         $matcher = new UrlMatcher($collection, $context);
         $path = rtrim($request->getPathInfo(), '/') . '/';
         try {
             $request->attributes->add($matcher->match($path));
             $matched = $matcher->match($path);
             $route = $collection->get($matched['_route']);
             Route::setRequest($request);
             $response = Route::execute($route, $matched);
         } catch (ResourceNotFoundException $e) {
             $callback = new DispatcherRouteCallback('dispatcher');
             $response = $callback->execute($request);
         }
     }
     return $response;
 }
Example #5
0
#!/usr/bin/php
<?php 
$config = ['require_services' => ['sf_event_dispatcher', 'sf_http_foundation', 'sf_debug', 'psr_log', 'sf_routing'], 'git_urls' => ['https://github.com/symfony/HttpKernel.git' => 'sf_http_kernel/'], 'autoload_config' => ['sf_http_kernel/' => 'Symfony\\Component\\HttpKernel'], 'example' => function () {
    $old_level = error_reporting();
    error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED & ~E_STRICT);
    $routes = new \Symfony\Component\Routing\RouteCollection();
    $routes->add('hello', new \Symfony\Component\Routing\Route('/', ['_controller' => function (\Symfony\Component\HttpFoundation\Request $request) {
        return new \Symfony\Component\HttpFoundation\Response(sprintf("Hello %s", $request->get('name')));
    }]));
    $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
    $context = new \Symfony\Component\Routing\RequestContext();
    $context->fromRequest($request);
    $matcher = new \Symfony\Component\Routing\Matcher\UrlMatcher($routes, $context);
    $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
    $dispatcher->addSubscriber(new \Symfony\Component\HttpKernel\EventListener\RouterListener($matcher));
    $resolver = new \Symfony\Component\HttpKernel\Controller\ControllerResolver();
    $kernel = new \Symfony\Component\HttpKernel\HttpKernel($dispatcher, $resolver);
    $kernel->handle($request)->send();
    echo PHP_EOL;
    error_reporting($old_level);
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
Example #6
0
 /**
  * @param string $route
  *
  * @return string|null
  */
 protected static function getAssetContentsByRoute($route)
 {
     $result = null;
     try {
         $routes = \Route::getList();
         /* @var $routes \Symfony\Component\Routing\RouteCollection */
         $context = new \Symfony\Component\Routing\RequestContext();
         $request = \Request::getInstance();
         $context->fromRequest($request);
         $matcher = new \Symfony\Component\Routing\Matcher\UrlMatcher($routes, $context);
         $matched = null;
         try {
             $matched = $matcher->match($route);
         } catch (\Exception $x) {
             $m = null;
             // Route matcher requires that paths ends with a slash
             if (preg_match('/^(.*[^\\/])($|\\?.*)$/', $route, $m)) {
                 try {
                     $matched = $matcher->match($m[1] . '/' . (isset($m[2]) ? $m[2] : ''));
                 } catch (\Exception $x) {
                 }
             }
         }
         if (isset($matched)) {
             $controller = $matched['_controller'];
             if (is_callable($controller)) {
                 ob_start();
                 $r = call_user_func($controller, false);
                 if ($r !== false) {
                     $result = ob_get_contents();
                 }
                 ob_end_clean();
             }
         }
     } catch (\Exception $x) {
     }
     return $result;
 }
Example #7
0
 /**
  * Inspects the request and determines what to serve.
  */
 public function dispatch(Request $request)
 {
     if ($this->installed) {
         $response = $this->getEarlyDispatchResponse();
     }
     if (!isset($response)) {
         $collection = Route::getList();
         $context = new \Symfony\Component\Routing\RequestContext();
         $context->fromRequest($request);
         $matcher = new UrlMatcher($collection, $context);
         $path = rtrim($request->getPathInfo(), '/') . '/';
         try {
             $request->attributes->add($matcher->match($path));
             $matched = $matcher->match($path);
             $route = $collection->get($matched['_route']);
             Route::setRequest($request);
             $response = Route::execute($route, $matched);
         } catch (ResourceNotFoundException $e) {
             $callback = new DispatcherRouteCallback('dispatcher');
             $response = $callback->execute($request);
         }
     }
     return $response;
 }
 /**
  * @return \Symfony\Component\Routing\RequestContext
  */
 public function getSymfony_Component_RequestContextService()
 {
     if (!isset(self::$_services['symfony.component.request_context'])) {
         $instance = new Symfony\Component\Routing\RequestContext();
         $instance->fromRequest($this->getTagService('request'));
         self::$_services['symfony.component.request_context'] = $instance;
     }
     return self::$_services['symfony.component.request_context'];
 }