-
Notifications
You must be signed in to change notification settings - Fork 976
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a2e40f
commit 6c05c38
Showing
33 changed files
with
1,114 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Scripts\Examples; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Shopware\Core\Framework\Context; | ||
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; | ||
use Shopware\Core\Framework\Uuid\Uuid; | ||
|
||
require_once __DIR__ . '/examples/base-script.php'; | ||
|
||
$env = 'dev'; // by default, kernel gets booted in dev | ||
|
||
$kernel = require __DIR__ . '/boot/boot.php'; | ||
|
||
class Main extends BaseScript | ||
{ | ||
public function run() | ||
{ | ||
$this->getContainer()->get(Connection::class)->executeStatement( | ||
'DELETE FROM my_entity WHERE 1 = 1' | ||
); | ||
|
||
$definition = $this->getContainer()->get('my_entity.definition'); | ||
|
||
/** @var EntityRepository $repo */ | ||
$repo = $this->getContainer()->get('my_entity.repository'); | ||
|
||
$data = [ | ||
[ | ||
'id' => Uuid::randomHex(), | ||
'name' => 'foo', | ||
'number' => 'foo', | ||
'productId' => '018f7142ea7872f4a675f0eb497f190b', | ||
'followId' => '018f7142ea7872f4a675f0eb497f190b', | ||
'categories' => [ | ||
['id' => '018f71422f4472bfadf392a3eba2e34f'] | ||
], | ||
'subs' => [ | ||
[ | ||
'number' => 'foo' | ||
] | ||
] | ||
] | ||
]; | ||
|
||
$repo->upsert($data, Context::createCLIContext()); | ||
|
||
$criteria = new Criteria(); | ||
$criteria->addAssociation('categories'); | ||
$criteria->addAssociation('follow'); | ||
$criteria->addAssociation('product'); | ||
$criteria->addAssociation('subs'); | ||
$entities = $repo->search($criteria, Context::createCLIContext()); | ||
|
||
file_put_contents(__DIR__ . '/my_entity.json', json_encode($entities, JSON_PRETTY_PRINT)); | ||
} | ||
} | ||
|
||
|
||
(new Main($kernel))->run(); |
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
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 | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
class Entity | ||
{ | ||
/** | ||
* @var class-string | ||
*/ | ||
public string $class; | ||
|
||
public function __construct(public string $name) {} | ||
} | ||
|
||
|
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
<?php | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Field | ||
{ | ||
public bool $nullable; | ||
|
||
public function __construct( | ||
public string $type, | ||
public bool $translated = false, | ||
public bool|array $api = false | ||
) {} | ||
} |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
<?php | ||
|
||
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 PRICE = 'price'; | ||
public const UUID = 'uuid'; | ||
public const AUTO_INCREMENT = 'auto-increment'; | ||
public const CUSTOM_FIELDS = 'custom-fields'; | ||
|
||
public const SERIALIZED = 'serialized'; | ||
public const JSON = 'json'; | ||
public const DATE = 'date'; | ||
public const DATE_INTERVAL = 'date-interval'; | ||
public const EMAIL = 'email'; | ||
public const LIST = 'list'; | ||
public const PASSWORD = 'password'; | ||
public const REMOTE_ADDRESS = 'remote-address'; | ||
public const TIME_ZONE = 'time-zone'; | ||
} |
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 | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Fk 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); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
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,9 @@ | ||
<?php | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Inherited | ||
{ | ||
public function __construct(public bool $reversed = false) {} | ||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
<?php | ||
|
||
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 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 | ||
|
||
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 string $ref = 'id' , | ||
public bool|array $api = false | ||
) { | ||
parent::__construct(type: self::TYPE,api: $api); | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
<?php | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class OnDelete | ||
{ | ||
public const CASCADE = 'cascade'; | ||
public const SET_NULL = 'set-null'; | ||
public const RESTRICT = 'restrict'; | ||
|
||
public function __construct(public string $behavior) {} | ||
} |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
<?php | ||
|
||
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 bool|array $api = false | ||
) { | ||
parent::__construct(type: self::TYPE, api: $api); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
<?php | ||
|
||
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 string $ref = 'id', public bool|array $api = false | ||
) { | ||
parent::__construct(type: self::TYPE, api: $api); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Core/Framework/DataAbstractionLayer/Attribute/Primary.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,9 @@ | ||
<?php | ||
|
||
namespace Shopware\Core\Framework\DataAbstractionLayer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Primary | ||
{ | ||
public function __construct() {} | ||
} |
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
<?php | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
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.