forked from shopware/shopware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEXT-31522 - Allow to define entities over php attribute directly at …
…the entity class instead of defining an definition
- Loading branch information
1 parent
1d0db0f
commit 18f6b42
Showing
41 changed files
with
968 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Core/Framework/DataAbstractionLayer/Attribute/CustomFields.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class CustomFields extends Field | ||
{ | ||
public const TYPE = 'custom-fields'; | ||
|
||
public function __construct(public bool $translated = false) | ||
{ | ||
parent::__construct(type: self::TYPE, translated: $this->translated, api: true); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Core/Framework/DataAbstractionLayer/Attribute/Entity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
class Entity | ||
{ | ||
/** | ||
* @var class-string | ||
*/ | ||
public string $class; | ||
|
||
public function __construct(public string $name, public ?string $parent = null) | ||
{ | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Core/Framework/DataAbstractionLayer/Attribute/Field.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Field | ||
{ | ||
public bool $nullable; | ||
|
||
/** | ||
* @param bool|array{admin-api: bool, store-api: bool} $api | ||
*/ | ||
public function __construct( | ||
public string $type, | ||
public bool $translated = false, | ||
public bool|array $api = false | ||
) { | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Core/Framework/DataAbstractionLayer/Attribute/FieldType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
enum FieldType: string | ||
{ | ||
public const STRING = 'string'; | ||
public const TEXT = 'text'; | ||
public const INT = 'int'; | ||
public const FLOAT = 'float'; | ||
public const BOOL = 'bool'; | ||
public const DATETIME = 'datetime'; | ||
public const UUID = 'uuid'; | ||
public const AUTO_INCREMENT = 'auto-increment'; | ||
public const JSON = 'json'; | ||
public const DATE = 'date'; | ||
public const DATE_INTERVAL = 'date-interval'; | ||
public const TIME_ZONE = 'time-zone'; | ||
|
||
public const EMAIL = 'email'; | ||
public const LIST = 'list'; | ||
public const PASSWORD = 'password'; | ||
public const REMOTE_ADDRESS = 'remote-address'; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Core/Framework/DataAbstractionLayer/Attribute/ForeignKey.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class ForeignKey extends Field | ||
{ | ||
public const TYPE = 'fk'; | ||
|
||
public bool $nullable; | ||
|
||
public function __construct(public string $entity, public bool|array $api = false) | ||
{ | ||
parent::__construct(type: self::TYPE, api: $api); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Core/Framework/DataAbstractionLayer/Attribute/Inherited.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Inherited | ||
{ | ||
public function __construct(public bool $reversed = false) | ||
{ | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Core/Framework/DataAbstractionLayer/Attribute/ManyToMany.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class ManyToMany extends Field | ||
{ | ||
public const TYPE = 'many-to-many'; | ||
|
||
public function __construct( | ||
public string $entity, | ||
public OnDelete $onDelete = OnDelete::NO_ACTION, | ||
public bool|array $api = false | ||
) { | ||
parent::__construct(type: self::TYPE, api: $api); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Core/Framework/DataAbstractionLayer/Attribute/ManyToOne.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class ManyToOne extends Field | ||
{ | ||
public const TYPE = 'many-to-one'; | ||
|
||
public function __construct( | ||
public string $entity, | ||
public OnDelete $onDelete = OnDelete::NO_ACTION, | ||
public string $ref = 'id', | ||
public bool|array $api = false, | ||
) { | ||
parent::__construct(type: self::TYPE, api: $api); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Core/Framework/DataAbstractionLayer/Attribute/OnDelete.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
enum OnDelete: string | ||
{ | ||
case CASCADE = 'CASCADE'; | ||
case SET_NULL = 'SET NULL'; | ||
case RESTRICT = 'RESTRICT'; | ||
case NO_ACTION = 'NO ACTION'; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Core/Framework/DataAbstractionLayer/Attribute/OneToMany.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class OneToMany extends Field | ||
{ | ||
public const TYPE = 'one-to-many'; | ||
|
||
public function __construct( | ||
public string $entity, | ||
public string $ref, | ||
public OnDelete $onDelete = OnDelete::NO_ACTION, | ||
public bool|array $api = false | ||
) { | ||
parent::__construct(type: self::TYPE, api: $api); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Core/Framework/DataAbstractionLayer/Attribute/OneToOne.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class OneToOne extends Field | ||
{ | ||
public const TYPE = 'one-to-one'; | ||
|
||
public function __construct( | ||
public string $entity, | ||
public ?string $column = null, | ||
public OnDelete $onDelete = OnDelete::NO_ACTION, | ||
public string $ref = 'id', | ||
public bool|array $api = false | ||
) { | ||
parent::__construct(type: self::TYPE, api: $api); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Core/Framework/DataAbstractionLayer/Attribute/PrimaryKey.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class PrimaryKey | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Core/Framework/DataAbstractionLayer/Attribute/Protection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
use Shopware\Core\Framework\Context; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Protection | ||
{ | ||
final public const SYSTEM_SCOPE = Context::SYSTEM_SCOPE; | ||
final public const USER_SCOPE = Context::USER_SCOPE; | ||
final public const CRUD_API_SCOPE = Context::CRUD_API_SCOPE; | ||
|
||
public function __construct(public array $write) | ||
{ | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Core/Framework/DataAbstractionLayer/Attribute/ReferenceVersion.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class ReferenceVersion extends Field | ||
{ | ||
public const TYPE = 'reference-version'; | ||
|
||
public function __construct(public string $entity) | ||
{ | ||
parent::__construct(type: self::TYPE, api: true); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Core/Framework/DataAbstractionLayer/Attribute/Required.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Required | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Core/Framework/DataAbstractionLayer/Attribute/Serialized.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\StringFieldSerializer; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Serialized extends Field | ||
{ | ||
public const TYPE = 'serialized'; | ||
|
||
public function __construct( | ||
public string $serializer = StringFieldSerializer::class, | ||
public bool|array $api = false | ||
) { | ||
parent::__construct(type: self::TYPE, api: $api); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Core/Framework/DataAbstractionLayer/Attribute/Translations.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Translations extends Field | ||
{ | ||
public const TYPE = 'translations'; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(type: self::TYPE, api: true); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Core/Framework/DataAbstractionLayer/Attribute/Version.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Version extends Field | ||
{ | ||
public const TYPE = 'version'; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(type: self::TYPE, api: true); | ||
} | ||
} |
Oops, something went wrong.