Skip to content

Commit

Permalink
App namespace variable (#32)
Browse files Browse the repository at this point in the history
* Add APP_NAMESPACE kernel variable

* Add APP_NAMESPACE kernel variable
  • Loading branch information
marforon authored Aug 10, 2023
1 parent 03f2d28 commit 0fbfe65
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ APP_ENV=test
APP_DEBUG=1
APP_SECRET=2b55525550c099650993e0c9b021346ddf040d38

APP_NAME=test
APP_SYSTEM=test
APP_VERSION=0.0.0
APP_READ_ONLY_MODE=0
APP_CACHE_PROXY_ENABLED=1
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return static function (array $context): Kernel {
return new Kernel(
appSystem: $context['APP_NAME'],
appNamespace: $context['APP_NAMESPACE'],
appSystem: $context['APP_SYSTEM'],
appVersion: $context['APP_VERSION'],
appReadOnlyMode: (bool) $context['APP_READ_ONLY_MODE'],
environment: $context['APP_ENV'],
Expand All @@ -72,7 +73,8 @@ require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return static function (array $context): Application {
$kernel = new Kernel(
appSystem: $context['APP_NAME'],
appNamespace: $context['APP_NAMESPACE'],
appSystem: $context['APP_SYSTEN'],
appVersion: $context['APP_VERSION'],
appReadOnlyMode: (bool) $context['APP_READ_ONLY_MODE'],
environment: $context['APP_ENV'],
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ext-mongodb": "*",
"ext-redis": "*",
"ext-zend-opcache": "*",
"anzusystems/contracts": "^2.2",
"anzusystems/contracts": "^3.0",
"anzusystems/serializer-bundle": "^2.0",
"doctrine/dbal": ">=3.0",
"doctrine/orm": ">=2.10",
Expand All @@ -36,6 +36,7 @@
"symfony/polyfill-uuid": "^1.23",
"symfony/runtime": ">=5.3|^6.0",
"symfony/security-bundle": ">=5.3.12|^6.0",
"symfony/uid": ">=5.3.12|^6.0",
"symfony/validator": ">=5.3|^6.0",
"symfony/yaml": ">=5.3|^6.0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/ApiFilter/ApiQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ private function applyFilters(): void
$iter = 0;
foreach ($this->apiParams->getFilter() as $filterVariant => $filter) {
foreach ($filter as $field => $value) {
$paramName = str_replace('.', '_', $field) . '_' . ++$iter;
/** @var string $fieldName */
$fieldName = str_replace('.', '_', $field);
$paramName = $fieldName . '_' . ++$iter;
switch ($filterVariant) {
case ApiParams::FILTER_CUSTOM:
foreach ($this->customFilters as $customFilter) {
Expand Down
2 changes: 1 addition & 1 deletion src/Csv/CsvHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function getTotalCount(SplFileObject $csv): int
return $count - 1;
}

public static function getCsv(string $filename, ?string $mode = 'r' ): SplFileObject
public static function getCsv(string $filename, string $mode = 'r'): SplFileObject
{
$userCsv = new SplFileObject($filename, $mode);
$userCsv->setFlags(SplFileObject::READ_CSV);
Expand Down
3 changes: 2 additions & 1 deletion src/Helper/CollectionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public static function colDiff(
/**
* @template T
* @template TKey of array-key
*
* @param Collection<TKey, T> $collection
* @return Collection<string, T>
*
* @return Collection<string, T>
*/
public static function getIndexedByUuid(Collection $collection): Collection
{
Expand Down
2 changes: 2 additions & 0 deletions src/Kernel/AnzuKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AnzuKernel extends Kernel
private string $contextId = '';

public function __construct(
private readonly string $appNamespace,
private readonly string $appSystem,
private readonly string $appVersion,
private readonly bool $appReadOnlyMode,
Expand All @@ -51,6 +52,7 @@ public function __construct(
public function boot(): void
{
AnzuApp::init(
appNamespace: $this->appNamespace,
appSystem: $this->appSystem,
appVersion: $this->appVersion,
appReadOnlyMode: $this->appReadOnlyMode,
Expand Down
6 changes: 6 additions & 0 deletions src/Security/Voter/AbstractVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;

/**
* @template TAttribute of string
* @template TSubject of mixed
*
* @template-extends Voter<TAttribute, TSubject>
*/
abstract class AbstractVoter extends Voter
{
use SecurityAwareTrait;
Expand Down
3 changes: 2 additions & 1 deletion src/Tests/Traits/AnzuKernelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ protected static function createKernel(array $options = []): AnzuKernel
$kernelClass = static::getKernelClass();

return new $kernelClass(
appSystem: (string) self::resolveKernelOption($options, 'name', 'APP_NAME', ''),
appNamespace: (string) self::resolveKernelOption($options, 'namespace', 'APP_NAMESPACE', ''),
appSystem: (string) self::resolveKernelOption($options, 'system', 'APP_SYSTEM', ''),
appVersion: (string) self::resolveKernelOption($options, 'version', 'APP_VERSION', '0.0.0'),
appReadOnlyMode: (bool) self::resolveKernelOption($options, 'debug', 'APP_READ_ONLY_MODE', false),
environment: (string) self::resolveKernelOption($options, 'environment', 'APP_ENV', 'test'),
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/CacheControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testCache(): void
self::$client->getResponse()->headers->get('xkey')
);
self::assertStringContainsString(
UserCacheSettings::getSystemXkey(),
UserCacheSettings::getProjectXkey(),
self::$client->getResponse()->headers->get('xkey')
);
self::assertSame(
Expand Down
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
AnnotationReader::addGlobalIgnoredNamespace('Nelmio');

$kernel = new AnzuTestKernel(
appNamespace: 'petitpress',
appSystem: 'commonbundle',
appVersion: 'dev',
appReadOnlyMode: false,
Expand Down
2 changes: 2 additions & 0 deletions tests/data/Response/Cache/UserCacheSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ public function __construct(
) {
parent::__construct(60);
}

public static function buildXKeyFromObject(object $data): string
{
if ($data instanceof AnzuUser) {
return self::XKEY_PREFIX . '-' . ((string) $data->getId());
}
return self::XKEY_PREFIX;
}

protected function getXKeys(): array
{
return [
Expand Down

0 comments on commit 0fbfe65

Please sign in to comment.