Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Platform/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ protected function initHttp(array $services): void
->desc($action->getDesc() ?? '');

if ($hook instanceof Route) {
if (! empty($action->getHttpAliasPath())) {
$hook->alias($action->getHttpAliasPath());
foreach ($action->getHttpAliases() as $alias) {
$hook->alias($alias);
}
}

Expand Down
33 changes: 11 additions & 22 deletions src/Platform/Scope/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ trait HTTP

protected ?string $httpPath = null;

protected ?string $httpAliasPath = null;

protected array $httpAliasParams = [];
/**
* @var array<string>
*/
protected array $httpAliases = [];

/**
* Set Http path
Expand Down Expand Up @@ -49,23 +50,13 @@ public function getHttpPath(): string
}

/**
* Get the value of httpAliasPath
*
* @return string
*/
public function getHttpAliasPath(): ?string
{
return $this->httpAliasPath;
}

/**
* Get the value of httpAliasParams
* Get the value of httpAliases
*
* @return array
* @return array<string>
*/
public function getHttpAliasParams(): array
public function getHttpAliases(): array
{
return $this->httpAliasParams;
return $this->httpAliases;
}

/**
Expand All @@ -79,16 +70,14 @@ public function getHttpMethod(): string
}

/**
* Set httpAlias path and params
* Append an httpAlias path. Can be called multiple times to register several aliases.
*
* @param string $path
* @param array $params
* @return self
*/
public function httpAlias(string $path, array $params = []): self
public function httpAlias(string $path): self
{
$this->httpAliasPath = $path;
$this->httpAliasParams = $params;
$this->httpAliases[] = $path;

return $this;
}
Comment on lines +78 to 83
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Breaking API change without deprecation

getHttpAliasPath(), getHttpAliasParams(), and the $params argument on httpAlias() are all removed in one step, with no deprecation shim. Any downstream code calling getHttpAliasPath(), getHttpAliasParams(), or httpAlias($path, $params) will throw a fatal error at runtime. If the library follows semver, this warrants at minimum a major-version bump or a temporary compatibility shim (getHttpAliasPath() returning the first element of $httpAliases, etc.) before removal.

Expand Down
26 changes: 26 additions & 0 deletions tests/Platform/TestActionAliased.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Utopia\Tests;

use Utopia\Platform\Action;

class TestActionAliased extends Action
{
public function __construct()
{
$this->httpPath = '/aliased';
$this->httpMethod = 'GET';
$this->httpAlias('/alias-one');
$this->httpAlias('/alias-two');
$this->httpAlias('/alias-three');
$this->inject('response');
$this->callback(function ($response) {
$this->action($response);
});
}

public function action($response)
{
$response->send('Aliased!');
}
}
1 change: 1 addition & 0 deletions tests/Platform/TestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public function __construct()
$this->addAction('redirect', new TestActionRedirect());
$this->addAction('initHook', new TestActionInit());
$this->addAction('withParams', new TestActionWithParams());
$this->addAction('aliased', new TestActionAliased());
}
}
20 changes: 20 additions & 0 deletions tests/e2e/HTTPServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ public function testHook()
$this->assertEquals('', ($response1->getHeaders()['x-init'] ?? ''));
}

public function testAliasedAction()
{
$paths = ['/aliased', '/alias-one', '/alias-two', '/alias-three'];

foreach ($paths as $path) {
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = $path;

$request = new Request();
$response = new MockResponse();

\ob_start();
$this->http->run($request, $response);
$result = \ob_get_contents();
\ob_end_clean();

$this->assertEquals('Aliased!', $result, "Alias '{$path}' should resolve to the aliased action");
}
}

public function testActionParamFieldsForwardedToRoute()
{
$routes = Http::getRoutes();
Expand Down
Loading