Skip to content

Commit

Permalink
Merge pull request #376 from loic425/feature/attributes-for-doctrine-…
Browse files Browse the repository at this point in the history
…mapping

Attributes for Doctrine mapping
  • Loading branch information
loic425 committed Dec 22, 2021
2 parents 22d08ab + 61aa63d commit 9b3b2aa
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 132 deletions.
2 changes: 1 addition & 1 deletion config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ doctrine:
mappings:
App:
is_bundle: false
type: annotation
type: attribute
dir: '%kernel.project_dir%/src/Monofony/Pack/CorePack/.recipe/src/Entity'
prefix: 'App\Entity'
alias: App
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ parameters:
# Test dependencies
- '**/spec/**.php'

# Grids
- '**/Grid/**.php'

# These packages aren't in require-dev of the global package
- '**MongoDB**'
- '**ODM**'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Entity\Customer;

use App\Entity\User\AppUser;
use Doctrine\ORM\Mapping as ORM;
use Monofony\Contracts\Core\Model\Customer\CustomerInterface;
use Monofony\Contracts\Core\Model\User\AppUserInterface;
Expand All @@ -12,15 +13,11 @@
use Symfony\Component\Validator\Constraints\Valid;
use Webmozart\Assert\Assert;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_customer")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_customer')]
class Customer extends BaseCustomer implements CustomerInterface
{
/**
* @ORM\OneToOne(targetEntity="App\Entity\User\AppUser", mappedBy="customer", cascade={"persist"})
*/
#[ORM\OneToOne(mappedBy: 'customer', targetEntity: AppUser::class, cascade: ['persist'])]
#[Valid]
private ?UserInterface $user = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

trait IdentifiableTrait
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected ?int $id = null;

public function getId(): ?int
Expand Down
16 changes: 4 additions & 12 deletions src/Monofony/Pack/CorePack/.recipe/src/Entity/Media/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,15 @@ abstract class File implements FileInterface, ResourceInterface

protected ?\SplFileInfo $file = null;

/**
* @ORM\Column(type="string")
*/
#[ORM\Column(type: 'string')]
#[Groups(groups: ['Default', 'Detailed'])]
protected ?string $path = null;

/**
* @ORM\Column(type="datetime")
*/
#[ORM\Column(type: 'datetime')]
protected \DateTimeInterface $createdAt;

/**
* @var \DateTimeInterface|null
*
* @ORM\Column(type="datetime", nullable=true)
*/
protected $updatedAt;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTimeInterface $updatedAt = null;

public function __construct()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,23 @@

namespace App\Entity\OAuth;

use App\Entity\User\AppUser;
use Doctrine\ORM\Mapping as ORM;
use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;

/**
* @ORM\Entity
* @ORM\Table(name="oauth_access_token")
*/
#[ORM\Entity]
#[ORM\Table(name: 'oauth_access_token')]
class AccessToken extends BaseAccessToken
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected $id;

/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
#[ORM\ManyToOne(targetEntity: Client::class)]
#[ORM\JoinColumn(nullable: false)]
protected $client;

/**
* @ORM\ManyToOne(targetEntity="App\Entity\User\AppUser")
*/
#[ORM\ManyToOne(targetEntity: AppUser::class)]
protected $user;
}
25 changes: 9 additions & 16 deletions src/Monofony/Pack/CorePack/.recipe/src/Entity/OAuth/AuthCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,23 @@

namespace App\Entity\OAuth;

use App\Entity\User\AppUser;
use Doctrine\ORM\Mapping as ORM;
use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode;

/**
* @ORM\Entity
* @ORM\Table(name="oauth_auth_code")
*/
#[ORM\Entity]
#[ORM\Table(name: 'oauth_auth_code')]
class AuthCode extends BaseAuthCode
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected $id;

/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
#[ORM\ManyToOne(targetEntity: Client::class)]
#[ORM\JoinColumn(nullable: false)]
protected $client;

/**
* @ORM\ManyToOne(targetEntity="App\Entity\User\AppUser")
*/
#[ORM\ManyToOne(targetEntity: AppUser::class)]
protected $user;
}
14 changes: 5 additions & 9 deletions src/Monofony/Pack/CorePack/.recipe/src/Entity/OAuth/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
use FOS\OAuthServerBundle\Entity\Client as BaseClient;
use FOS\OAuthServerBundle\Model\ClientInterface;

