Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Use attributes #1235

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions example/src/Entity/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,25 @@

use Doctrine\ORM;

/**
* @ORM\Mapping\Embeddable
*/
#[ORM\Mapping\Embeddable()]
final class Avatar
{
/**
* @ORM\Mapping\Column(
* name="url",
* type="string"
* )
*/
#[ORM\Mapping\Column(
name: 'url',
type: 'string',
)]
private string $url = '';

/**
* @ORM\Mapping\Column(
* name="width",
* type="integer"
* )
*/
#[ORM\Mapping\Column(
name: 'width',
type: 'integer',
)]
private int $width = 0;

/**
* @ORM\Mapping\Column(
* name="height",
* type="integer"
* )
*/
#[ORM\Mapping\Column(
name: 'height',
type: 'integer',
)]
private int $height = 0;

public function url(): string
Expand Down
46 changes: 18 additions & 28 deletions example/src/Entity/CodeOfConduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,32 @@

use Doctrine\ORM;

/**
* @ORM\Mapping\Entity
*
* @ORM\Mapping\Table(name="code_of_conduct")
*/
#[ORM\Mapping\Entity()]
#[ORM\Mapping\Table(name: 'code_of_conduct')]
class CodeOfConduct
{
/**
* @ORM\Mapping\Id
*
* @ORM\Mapping\Column(type="string")
*/
#[ORM\Mapping\Id()]
#[ORM\Mapping\Column(
type: 'string',
)]
private string $key;

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

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

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

public function __construct(
Expand Down
79 changes: 29 additions & 50 deletions example/src/Entity/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,68 +17,47 @@
use Doctrine\ORM;
use Ramsey\Uuid;

/**
* @ORM\Mapping\Entity
*
* @ORM\Mapping\Table(name="organization")
*/
#[ORM\Mapping\Entity()]
#[ORM\Mapping\Table(name: 'organization')]
class Organization
{
/**
* @ORM\Mapping\Id
*
* @ORM\Mapping\GeneratedValue(strategy="NONE")
*
* @ORM\Mapping\Column(
* type="string",
* length=36
* )
*/
#[ORM\Mapping\Id()]
#[ORM\Mapping\GeneratedValue(strategy: 'NONE')]
#[ORM\Mapping\Column(
type: 'string',
length: 36,
)]
private string $id;

/**
* @ORM\Mapping\Column(
* name="is_verified",
* type="boolean"
* )
*/
#[ORM\Mapping\Column(
name: 'is_verified',
type: 'boolean',
)]
private bool $isVerified = false;

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

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

/**
* @ORM\Mapping\OneToMany(
* targetEntity="Example\Entity\Repository",
* mappedBy="organization"
* )
*
* @var Common\Collections\Collection<int, Repository>
*/
#[ORM\Mapping\OneToMany(
targetEntity: 'Example\Entity\Repository',
mappedBy: 'organization',
)]
private Common\Collections\Collection $repositories;

/**
* @ORM\Mapping\ManyToMany(
* targetEntity="Example\Entity\User",
* inversedBy="organizations"
* )
*
* @var Common\Collections\Collection<int, User>
*/
#[ORM\Mapping\ManyToMany(
targetEntity: 'Example\Entity\User',
inversedBy: 'organizations',
)]
private Common\Collections\Collection $members;
private bool $constructorWasCalled = false;

Expand Down
48 changes: 18 additions & 30 deletions example/src/Entity/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,30 @@
use Doctrine\ORM;
use Ramsey\Uuid;

/**
* @ORM\Mapping\Entity
*
* @ORM\Mapping\Table(name="project")
*/
#[ORM\Mapping\Entity()]
#[ORM\Mapping\Table(name: 'project')]
class Project
{
/**
* @ORM\Mapping\Id
*
* @ORM\Mapping\GeneratedValue(strategy="NONE")
*
* @ORM\Mapping\Column(
* type="string",
* length=36
* )
*/
#[ORM\Mapping\Id()]
#[ORM\Mapping\GeneratedValue(strategy: 'NONE')]
#[ORM\Mapping\Column(
type: 'string',
length: 36,
)]
private string $id;

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

/**
* @ORM\Mapping\ManyToOne(targetEntity="Example\Entity\Repository")
*
* @ORM\Mapping\JoinColumn(
* name="repository_id",
* referencedColumnName="id",
* nullable=false
* )
*/
#[ORM\Mapping\ManyToOne(targetEntity: Repository::class)]
#[ORM\Mapping\JoinColumn(
name: 'repository_id',
referencedColumnName: 'id',
nullable: false,
)]
private Repository $repository;

public function __construct(
Expand Down
80 changes: 31 additions & 49 deletions example/src/Entity/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,47 @@
use Doctrine\ORM;
use Ramsey\Uuid;

/**
* @ORM\Mapping\Entity
*
* @ORM\Mapping\Table(name="repository")
*/
#[ORM\Mapping\Entity()]
#[ORM\Mapping\Table(name: 'repository')]
class Repository
{
/**
* @ORM\Mapping\Id
*
* @ORM\Mapping\GeneratedValue(strategy="NONE")
*
* @ORM\Mapping\Column(
* name="id",
* type="string"
* )
*/
#[ORM\Mapping\Id()]
#[ORM\Mapping\GeneratedValue(strategy: 'NONE')]
#[ORM\Mapping\Column(
name: 'id',
type: 'string',
)]
private string $id;

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

/**
* @ORM\Mapping\ManyToOne(
* targetEntity="Example\Entity\Organization",
* inversedBy="repositories"
* )
*
* @ORM\Mapping\JoinColumn(
* name="organization_id",
* referencedColumnName="id",
* nullable=false
* )
*/
#[ORM\Mapping\ManyToOne(
targetEntity: Organization::class,
inversedBy: 'repositories',
)]
#[ORM\Mapping\JoinColumn(
name: 'organization_id',
referencedColumnName: 'id',
nullable: false,
)]
private Organization $organization;

/**
* @ORM\Mapping\ManyToOne(targetEntity="Example\Entity\Repository")
*
* @ORM\Mapping\JoinColumn(
* name="template_id",
* referencedColumnName="id"
* )
*/
#[ORM\Mapping\ManyToOne(targetEntity: self::class)]
#[ORM\Mapping\JoinColumn(
name: 'template_id',
referencedColumnName: 'id',
)]
private ?Repository $template;

/**
* @ORM\Mapping\ManyToOne(targetEntity="Example\Entity\CodeOfConduct")
*
* @ORM\Mapping\JoinColumn(
* name="code_of_conduct_key",
* referencedColumnName="key"
* )
*/
#[ORM\Mapping\ManyToOne(targetEntity: CodeOfConduct::class)]
#[ORM\Mapping\JoinColumn(
name: 'code_of_conduct_key',
referencedColumnName: 'key',
)]
private ?CodeOfConduct $codeOfConduct;

public function __construct(
Expand Down
Loading
Loading