Skip to content

Commit

Permalink
feat: add ability to set IDE url template
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Apr 24, 2024
1 parent fed0a63 commit 15dbbd3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
16 changes: 16 additions & 0 deletions app/src/Application/AppVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Application;

use Spiral\Core\Attribute\Singleton;

#[Singleton]
final readonly class AppVersion
{
public function __construct(
public string $version,
) {
}
}
21 changes: 20 additions & 1 deletion app/src/Application/Bootloader/AppBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace App\Application\Bootloader;

use App\Application\AppVersion;
use App\Application\HTTP\Interceptor\JsonResourceInterceptor;
use App\Application\HTTP\Interceptor\StringToIntParametersInterceptor;
use App\Application\HTTP\Interceptor\UuidParametersConverterInterceptor;
use App\Application\Ide\UrlTemplate;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Bootloader\DomainBootloader;
use Spiral\Core\CoreInterface;

Expand All @@ -15,7 +18,23 @@ final class AppBootloader extends DomainBootloader
public function defineSingletons(): array
{
return [
CoreInterface::class => fn(\Spiral\Core\Core $core, \Psr\Container\ContainerInterface $container, ?\Psr\EventDispatcher\EventDispatcherInterface $dispatcher = null): \Spiral\Core\InterceptableCore => self::domainCore($core, $container, $dispatcher),
CoreInterface::class => fn(
\Spiral\Core\Core $core,
\Psr\Container\ContainerInterface $container,
?\Psr\EventDispatcher\EventDispatcherInterface $dispatcher = null,
): \Spiral\Core\InterceptableCore => self::domainCore($core, $container, $dispatcher),

UrlTemplate::class => fn(
EnvironmentInterface $env,
): UrlTemplate => new UrlTemplate(
template: $env->get('IDE_URL_TEMPLATE', 'phpstorm://open?url=file://%s&line=%d'),
),

AppVersion::class => fn(
EnvironmentInterface $env,
): AppVersion => new AppVersion(
version: $env->get('APP_VERSION', 'dev'),
),
];
}

Expand Down
16 changes: 16 additions & 0 deletions app/src/Application/Ide/UrlTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Application\Ide;

use Spiral\Core\Attribute\Singleton;

#[Singleton]
final readonly class UrlTemplate
{
public function __construct(
public string $template,
) {
}
}
16 changes: 13 additions & 3 deletions app/src/Interfaces/Http/Controller/SettingsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@

namespace App\Interfaces\Http\Controller;

use App\Application\AppVersion;
use App\Application\Auth\AuthSettings;
use App\Application\HTTP\Response\JsonResource;
use App\Application\HTTP\Response\ResourceInterface;
use App\Application\Ide\UrlTemplate;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Router\Annotation\Route;

final class SettingsAction
{
#[Route(route: 'settings', methods: ['GET'], group: 'api_guest')]
public function __invoke(EnvironmentInterface $env, AuthSettings $settings): ResourceInterface
public function __invoke(
EnvironmentInterface $env,
AuthSettings $settings,
UrlTemplate $ideUrl,
AppVersion $appVersion,
): ResourceInterface
{
return new JsonResource([
'auth' => [
'enabled' => $settings->enabled,
'login_url' => (string) $settings->loginUrl,
'login_url' => (string)$settings->loginUrl,
],
'version' => $env->get('APP_VERSION', 'dev'),
'ide' => [
'url_template' => $ideUrl->template,
],
'version' => $appVersion->version,
]);
}
}

0 comments on commit 15dbbd3

Please sign in to comment.