/**
* @ORM\Entity
* @ORM\Table(name="oauth_client")
*/
#[ORM\Entity]
#[ORM\Table(name: 'oauth_client')]
class Client extends BaseClient implements ClientInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected $id;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,23 @@

namespace App\Entity\OAuth;

use App\Entity\User\AppUser;
use Doctrine\ORM\Mapping as ORM;
use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken;

/**
* @ORM\Entity
* @ORM\Table(name="oauth_refresh_token")
*/
#[ORM\Entity]
#[ORM\Table(name: 'oauth_refresh_token')]
class RefreshToken extends BaseRefreshToken
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected $id;

/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
#[ORM\ManyToOne(targetEntity: Client::class)]
#[ORM\JoinColumn(nullable: false)]
protected $client;

/**
* @ORM\ManyToOne(targetEntity="App\Entity\User\AppUser")
*/
#[ORM\ManyToOne(targetEntity: AppUser::class)]
protected $user;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
use Vich\UploaderBundle\Mapping\Annotation as Vich;

/**
* @ORM\Entity
* @ORM\Table(name="app_admin_avatar")
*
* @Vich\Uploadable
*/
#[ORM\Entity]
#[ORM\Table(name: 'app_admin_avatar')]
class AdminAvatar extends File implements AdminAvatarInterface
{
/**
* {@inheritdoc}
*
* @Vich\UploadableField(mapping="admin_avatar", fileNameProperty="path")
*/
#[\Symfony\Component\Validator\Constraints\File(maxSize: '6000000', mimeTypes: ['image/*'])]
Expand Down
36 changes: 5 additions & 31 deletions src/Monofony/Pack/CorePack/.recipe/src/Entity/User/AdminUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,17 @@
use Monofony\Contracts\Core\Model\User\AdminUserInterface;
use Sylius\Component\User\Model\User as BaseUser;

/**
* @ORM\Entity
* @ORM\Table("sylius_admin_user")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_admin_user')]
class AdminUser extends BaseUser implements AdminUserInterface
{
/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: 'string', nullable: true)]
private ?string $lastName = null;

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

/**
* @ORM\OneToOne(targetEntity="App\Entity\User\AdminAvatar", cascade={"persist"})
*/
#[ORM\OneToOne(targetEntity: AdminAvatar::class, cascade: ['persist'])]
private ?AdminAvatarInterface $avatar = null;

public function __construct()
Expand All @@ -37,49 +29,31 @@ public function __construct()
$this->roles = [self::DEFAULT_ADMIN_ROLE];
}

/**
* {@inheritdoc}
*/
public function getLastName(): ?string
{
return $this->lastName;
}

/**
* {@inheritdoc}
*/
public function setLastName(?string $lastName): void
{
$this->lastName = $lastName;
}

/**
* {@inheritdoc}
*/
public function getFirstName(): ?string
{
return $this->firstName;
}

/**
* {@inheritdoc}
*/
public function setFirstName(?string $firstName): void
{
$this->firstName = $firstName;
}

/**
* {@inheritdoc}
*/
public function getAvatar(): ?AdminAvatarInterface
{
return $this->avatar;
}

/**
* {@inheritdoc}
*/
public function setAvatar(?AdminAvatarInterface $avatar): void
{
$this->avatar = $avatar;
Expand Down
18 changes: 4 additions & 14 deletions src/Monofony/Pack/CorePack/.recipe/src/Entity/User/AppUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,19 @@
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
use Sylius\Component\User\Model\User as BaseUser;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_app_user")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_app_user')]
class AppUser extends BaseUser implements AppUserInterface
{
/**
* @ORM\OneToOne(targetEntity="Sylius\Component\Customer\Model\CustomerInterface", inversedBy="user", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
#[ORM\OneToOne(inversedBy: 'user', targetEntity: CustomerInterface::class, cascade: ['persist'])]
#[ORM\JoinColumn(nullable: false)]
private ?CustomerInterface $customer = null;

/**
* {@inheritdoc}
*/
public function getCustomer(): ?CustomerInterface
{
return $this->customer;
}

/**
* {@inheritdoc}
*/
public function setCustomer($customer): void
{
$this->customer = $customer;
Expand Down

0 comments on commit 9b3b2aa

Please sign in to comment.