Skip to content

Commit dc503e6

Browse files
committed
Mark old methods as deprecated for better future reusability.
1 parent b160374 commit dc503e6

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/Endpoint/BaseEndpoint.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ abstract class BaseEndpoint implements Endpoint
4545
/** @var callable[] */
4646
public array $onSaveState = [];
4747

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

5051
protected Convention $convention;
5152

52-
/** @var mixed[] */
53+
/**
54+
* @var mixed[]
55+
* @deprecated since 2022-10-29, please use native typed method arguments.
56+
*/
5357
protected array $data = [];
5458

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

7983
/**
8084
* Get current endpoint name.
85+
* @deprecated since 2022-10-29, please use native class name or meta entity.
8186
*/
8287
final public function getName(): string
8388
{
@@ -93,6 +98,7 @@ final public function getName(): string
9398
* do not have a predetermined structure that we are able to describe as an object.
9499
*
95100
* @return array<int|string, mixed>
101+
* @deprecated since 2022-10-29, please use native typed method arguments.
96102
*/
97103
public function getData(): array
98104
{
@@ -330,6 +336,7 @@ final public function getUserEntity(): ?IIdentity
330336
}
331337

332338

339+
/** @deprecated since 2022-10-29, please use baraja-core/cas instead. */
333340
final public function getAuthorizator(): Authorizator
334341
{
335342
$authorizator = $this->getUser()->getAuthorizatorIfExists();
@@ -382,6 +389,7 @@ final public function linkSafe(string $dest, array $params = []): ?string
382389
* @param positive-int $httpCode
383390
* @phpstan-return never-return
384391
* @throws ThrowResponse
392+
* @deprecated since 2022-10-29, please remove this feature from your project. Redirect is anti-pattern for API.
385393
*/
386394
final public function redirect(string $dest, array $params = [], int $httpCode = 301): void
387395
{
@@ -393,6 +401,7 @@ final public function redirect(string $dest, array $params = [], int $httpCode =
393401
* @param positive-int $httpCode
394402
* @phpstan-return never-return
395403
* @throws ThrowResponse
404+
* @deprecated since 2022-10-29, please remove this feature from your project. Redirect is anti-pattern for API.
396405
*/
397406
final public function redirectUrl(string $url, int $httpCode = 301): void
398407
{
@@ -403,6 +412,7 @@ final public function redirectUrl(string $url, int $httpCode = 301): void
403412
}
404413

405414

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

422432

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

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

443455
/**
444456
* @return array<string, mixed>
457+
* @deprecated since 2022-10-29, please inject scala parameters to individual DIC services.
445458
*/
446459
final public function getParameters(): array
447460
{
448461
return $this->container->getParameters();
449462
}
450463

451464

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

464480
/**
465481
* Is it an AJAX request?
482+
* @deprecated since 2022-10-29, please use static helper.
466483
*/
467484
final public function isAjax(): bool
468485
{
469-
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'xmlhttprequest'
470-
|| isset($_SERVER['HTTP_X_TRACY_AJAX']);
486+
return Helpers::isAjax();
471487
}
472488
}

src/Helpers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,14 @@ public static function parseRolesFromComment(string $comment): array
135135

136136
return [];
137137
}
138+
139+
140+
/**
141+
* Is it an AJAX request?
142+
*/
143+
public static function isAjax(): bool
144+
{
145+
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'xmlhttprequest'
146+
|| isset($_SERVER['HTTP_X_TRACY_AJAX']);
147+
}
138148
}

0 commit comments

Comments
 (0)