Skip to content

Commit

Permalink
Testing & refactoring in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Dec 14, 2023
1 parent 762a8a5 commit 7873014
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 73 deletions.
72 changes: 0 additions & 72 deletions src/functions/framework-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,78 +121,6 @@ function sMVC_DumpVar(...$vals): void {
}
}

/**
* Returns the base path segment of the URI.
* It performs the same function as \Slim\Http\Uri::getBasePath()
* You are strongly advised to use this function instead of
* \Slim\Http\Uri::getBasePath(), in order to ensure that your
* app will be compatible with other PSR-7 implementations because
* \Slim\Http\Uri::getBasePath() is not a PSR-7 method.
*
* @deprecated since version 4.x
* @see SlimMvcTools\Controllers\BaseController->getAppBasePath()
* @psalm-suppress MixedInferredReturnType
*/
function sMVC_GetBaseUrlPath(): string {

static $server, $base_path, $has_been_computed;

if( !$server ) {

//copy / capture the super global only once
/** @psalm-suppress MixedAssignment */
$server = sMVC_GetSuperGlobal('server');
}

if( !$base_path && !$has_been_computed ) {

$base_path = '';
$has_been_computed = true;
/**
* @psalm-suppress MixedArgument
* @psalm-suppress MixedArrayAccess
*/
$requestScriptName = (string) parse_url($server['SCRIPT_NAME'], PHP_URL_PATH);
$requestScriptDir = dirname($requestScriptName);

// parse_url() requires a full URL. As we don't extract the domain name or scheme,
// we use a stand-in.
/**
* @psalm-suppress MixedArrayAccess
* @psalm-suppress MixedOperand
*/
$requestUri = (string) parse_url( 'http://example.com' . $server['REQUEST_URI'], PHP_URL_PATH);

if (stripos($requestUri, $requestScriptName) === 0) {

$base_path = $requestScriptName;

} elseif ($requestScriptDir !== '/' && stripos($requestUri, $requestScriptDir) === 0) {

$base_path = $requestScriptDir;
}
}

/** @psalm-suppress MixedReturnStatement */
return $base_path;
}

/**
* Generates a link prepended with sMVC_GetBaseUrlPath().
* Can be used for generating values for the href attribute of an a or link tag, or the src
* atrribute of a script tag, etc.
*
* @param string $path
*
* @deprecated since version 4.x
* @see SlimMvcTools\Controllers\BaseController->makeLink(string $path): string
*/
function sMVC_MakeLink(string $path): string {

/** @psalm-suppress DeprecatedFunction */
return sMVC_GetBaseUrlPath(). '/'.ltrim($path, '/');
}

/**
* This function stores a snapshot of the following super globals $_SERVER, $_GET,
* $_POST, $_FILES, $_COOKIE, $_SESSION & $_ENV and then returns the stored values
Expand Down
7 changes: 6 additions & 1 deletion tests/FrameworkHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ public function testThat_sMVC_addQueryStrParamToUri_WorksAsExpected() {
$this->newRequest()->getUri(),
'baa', 'yoo'
);
self::assertEquals('http://tnyholm.se/blah?var=1&baa=yoo', sMVC_UriToString($result));

$result2 = sMVC_AddQueryStrParamToUri(
$result,
'boo', 'baa'
);
self::assertEquals('http://tnyholm.se/blah?var=1&baa=yoo&boo=baa', sMVC_UriToString($result2));
}

public function testThat_sMVC_DisplayAndLogFrameworkFileNotFoundError_WorksAsExpected() {
Expand Down

0 comments on commit 7873014

Please sign in to comment.