Skip to content

Commit

Permalink
Merge pull request #210 from cPintiuta/4.0
Browse files Browse the repository at this point in the history
doctrine mappings: annotations --> attrributes
  • Loading branch information
arhimede authored Nov 2, 2023
2 parents 46faf89 + 98f417f commit 2e5c0f1
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 193 deletions.
8 changes: 4 additions & 4 deletions config/autoload/doctrine.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

use Doctrine\Common\Cache\PhpFileCache;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType;
use Ramsey\Uuid\Doctrine\UuidBinaryType;
Expand All @@ -29,17 +29,17 @@
],
],
'AdminEntities' => [
'class' => AnnotationDriver::class,
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/../../src/Admin/src/Entity',
],
'UserEntities' => [
'class' => AnnotationDriver::class,
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/../../src/User/src/Entity',
],
'AppEntities' => [
'class' => AnnotationDriver::class,
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/../../src/App/src/Entity',
],
Expand Down
31 changes: 13 additions & 18 deletions src/Admin/src/Entity/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Api\Admin\Entity;

use Api\Admin\Repository\AdminRepository;
use Api\App\Entity\AbstractEntity;
use Api\App\Entity\PasswordTrait;
use Api\App\Entity\RoleInterface;
Expand All @@ -13,11 +14,9 @@
use Exception;
use League\OAuth2\Server\Entities\UserEntityInterface;

/**
* @ORM\Entity(repositoryClass="Api\Admin\Repository\AdminRepository")
* @ORM\Table(name="admin")
* @ORM\HasLifecycleCallbacks()
*/
#[ORM\Entity(repositoryClass: AdminRepository::class)]
#[ORM\Table("admin")]
#[ORM\HasLifecycleCallbacks]
class Admin extends AbstractEntity implements UserEntityInterface
{
use PasswordTrait;
Expand All @@ -29,29 +28,25 @@ class Admin extends AbstractEntity implements UserEntityInterface
self::STATUS_INACTIVE,
];

/** @ORM\Column(name="identity", type="string", length=100, unique=true) */
#[ORM\Column(name: "identity", type: "string", length: 100, unique: true)]
protected string $identity;

/** @ORM\Column(name="firstName", type="string", length=255) */
#[ORM\Column(name: "firstName", type: "string", length: 255)]
protected string $firstName;

/** @ORM\Column(name="lastName", type="string", length=255) */
#[ORM\Column(name: "lastName", type: "string", length: 255)]
protected string $lastName;

/** @ORM\Column(name="password", type="string", length=100) */
#[ORM\Column(name: "password", type: "string", length: 100)]
protected string $password;

/** @ORM\Column(name="status", type="string", length=20) */
#[ORM\Column(name: "status", type: "string", length: 20)]
protected string $status = self::STATUS_ACTIVE;

/**
* @ORM\ManyToMany(targetEntity="Api\Admin\Entity\AdminRole")
* @ORM\JoinTable(
* name="admin_roles",
* joinColumns={@ORM\JoinColumn(name="userUuid", referencedColumnName="uuid")},
* inverseJoinColumns={@ORM\JoinColumn(name="roleUuid", referencedColumnName="uuid")}
* )
*/
#[ORM\ManyToMany(targetEntity: AdminRole::class)]
#[ORM\JoinTable(name: "admin_roles")]
#[ORM\JoinColumn(name: "userUuid", referencedColumnName: "uuid")]
#[ORM\InverseJoinColumn(name: "roleUuid", referencedColumnName: "uuid")]
protected Collection $roles;

public function __construct()
Expand Down
11 changes: 5 additions & 6 deletions src/Admin/src/Entity/AdminRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

namespace Api\Admin\Entity;

