Skip to content

Commit

Permalink
Changed event structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof committed Aug 9, 2023
1 parent 7d09e3e commit 1f3a4c3
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 85 deletions.

This file was deleted.

43 changes: 24 additions & 19 deletions src/contracts/Event/NameSchema/AbstractNameSchemaEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,40 @@

namespace Ibexa\Contracts\Core\Event\NameSchema;

use Symfony\Contracts\EventDispatcher\Event;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;

abstract class AbstractNameSchemaEvent extends Event
abstract class AbstractNameSchemaEvent extends AbstractSchemaEvent
{
/** @var array<string, array> */
protected array $schemaIdentifiers;

/**
* @var array<string, array<string>>
*/
protected array $tokenValues = [];

public function __construct(array $schemaIdentifiers)
{
$this->schemaIdentifiers = $schemaIdentifiers;
private ContentType $contentType;

private array $fieldMap;

private array $languageCodes;

public function __construct(
array $schemaIdentifiers,
ContentType $contentType,
array $fieldMap,
array $languageCodes
) {
parent::__construct($schemaIdentifiers);
$this->contentType = $contentType;
$this->fieldMap = $fieldMap;
$this->languageCodes = $languageCodes;
}

public function getTokenValues(): array
public function getContentType(): ContentType
{
return $this->tokenValues;
return $this->contentType;
}

public function setTokenValues(array $names): void
public function getFieldMap(): array
{
$this->tokenValues = $names;
return $this->fieldMap;
}

public function getSchemaIdentifiers(): array
public function getLanguageCodes(): array
{
return $this->schemaIdentifiers;
return $this->languageCodes;
}
}
40 changes: 40 additions & 0 deletions src/contracts/Event/NameSchema/AbstractSchemaEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Core\Event\NameSchema;

use Symfony\Contracts\EventDispatcher\Event;

abstract class AbstractSchemaEvent extends Event
{
/** @var array<string, array> */
protected array $schemaIdentifiers;

/** @var array<string, array<string>> */
protected array $tokenValues = [];

public function __construct(array $schemaIdentifiers)
{
$this->schemaIdentifiers = $schemaIdentifiers;
}

public function getTokenValues(): array
{
return $this->tokenValues;
}

public function setTokenValues(array $names): void
{
$this->tokenValues = $names;
}

public function getSchemaIdentifiers(): array
{
return $this->schemaIdentifiers;
}
}
15 changes: 15 additions & 0 deletions src/contracts/Event/NameSchema/ContentAwareEventInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Core\Event\NameSchema;

use Ibexa\Contracts\Core\Repository\Values\Content\Content;

interface ContentAwareEventInterface
{
public function getContent(): Content;
}
22 changes: 21 additions & 1 deletion src/contracts/Event/NameSchema/ResolveContentNameSchemaEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@

namespace Ibexa\Contracts\Core\Event\NameSchema;

final class ResolveContentNameSchemaEvent extends AbstractContentAwareNameSchemaEvent
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;

final class ResolveContentNameSchemaEvent extends AbstractNameSchemaEvent implements ContentAwareEventInterface
{
protected Content $content;

public function __construct(
Content $content,
array $schemaIdentifiers,
ContentType $contentType,
array $fieldMap,
array $languageCodes
) {
parent::__construct($schemaIdentifiers, $contentType, $fieldMap, $languageCodes);
$this->content = $content;
}

public function getContent(): Content
{
return $this->content;
}
}
33 changes: 0 additions & 33 deletions src/contracts/Event/NameSchema/ResolveNameSchemaEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,7 @@

namespace Ibexa\Contracts\Core\Event\NameSchema;

use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;

final class ResolveNameSchemaEvent extends AbstractNameSchemaEvent
{
private ContentType $contentType;

private array $fieldMap;

private array $languageCodes;

public function __construct(
array $schemaIdentifiers,
ContentType $contentType,
array $fieldMap,
array $languageCodes
) {
parent::__construct($schemaIdentifiers);
$this->contentType = $contentType;
$this->fieldMap = $fieldMap;
$this->languageCodes = $languageCodes;
}

public function getContentType(): ContentType
{
return $this->contentType;
}

public function getFieldMap(): array
{
return $this->fieldMap;
}

public function getLanguageCodes(): array
{
return $this->languageCodes;
}
}
18 changes: 17 additions & 1 deletion src/contracts/Event/NameSchema/ResolveUrlAliasSchemaEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@

namespace Ibexa\Contracts\Core\Event\NameSchema;

final class ResolveUrlAliasSchemaEvent extends AbstractContentAwareNameSchemaEvent
use Ibexa\Contracts\Core\Repository\Values\Content\Content;

final class ResolveUrlAliasSchemaEvent extends AbstractSchemaEvent implements ContentAwareEventInterface
{
protected Content $content;

public function __construct(
array $schemaIdentifiers,
Content $content
) {
parent::__construct($schemaIdentifiers);
$this->content = $content;
}

public function getContent(): Content
{
return $this->content;
}
}
12 changes: 10 additions & 2 deletions src/lib/Repository/NameSchema/NameSchemaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,16 @@ public function resolveNameSchema(
return $this->buildNames($event->getTokenValues(), $schemaName);
}

public function resolve(string $nameSchema, ContentType $contentType, array $fieldMap, array $languageCodes): array
{
public function resolveContentNameSchema(){

}

public function resolve(
string $nameSchema,
ContentType $contentType,
array $fieldMap,
array $languageCodes
): array {
$schemaIdentifiers = $this->schemaIdentifierExtractor->extract($nameSchema);
$event = $this->eventDispatcher->dispatch(
new ResolveNameSchemaEvent(
Expand Down

0 comments on commit 1f3a4c3

Please sign in to comment.