Skip to content

Commit

Permalink
Mark old methods as deprecated for better future reusability.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Oct 29, 2022
1 parent b160374 commit dc503e6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Endpoint/BaseEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ abstract class BaseEndpoint implements Endpoint
/** @var callable[] */
public array $onSaveState = [];

/** @deprecated since 2022-10-29, please use static DIC constructor dependencies. */
protected Container $container;

protected Convention $convention;

/** @var mixed[] */
/**
* @var mixed[]
* @deprecated since 2022-10-29, please use native typed method arguments.
*/
protected array $data = [];

/** @var array<int, array{message: string, type: string}> */
Expand Down Expand Up @@ -78,6 +82,7 @@ public function startup(): void

/**
* Get current endpoint name.
* @deprecated since 2022-10-29, please use native class name or meta entity.
*/
final public function getName(): string
{
Expand All @@ -93,6 +98,7 @@ final public function getName(): string
* do not have a predetermined structure that we are able to describe as an object.
*
* @return array<int|string, mixed>
* @deprecated since 2022-10-29, please use native typed method arguments.
*/
public function getData(): array
{
Expand Down Expand Up @@ -330,6 +336,7 @@ final public function getUserEntity(): ?IIdentity
}


/** @deprecated since 2022-10-29, please use baraja-core/cas instead. */
final public function getAuthorizator(): Authorizator
{
$authorizator = $this->getUser()->getAuthorizatorIfExists();
Expand Down Expand Up @@ -382,6 +389,7 @@ final public function linkSafe(string $dest, array $params = []): ?string
* @param positive-int $httpCode
* @phpstan-return never-return
* @throws ThrowResponse
* @deprecated since 2022-10-29, please remove this feature from your project. Redirect is anti-pattern for API.
*/
final public function redirect(string $dest, array $params = [], int $httpCode = 301): void
{
Expand All @@ -393,6 +401,7 @@ final public function redirect(string $dest, array $params = [], int $httpCode =
* @param positive-int $httpCode
* @phpstan-return never-return
* @throws ThrowResponse
* @deprecated since 2022-10-29, please remove this feature from your project. Redirect is anti-pattern for API.
*/
final public function redirectUrl(string $url, int $httpCode = 301): void
{
Expand All @@ -403,6 +412,7 @@ final public function redirectUrl(string $url, int $httpCode = 301): void
}


/** @deprecated since 2022-10-29, please implement it in your project. */
final public function getCache(?string $namespace = null): Cache
{
static $storage;
Expand All @@ -420,6 +430,7 @@ final public function getCache(?string $namespace = null): Cache
}


/** @deprecated since 2022-10-29, please implement it in your project. */
final public function getTranslator(): Translator
{
static $translator;
Expand All @@ -433,6 +444,7 @@ final public function getTranslator(): Translator

/**
* @param array<string, mixed>|mixed ...$parameters
* @deprecated since 2022-10-29, please implement it in your project.
*/
final public function translate(mixed $message, ...$parameters): string
{
Expand All @@ -442,13 +454,17 @@ final public function translate(mixed $message, ...$parameters): string

/**
* @return array<string, mixed>
* @deprecated since 2022-10-29, please inject scala parameters to individual DIC services.
*/
final public function getParameters(): array
{
return $this->container->getParameters();
}


/**
* @deprecated since 2022-10-29, please inject scala parameters to individual DIC services.
*/
final public function getParameter(string $key, mixed $defaultValue = null): mixed
{
return $this->container->getParameters()[$key] ?? $defaultValue;
Expand All @@ -463,10 +479,10 @@ final public function injectContainer(Container $container): void

/**
* Is it an AJAX request?
* @deprecated since 2022-10-29, please use static helper.
*/
final public function isAjax(): bool
{
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'xmlhttprequest'
|| isset($_SERVER['HTTP_X_TRACY_AJAX']);
return Helpers::isAjax();
}
}
10 changes: 10 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,14 @@ public static function parseRolesFromComment(string $comment): array

return [];
}


/**
* Is it an AJAX request?
*/
public static function isAjax(): bool
{
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'xmlhttprequest'
|| isset($_SERVER['HTTP_X_TRACY_AJAX']);
}
}

0 comments on commit dc503e6

Please sign in to comment.