use Api\Admin\Repository\AdminRoleRepository;
use Api\App\Entity\AbstractEntity;
use Api\App\Entity\RoleInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity(repositoryClass="Api\Admin\Repository\AdminRoleRepository")
* @ORM\Table(name="admin_role")
* @ORM\HasLifecycleCallbacks()
*/
#[ORM\Entity(repositoryClass: AdminRoleRepository::class)]
#[ORM\Table("admin_role")]
#[ORM\HasLifecycleCallbacks]
class AdminRole extends AbstractEntity implements RoleInterface
{
public const ROLE_ADMIN = 'admin';
Expand All @@ -22,7 +21,7 @@ class AdminRole extends AbstractEntity implements RoleInterface
self::ROLE_SUPERUSER,
];

/** @ORM\Column(name="name", type="string", length=30, unique=true) */
#[ORM\Column(name: "name", type: "string", length: 30, unique: true)]
protected string $name;

public function getName(): string
Expand Down
40 changes: 16 additions & 24 deletions src/App/src/Entity/OAuthAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Api\App\Entity;

use Api\App\Repository\OAuthAccessTokenRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
Expand All @@ -19,44 +20,35 @@
use League\OAuth2\Server\Entities\ScopeEntityInterface;
use RuntimeException;

/**
* @ORM\Entity(repositoryClass="Api\App\Repository\OAuthAccessTokenRepository")
* @ORM\Table(name="oauth_access_tokens")
*/
#[ORM\Entity(repositoryClass: OAuthAccessTokenRepository::class)]
#[ORM\Table(name: "oauth_access_tokens")]
class OAuthAccessToken implements AccessTokenEntityInterface
{
/**
* @ORM\Id()
* @ORM\Column(name="id", type="integer", options={"unsigned":true})
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Id]
#[ORM\Column(name: "id", type: "integer", options: ['unsigned' => true])]
#[ORM\GeneratedValue(strategy: "IDENTITY")]
private int $id;

/**
* @ORM\ManyToOne(targetEntity="Api\App\Entity\OAuthClient")
* @ORM\JoinColumn(name="client_id", referencedColumnName="id")
*/
#[ORM\ManyToOne(targetEntity: OAuthClient::class)]
#[ORM\JoinColumn(name: "client_id", referencedColumnName: "id")]
private ClientEntityInterface $client;

/** @ORM\Column(name="user_id", type="string", nullable=true) */
#[ORM\Column(name: "user_id", type: "string", nullable: true)]
private ?string $userId;

/** @ORM\Column(name="token", type="string", length=100) */
#[ORM\Column(name: "token", type: "string", length: 100)]
private string $token;

/** @ORM\Column(name="revoked", type="boolean", options={"default":0}) */
#[ORM\Column(name: "revoked", type: "boolean", options: ['default' => false])]
private bool $isRevoked = false;

/**
* @ORM\ManyToMany(targetEntity="Api\App\Entity\OAuthScope", inversedBy="accessTokens", indexBy="id")
* @ORM\JoinTable(name="oauth_access_token_scopes",
* joinColumns={@ORM\JoinColumn(name="access_token_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
* )
*/
#[ORM\ManyToMany(targetEntity: OAuthScope::class, inversedBy: "accessTokens", indexBy: "id")]
#[ORM\JoinTable(name: "oauth_access_token_scopes")]
#[ORM\JoinColumn(name: "access_token_id", referencedColumnName: "id")]
#[ORM\InverseJoinColumn(name: "scope_id", referencedColumnName: "id")]
protected Collection $scopes;

/** @ORM\Column(name="expires_at", type="datetime_immutable") */
#[ORM\Column(name: 'expires_at', type: "datetime_immutable")]
private DateTimeImmutable $expiresAt;

private ?CryptKey $privateKey = null;
Expand Down
36 changes: 14 additions & 22 deletions src/App/src/Entity/OAuthAuthCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Api\App\Entity;

use Api\App\Repository\OAuthAuthCodeRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
Expand All @@ -14,40 +15,31 @@
use League\OAuth2\Server\Entities\ScopeEntityInterface;
use League\OAuth2\Server\Entities\Traits\AuthCodeTrait;

/**
* @ORM\Entity(repositoryClass="Api\App\Repository\OAuthAuthCodeRepository")
* @ORM\Table(name="oauth_auth_codes")
*/
#[ORM\Entity(repositoryClass: OAuthAuthCodeRepository::class)]
#[ORM\Table(name: "oauth_auth_codes")]
class OAuthAuthCode implements AuthCodeEntityInterface
{
use AuthCodeTrait;

/**
* @ORM\Id()
* @ORM\Column(name="id", type="integer", options={"unsigned":true})
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Id]
#[ORM\Column(name: "id", type: "integer", options: ['unsigned' => true])]
#[ORM\GeneratedValue(strategy: "IDENTITY")]
private int $id;

/**
* @ORM\ManyToOne(targetEntity="Api\App\Entity\OAuthClient")
* @ORM\JoinColumn(name="client_id", referencedColumnName="id")
*/
#[ORM\ManyToOne(targetEntity: OAuthClient::class)]
#[ORM\JoinColumn(name: "client_id", referencedColumnName: "id")]
private ClientEntityInterface $client;

/** @ORM\Column(name="revoked", type="boolean", options={"default":0}) */
#[ORM\Column(name: "revoked", type: "boolean", options: ['default' => false])]
private bool $isRevoked = false;

/**
* @ORM\ManyToMany(targetEntity="Api\App\Entity\OAuthSCope", inversedBy="authCodes", indexBy="id")
* @ORM\JoinTable(name="oauth_auth_code_scopes",
* joinColumns={@ORM\JoinColumn(name="auth_code_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
* )
*/
#[ORM\ManyToMany(targetEntity: OAuthScope::class, inversedBy: "authCodes", indexBy: "id")]
#[ORM\JoinTable(name: "oauth_auth_code_scopes")]
#[ORM\JoinColumn(name: "auth_code_id", referencedColumnName: "id")]
#[ORM\InverseJoinColumn(name: "scope_id", referencedColumnName: "id")]
protected Collection $scopes;

/** @ORM\Column(type="datetime_immutable", nullable=true) */
#[ORM\Column(type: "datetime_immutable", nullable: true)]
private DateTimeImmutable $expiresDatetime;

public function __construct()
Expand Down
31 changes: 13 additions & 18 deletions src/App/src/Entity/OAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,40 @@

namespace Api\App\Entity;

use Api\App\Repository\OAuthClientRepository;
use Api\User\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use League\OAuth2\Server\Entities\ClientEntityInterface;

/**
* @ORM\Entity(repositoryClass="Api\App\Repository\OAuthClientRepository")
* @ORM\Table(name="oauth_clients")
*/
#[ORM\Entity(repositoryClass: OAuthClientRepository::class)]
#[ORM\Table(name: "oauth_clients")]
class OAuthClient implements ClientEntityInterface
{
public const NAME_ADMIN = 'admin';
public const NAME_FRONTEND = 'frontend';

/**
* @ORM\Id()
* @ORM\Column(name="id", type="integer", options={"unsigned":true})
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Id]
#[ORM\Column(name: "id", type: "integer", options: ['unsigned' => true])]
#[ORM\GeneratedValue(strategy: "IDENTITY")]
private int $id;

/**
* @ORM\ManyToOne(targetEntity="Api\User\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="uuid", nullable=true)
*/
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: "user_id", referencedColumnName: "uuid", nullable: true)]
private ?User $user = null;

/** @ORM\Column(name="name", type="string", length=40) */
#[ORM\Column(name: "name", type: "string", length: 40)]
private string $name = '';

/** @ORM\Column(name="secret", type="string", length=100, nullable=true) */
#[ORM\Column(name: "secret", type: "string", length: 100, nullable: true)]
private ?string $secret = null;

/** @ORM\Column(name="redirect", type="string", length=191) */
#[ORM\Column(name: "redirect", type: "string", length: 191)]
private string $redirect = '';

/** @ORM\Column(name="revoked", type="boolean", options={"default":0}) */
#[ORM\Column(name: "revoked", type: "boolean", options: ['default' => false])]
private bool $isRevoked = false;

/** @ORM\Column(name="isConfidential", type="boolean", options={"default":0}) */
#[ORM\Column(name: "isConfidential", type: "boolean", options: ['default' => false])]
private bool $isConfidential = false;

public function setId(int $id): self
Expand Down
25 changes: 10 additions & 15 deletions src/App/src/Entity/OAuthRefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,29 @@

namespace Api\App\Entity;

use Api\App\Repository\OAuthRefreshTokenRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;

/**
* @ORM\Entity(repositoryClass="Api\App\Repository\OAuthRefreshTokenRepository")
* @ORM\Table(name="oauth_refresh_tokens")
*/
#[ORM\Entity(repositoryClass: OAuthRefreshTokenRepository::class)]
#[ORM\Table(name: "oauth_refresh_tokens")]
class OAuthRefreshToken implements RefreshTokenEntityInterface
{
/**
* @ORM\Id()
* @ORM\Column(name="id", type="integer", options={"unsigned":true})
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Id]
#[ORM\Column(name: "id", type: "integer", options: ['unsigned' => true])]
#[ORM\GeneratedValue(strategy: "IDENTITY")]
private int $id;

/**
* @ORM\ManyToOne(targetEntity="Api\App\Entity\OAuthAccessToken")
* @ORM\JoinColumn(name="access_token_id", referencedColumnName="id")
*/
#[ORM\ManyToOne(targetEntity: OAuthAccessToken::class)]
#[ORM\JoinColumn(name: "access_token_id", referencedColumnName: "id")]
private AccessTokenEntityInterface $accessToken;

/** @ORM\Column(name="revoked", type="boolean", options={"default":0}) */
#[ORM\Column(name: "revoked", type: "boolean", options: ['default' => false])]
private bool $isRevoked = false;

/** @ORM\Column(name="expires_at", type="datetime_immutable") */
#[ORM\Column(name: "expires_at", type: "datetime_immutable")]
private DateTimeImmutable $expiresAt;

public function setId(int $id): self
Expand Down
21 changes: 9 additions & 12 deletions src/App/src/Entity/OAuthScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,32 @@

namespace Api\App\Entity;

use Api\App\Repository\OAuthScopeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use League\OAuth2\Server\Entities\ScopeEntityInterface;
use League\OAuth2\Server\Entities\Traits\ScopeTrait;

/**
* @ORM\Entity(repositoryClass="Api\App\Repository\OAuthScopeRepository")
* @ORM\Table(name="oauth_scopes")
*/
#[ORM\Entity(repositoryClass: OAuthScopeRepository::class)]
#[ORM\Table(name: "oauth_scopes")]
class OAuthScope implements ScopeEntityInterface
{
use ScopeTrait;

/**
* @ORM\Id()
* @ORM\Column(name="id", type="integer", options={"unsigned":true})
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Id]
#[ORM\Column(name: "id", type: "integer", options: ['unsigned' => true])]
#[ORM\GeneratedValue(strategy: "IDENTITY")]
private int $id;

/** @ORM\Column(name="scope", type="string", length=191) */
#[ORM\Column(name: "scope", type: "string", length: 191)]
private string $scope = '';

/** @ORM\ManyToMany(targetEntity="Api\App\Entity\OAuthAccessToken", mappedBy="scopes") */
#[ORM\ManyToMany(targetEntity: OAuthAccessToken::class, mappedBy: "scopes")]
protected Collection $accessTokens;

/** @ORM\ManyToMany(targetEntity="Api\App\Entity\OAuthAuthCode", mappedBy="scopes") */
#[ORM\ManyToMany(targetEntity: OAuthAuthCode::class, mappedBy: "scopes")]
protected Collection $authCodes;

public function __construct()
Expand Down
Loading

0 comments on commit 2e5c0f1

Please sign in to comment.