From fbb14df39961c429a6cb802df5d432e52be36056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Thu, 11 Jul 2024 02:29:08 +0200 Subject: [PATCH] fix: update table scheme --- composer.json | 2 + composer.lock | 291 +++++++++++++++++- config/packages/security.yaml | 8 +- migrations/Version20240710222838.php | 44 --- migrations/Version20240711002439.php | 67 ++++ src/Entity/BookmarkDomainList.php | 74 +++++ src/Entity/Domain.php | 2 +- src/Entity/DomainEntity.php | 6 +- src/Entity/Event.php | 2 +- src/Entity/NameserverEntity.php | 8 +- src/Entity/User.php | 151 +++++++++ .../BookmarkDomainListRepository.php | 43 +++ src/Repository/UserRepository.php | 60 ++++ symfony.lock | 9 + 14 files changed, 711 insertions(+), 56 deletions(-) delete mode 100644 migrations/Version20240710222838.php create mode 100644 migrations/Version20240711002439.php create mode 100644 src/Entity/BookmarkDomainList.php create mode 100644 src/Entity/User.php create mode 100644 src/Repository/BookmarkDomainListRepository.php create mode 100644 src/Repository/UserRepository.php diff --git a/composer.json b/composer.json index ce36e79..1b979c9 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "doctrine/orm": "^3.2", "phpdocumentor/reflection-docblock": "^5.4", "phpstan/phpdoc-parser": "^1.29", + "spatie/icalendar-generator": "^2.8", "symfony/asset": "7.1.*", "symfony/asset-mapper": "7.1.*", "symfony/console": "7.1.*", @@ -38,6 +39,7 @@ "symfony/string": "7.1.*", "symfony/translation": "7.1.*", "symfony/twig-bundle": "7.1.*", + "symfony/uid": "7.1.*", "symfony/ux-turbo": "^2.18", "symfony/validator": "7.1.*", "symfony/web-link": "7.1.*", diff --git a/composer.lock b/composer.lock index 09bbc42..958f28c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6a69bab77db7d87183f93d182e22724e", + "content-hash": "2c9a601dd6b90ee988fc2c8205c79665", "packages": [ { "name": "composer/semver", @@ -2005,6 +2005,142 @@ }, "time": "2021-07-14T16:46:02+00:00" }, + { + "name": "spatie/enum", + "version": "3.13.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/enum.git", + "reference": "f1a0f464ba909491a53e60a955ce84ad7cd93a2c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/enum/zipball/f1a0f464ba909491a53e60a955ce84ad7cd93a2c", + "reference": "f1a0f464ba909491a53e60a955ce84ad7cd93a2c", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^8.0" + }, + "require-dev": { + "fakerphp/faker": "^1.9.1", + "larapack/dd": "^1.1", + "phpunit/phpunit": "^9.0", + "vimeo/psalm": "^4.3" + }, + "suggest": { + "fakerphp/faker": "To use the enum faker provider", + "phpunit/phpunit": "To use the enum assertions" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\Enum\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brent Roose", + "email": "brent@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Tom Witkowski", + "email": "dev@gummibeer.de", + "homepage": "https://gummibeer.de", + "role": "Developer" + } + ], + "description": "PHP Enums", + "homepage": "https://github.com/spatie/enum", + "keywords": [ + "enum", + "enumerable", + "spatie" + ], + "support": { + "docs": "https://docs.spatie.be/enum", + "issues": "https://github.com/spatie/enum/issues", + "source": "https://github.com/spatie/enum" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2022-04-22T08:51:55+00:00" + }, + { + "name": "spatie/icalendar-generator", + "version": "2.8.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/icalendar-generator.git", + "reference": "6cb8b9b9df72bbea25b302aabce680917739fdb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/icalendar-generator/zipball/6cb8b9b9df72bbea25b302aabce680917739fdb6", + "reference": "6cb8b9b9df72bbea25b302aabce680917739fdb6", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": "^8.1", + "spatie/enum": "^3.11" + }, + "require-dev": { + "ext-json": "*", + "larapack/dd": "^1.1", + "nesbot/carbon": "^3.5", + "pestphp/pest": "^2.34", + "spatie/pest-plugin-snapshots": "^2.1", + "vimeo/psalm": "^5.24" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\IcalendarGenerator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ruben Van Assche", + "email": "ruben@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Build calendars in the iCalendar format", + "homepage": "https://github.com/spatie/icalendar-generator", + "keywords": [ + "calendar", + "iCalendar", + "ical", + "ics", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/icalendar-generator/issues", + "source": "https://github.com/spatie/icalendar-generator/tree/2.8.1" + }, + "time": "2024-06-17T11:23:50+00:00" + }, { "name": "symfony/asset", "version": "v7.1.1", @@ -5261,6 +5397,85 @@ ], "time": "2024-06-19T12:35:24+00:00" }, + { + "name": "symfony/polyfill-uuid", + "version": "v1.30.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-uuid.git", + "reference": "2ba1f33797470debcda07fe9dce20a0003df18e9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/2ba1f33797470debcda07fe9dce20a0003df18e9", + "reference": "2ba1f33797470debcda07fe9dce20a0003df18e9", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-uuid": "*" + }, + "suggest": { + "ext-uuid": "For best performance" + }, + "type": "library", + "extra": { + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Uuid\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Grégoire Pineau", + "email": "lyrixx@lyrixx.info" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for uuid functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "uuid" + ], + "support": { + "source": "https://github.com/symfony/polyfill-uuid/tree/v1.30.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-31T15:07:36+00:00" + }, { "name": "symfony/process", "version": "v7.1.1", @@ -6835,6 +7050,80 @@ ], "time": "2024-05-31T14:59:31+00:00" }, + { + "name": "symfony/uid", + "version": "v7.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/uid.git", + "reference": "bb59febeecc81528ff672fad5dab7f06db8c8277" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/uid/zipball/bb59febeecc81528ff672fad5dab7f06db8c8277", + "reference": "bb59febeecc81528ff672fad5dab7f06db8c8277", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-uuid": "^1.15" + }, + "require-dev": { + "symfony/console": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Uid\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Grégoire Pineau", + "email": "lyrixx@lyrixx.info" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an object-oriented API to generate and represent UIDs", + "homepage": "https://symfony.com", + "keywords": [ + "UID", + "ulid", + "uuid" + ], + "support": { + "source": "https://github.com/symfony/uid/tree/v7.1.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-31T14:57:53+00:00" + }, { "name": "symfony/ux-turbo", "version": "v2.18.0", diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 367af25..fbfb8ed 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -4,14 +4,18 @@ security: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider providers: - users_in_memory: { memory: null } + # used to reload user from session & other features (e.g. switch_user) + app_user_provider: + entity: + class: App\Entity\User + property: email firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false main: lazy: true - provider: users_in_memory + provider: app_user_provider # activate different ways to authenticate # https://symfony.com/doc/current/security.html#the-firewall diff --git a/migrations/Version20240710222838.php b/migrations/Version20240710222838.php deleted file mode 100644 index 0da6526..0000000 --- a/migrations/Version20240710222838.php +++ /dev/null @@ -1,44 +0,0 @@ -addSql('CREATE TEMPORARY TABLE __temp__domain_entity AS SELECT domain_id, entity_id, roles FROM domain_entity'); - $this->addSql('DROP TABLE domain_entity'); - $this->addSql('CREATE TABLE domain_entity (domain_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:array) - , PRIMARY KEY(domain_id, entity_id), CONSTRAINT FK_614B48A1115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (ldhname) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_614B48A181257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE)'); - $this->addSql('INSERT INTO domain_entity (domain_id, entity_id, roles) SELECT domain_id, entity_id, roles FROM __temp__domain_entity'); - $this->addSql('DROP TABLE __temp__domain_entity'); - $this->addSql('CREATE INDEX IDX_614B48A181257D5D ON domain_entity (entity_id)'); - $this->addSql('CREATE INDEX IDX_614B48A1115F0EE5 ON domain_entity (domain_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TEMPORARY TABLE __temp__domain_entity AS SELECT domain_id, entity_id, roles FROM domain_entity'); - $this->addSql('DROP TABLE domain_entity'); - $this->addSql('CREATE TABLE domain_entity (domain_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles VARCHAR(255) NOT NULL, PRIMARY KEY(domain_id, entity_id), CONSTRAINT FK_614B48A1115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (ldhname) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_614B48A181257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); - $this->addSql('INSERT INTO domain_entity (domain_id, entity_id, roles) SELECT domain_id, entity_id, roles FROM __temp__domain_entity'); - $this->addSql('DROP TABLE __temp__domain_entity'); - $this->addSql('CREATE INDEX IDX_614B48A1115F0EE5 ON domain_entity (domain_id)'); - $this->addSql('CREATE INDEX IDX_614B48A181257D5D ON domain_entity (entity_id)'); - } -} diff --git a/migrations/Version20240711002439.php b/migrations/Version20240711002439.php new file mode 100644 index 0000000..77ef995 --- /dev/null +++ b/migrations/Version20240711002439.php @@ -0,0 +1,67 @@ +addSql('CREATE TABLE bookmark_domain_list (token VARCHAR(36) NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY(token), CONSTRAINT FK_F05EDCECA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_F05EDCECA76ED395 ON bookmark_domain_list (user_id)'); + $this->addSql('CREATE TABLE domain (ldhname VARCHAR(255) NOT NULL, handle VARCHAR(255) NOT NULL, status CLOB NOT NULL --(DC2Type:simple_array) + , whois_status VARCHAR(255) NOT NULL, PRIMARY KEY(ldhname))'); + $this->addSql('CREATE TABLE domain_entity (domain_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array) + , PRIMARY KEY(domain_id, entity_id), CONSTRAINT FK_614B48A1115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (ldhname) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_614B48A181257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_614B48A1115F0EE5 ON domain_entity (domain_id)'); + $this->addSql('CREATE INDEX IDX_614B48A181257D5D ON domain_entity (entity_id)'); + $this->addSql('CREATE TABLE entity (handle VARCHAR(255) NOT NULL, PRIMARY KEY(handle))'); + $this->addSql('CREATE TABLE event ("action" VARCHAR(255) NOT NULL, domain_id VARCHAR(255) NOT NULL, date DATE NOT NULL --(DC2Type:date_immutable) + , PRIMARY KEY("action", domain_id), CONSTRAINT FK_3BAE0AA7115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (ldhname) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_3BAE0AA7115F0EE5 ON event (domain_id)'); + $this->addSql('CREATE TABLE nameserver (handle VARCHAR(255) NOT NULL, ldhname VARCHAR(255) NOT NULL, status CLOB NOT NULL --(DC2Type:array) + , PRIMARY KEY(handle))'); + $this->addSql('CREATE TABLE nameserver_entity (nameserver_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array) + , status CLOB NOT NULL --(DC2Type:simple_array) + , PRIMARY KEY(nameserver_id, entity_id), CONSTRAINT FK_A269AFB41A555619 FOREIGN KEY (nameserver_id) REFERENCES nameserver (handle) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_A269AFB481257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE INDEX IDX_A269AFB41A555619 ON nameserver_entity (nameserver_id)'); + $this->addSql('CREATE INDEX IDX_A269AFB481257D5D ON nameserver_entity (entity_id)'); + $this->addSql('CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles CLOB NOT NULL --(DC2Type:json) + , password VARCHAR(255) NOT NULL)'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_EMAIL ON user (email)'); + $this->addSql('CREATE TABLE messenger_messages (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, body CLOB NOT NULL, headers CLOB NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at DATETIME NOT NULL --(DC2Type:datetime_immutable) + , available_at DATETIME NOT NULL --(DC2Type:datetime_immutable) + , delivered_at DATETIME DEFAULT NULL --(DC2Type:datetime_immutable) + )'); + $this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name)'); + $this->addSql('CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at)'); + $this->addSql('CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE bookmark_domain_list'); + $this->addSql('DROP TABLE domain'); + $this->addSql('DROP TABLE domain_entity'); + $this->addSql('DROP TABLE entity'); + $this->addSql('DROP TABLE event'); + $this->addSql('DROP TABLE nameserver'); + $this->addSql('DROP TABLE nameserver_entity'); + $this->addSql('DROP TABLE user'); + $this->addSql('DROP TABLE messenger_messages'); + } +} diff --git a/src/Entity/BookmarkDomainList.php b/src/Entity/BookmarkDomainList.php new file mode 100644 index 0000000..8f89247 --- /dev/null +++ b/src/Entity/BookmarkDomainList.php @@ -0,0 +1,74 @@ + + */ + #[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'ldhname')] + private Collection $domains; + + public function __construct() + { + $this->token = Uuid::v4(); + $this->domains = new ArrayCollection(); + } + + public function getToken(): ?string + { + return $this->token; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } + + /** + * @return Collection + */ + public function getDomains(): Collection + { + return $this->domains; + } + + public function addDomain(Domain $domain): static + { + if (!$this->domains->contains($domain)) { + $this->domains->add($domain); + } + + return $this; + } + + public function removeDomain(Domain $domain): static + { + $this->domains->removeElement($domain); + + return $this; + } +} diff --git a/src/Entity/Domain.php b/src/Entity/Domain.php index ae794fd..003858c 100644 --- a/src/Entity/Domain.php +++ b/src/Entity/Domain.php @@ -18,7 +18,7 @@ class Domain #[ORM\Column(length: 255)] private ?string $handle = null; - #[ORM\Column(type: Types::ARRAY)] + #[ORM\Column(type: Types::SIMPLE_ARRAY)] private array $status = []; /** diff --git a/src/Entity/DomainEntity.php b/src/Entity/DomainEntity.php index 499b0a7..fb2718a 100644 --- a/src/Entity/DomainEntity.php +++ b/src/Entity/DomainEntity.php @@ -11,15 +11,15 @@ class DomainEntity { #[ORM\Id] #[ORM\ManyToOne(inversedBy: 'domainEntities')] - #[ORM\JoinColumn(nullable: false, referencedColumnName: 'ldhname')] + #[ORM\JoinColumn(referencedColumnName: 'ldhname', nullable: false)] private ?Domain $domain = null; #[ORM\Id] #[ORM\ManyToOne(inversedBy: 'domainEntities')] - #[ORM\JoinColumn(nullable: false, referencedColumnName: 'handle')] + #[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)] private ?Entity $entity = null; - #[ORM\Column(type: Types::ARRAY)] + #[ORM\Column(type: Types::SIMPLE_ARRAY)] private array $roles = []; public function getDomain(): ?Domain diff --git a/src/Entity/Event.php b/src/Entity/Event.php index 13aa7b4..c641997 100644 --- a/src/Entity/Event.php +++ b/src/Entity/Event.php @@ -18,7 +18,7 @@ class Event #[ORM\Id] #[ORM\ManyToOne(inversedBy: 'events')] - #[ORM\JoinColumn(nullable: false, referencedColumnName: 'ldhname')] + #[ORM\JoinColumn(referencedColumnName: 'ldhname', nullable: false)] private ?Domain $domain = null; public function getAction(): ?string diff --git a/src/Entity/NameserverEntity.php b/src/Entity/NameserverEntity.php index ccc6565..618358d 100644 --- a/src/Entity/NameserverEntity.php +++ b/src/Entity/NameserverEntity.php @@ -11,18 +11,18 @@ class NameserverEntity { #[ORM\Id] #[ORM\ManyToOne(inversedBy: 'nameserverEntities')] - #[ORM\JoinColumn(nullable: false, referencedColumnName: 'handle')] + #[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)] private ?Nameserver $nameserver = null; #[ORM\Id] #[ORM\ManyToOne(inversedBy: 'nameserverEntities')] - #[ORM\JoinColumn(nullable: false, referencedColumnName: 'handle')] + #[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)] private ?Entity $entity = null; - #[ORM\Column(type: Types::ARRAY)] + #[ORM\Column(type: Types::SIMPLE_ARRAY)] private array $roles = []; - #[ORM\Column(type: Types::ARRAY)] + #[ORM\Column(type: Types::SIMPLE_ARRAY)] private array $status = []; public function getNameserver(): ?Nameserver diff --git a/src/Entity/User.php b/src/Entity/User.php new file mode 100644 index 0000000..3d343db --- /dev/null +++ b/src/Entity/User.php @@ -0,0 +1,151 @@ + The user roles + */ + #[ORM\Column] + private array $roles = []; + + /** + * @var string The hashed password + */ + #[ORM\Column] + private ?string $password = null; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: BookmarkDomainList::class, mappedBy: 'user', orphanRemoval: true)] + private Collection $bookmarkDomainLists; + + public function __construct() + { + $this->bookmarkDomainLists = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getEmail(): ?string + { + return $this->email; + } + + public function setEmail(string $email): static + { + $this->email = $email; + + return $this; + } + + /** + * A visual identifier that represents this user. + * + * @see UserInterface + */ + public function getUserIdentifier(): string + { + return (string) $this->email; + } + + /** + * @see UserInterface + * + * @return list + */ + public function getRoles(): array + { + $roles = $this->roles; + // guarantee every user at least has ROLE_USER + $roles[] = 'ROLE_USER'; + + return array_unique($roles); + } + + /** + * @param list $roles + */ + public function setRoles(array $roles): static + { + $this->roles = $roles; + + return $this; + } + + /** + * @see PasswordAuthenticatedUserInterface + */ + public function getPassword(): string + { + return $this->password; + } + + public function setPassword(string $password): static + { + $this->password = $password; + + return $this; + } + + /** + * @see UserInterface + */ + public function eraseCredentials(): void + { + // If you store any temporary, sensitive data on the user, clear it here + // $this->plainPassword = null; + } + + /** + * @return Collection + */ + public function getBookmarkDomainLists(): Collection + { + return $this->bookmarkDomainLists; + } + + public function addBookmarkDomainList(BookmarkDomainList $bookmarkDomainList): static + { + if (!$this->bookmarkDomainLists->contains($bookmarkDomainList)) { + $this->bookmarkDomainLists->add($bookmarkDomainList); + $bookmarkDomainList->setUser($this); + } + + return $this; + } + + public function removeBookmarkDomainList(BookmarkDomainList $bookmarkDomainList): static + { + if ($this->bookmarkDomainLists->removeElement($bookmarkDomainList)) { + // set the owning side to null (unless already changed) + if ($bookmarkDomainList->getUser() === $this) { + $bookmarkDomainList->setUser(null); + } + } + + return $this; + } +} diff --git a/src/Repository/BookmarkDomainListRepository.php b/src/Repository/BookmarkDomainListRepository.php new file mode 100644 index 0000000..0618368 --- /dev/null +++ b/src/Repository/BookmarkDomainListRepository.php @@ -0,0 +1,43 @@ + + */ +class BookmarkDomainListRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, BookmarkDomainList::class); + } + + // /** + // * @return BookmarkDomainList[] Returns an array of BookmarkDomainList objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('b') + // ->andWhere('b.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('b.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?BookmarkDomainList + // { + // return $this->createQueryBuilder('b') + // ->andWhere('b.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php new file mode 100644 index 0000000..4f2804e --- /dev/null +++ b/src/Repository/UserRepository.php @@ -0,0 +1,60 @@ + + */ +class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, User::class); + } + + /** + * Used to upgrade (rehash) the user's password automatically over time. + */ + public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void + { + if (!$user instanceof User) { + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class)); + } + + $user->setPassword($newHashedPassword); + $this->getEntityManager()->persist($user); + $this->getEntityManager()->flush(); + } + + // /** + // * @return User[] Returns an array of User objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('u') + // ->andWhere('u.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('u.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?User + // { + // return $this->createQueryBuilder('u') + // ->andWhere('u.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/symfony.lock b/symfony.lock index c3b74f1..2afeabc 100644 --- a/symfony.lock +++ b/symfony.lock @@ -248,6 +248,15 @@ "templates/base.html.twig" ] }, + "symfony/uid": { + "version": "7.1", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "7.0", + "ref": "0df5844274d871b37fc3816c57a768ffc60a43a5" + } + }, "symfony/ux-turbo": { "version": "v2.18.0" },