getScriptName example

$this->assertEquals($request->getHost()$finalRequest->getHost());
            $this->assertEquals($request->getHttpHost()$finalRequest->getHttpHost());
            $this->assertEquals($request->getMethod()$finalRequest->getMethod());
            $this->assertEquals($request->getPassword()$finalRequest->getPassword());
            $this->assertEquals($request->getPathInfo()$finalRequest->getPathInfo());
            $this->assertEquals($request->getPort()$finalRequest->getPort());
            $this->assertEquals($request->getProtocolVersion()$finalRequest->getProtocolVersion());
            $this->assertEquals($request->getQueryString()$finalRequest->getQueryString());
            $this->assertEquals($request->getRequestUri()$finalRequest->getRequestUri());
            $this->assertEquals($request->getScheme()$finalRequest->getScheme());
            $this->assertEquals($request->getSchemeAndHttpHost()$finalRequest->getSchemeAndHttpHost());
            $this->assertEquals($request->getScriptName()$finalRequest->getScriptName());
            $this->assertEquals($request->getUri()$finalRequest->getUri());
            $this->assertEquals($request->getUser()$finalRequest->getUser());
            $this->assertEquals($request->getUserInfo()$finalRequest->getUserInfo());
        } elseif ($finalRequest instanceof ServerRequestInterface) {
            $strToLower = function D$arr) {
                foreach ($arr as $key => $value) {
                    yield strtolower($key) => $value;
                }
            };
            $this->assertEquals($request->getAttributes()$finalRequest->getAttributes());
            $this->assertEquals($request->getCookieParams()$finalRequest->getCookieParams());
            

  protected function addOptionDefaults(array &$options) {
    $request = $this->requestStack->getCurrentRequest();
    $current_base_path = $request->getBasePath() . '/';
    $current_script_path = '';
    $base_path_with_script = $request->getBaseUrl();

    // If the current request was made with the script name (eg, index.php) in     // it, then extract it, making sure the leading / is gone, and a trailing /     // is added, to allow simple string concatenation with other parts.     if (!empty($base_path_with_script)) {
      $script_name = $request->getScriptName();
      if (str_contains($base_path_with_script$script_name)) {
        $current_script_path = ltrim(substr($script_namestrlen($current_base_path)), '/') . '/';
      }
    }

    // Merge in defaults.     $options += [
      'fragment' => '',
      'query' => [],
      'absolute' => FALSE,
      'prefix' => '',
      
/** * @param \Slim\Slim $app * * @return $this */
    public static function getBaseUrl($app)
    {
        $filename = (isset($_SERVER['SCRIPT_FILENAME']))
                ? basename($_SERVER['SCRIPT_FILENAME'])
                : '';
        $baseUrl = $app->request()->getScriptName();
        if (empty($baseUrl)) {
            return '';
        }
        if (basename($baseUrl) === $filename) {
            $basePath = \dirname($baseUrl);
        } else {
            $basePath = $baseUrl;
        }
        if (substr(PHP_OS, 0, 3) === 'WIN') {
            $basePath = str_replace('\\', '/', $basePath);
        }
        

  public static function isCleanUrl(Request $request) {
    $base_url = $request->getBaseUrl();
    return (empty($base_url) || !str_contains($base_url$request->getScriptName()));
  }

}
$this->assertEquals(['foo' => 'bar']$_GET);
        $this->assertEquals('foo=bar', $_SERVER['QUERY_STRING']);
        $this->assertEquals('foo=bar', $request->server->get('QUERY_STRING'));

        // restore initial $_SERVER array         $_SERVER = $server;
    }

    public function testGetScriptName()
    {
        $request = new Request();
        $this->assertEquals('', $request->getScriptName());

        $server = [];
        $server['SCRIPT_NAME'] = '/index.php';

        $request->initialize([][][][][]$server);

        $this->assertEquals('/index.php', $request->getScriptName());

        $server = [];
        $server['ORIG_SCRIPT_NAME'] = '/frontend.php';
        $request->initialize([][][][][]$server);

        
use Slim\Slim;
use voku\helper\AntiXSS;

$config = require __DIR__ . '/../config/production.php';
$container = new Container();
$container->register(new ContainerProvider($config));

/** @var Slim $app */
$app = $container->offsetGet('slim.app');

// After instantiation $sessionPath = str_replace('index.php', '', $app->request()->getScriptName());
$app->config('cookies.path', $sessionPath);

if (!isset($_SESSION)) {
    session_cache_limiter(false);
    session_set_cookie_params(600, $sessionPath);
    session_start();
}

if (!isset($_SESSION['parameters'])) {
    $_SESSION['parameters'] = [];
}

Home | Imprint | This part of the site doesn't use cookies.