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

[DNM] Entity example #10

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"doctrine/dbal": "^2.6",
"doctrine/doctrine-bundle": "^1.8",
"doctrine/orm": "^2.6",
"ramsey/uuid": "^3.7",
"symfony/console": "^4.0",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.0",
Expand Down
130 changes: 129 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 154 additions & 0 deletions src/Entity/ItemType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php declare(strict_types = 1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

/**
* @ORM\Entity
*/
class ItemType
{
/**
* @var UuidInterface
*
* @ORM\Id
* @ORM\Column(type="guid", unique=true)
*/
protected $id;

/**
* @var string
* @ORM\Column(type="string", length=255)
*/
protected $commonName;

/**
* @var string|null
* @ORM\Column(type="string", length=1023, nullable=true)
*/
protected $officialName;

/**
* @var int|null
* @ORM\Column(type="integer", nullable=true)
*/
protected $basicRentalPrice;

/**
* @var string|null
* @ORM\Column(type="string", nullable=true)
*/
protected $productPageUrl;

/**
* @var string|null
* @TODO How to handle files
* @ORM\Column(type="string", nullable=true)
*/
protected $avatar;

/**
* @var string[]
* @TODO How to handle files
* @ORM\Column(type="json_array", nullable=true)
*/
protected $attachments;

/**
* Weight in grams.
*
* @var int|null
* @ORM\Column(type="integer", nullable=true)
*/
protected $weight;

/**
* ItemType constructor.
*
* @param string $commonName
*/
public function __construct(string $commonName)
{
$this->commonName = $commonName;
$this->id = Uuid::uuid4();
}

public function getCommonName(): string
{
return $this->commonName;
}

public function setCommonName(string $commonName): void
{
$this->commonName = $commonName;
}

public function getOfficialName(): ?string
{
return $this->officialName;
}

public function setOfficialName(?string $officialName): void
{
$this->officialName = $officialName;
}

public function getBasicRentalPrice(): ?int
{
return $this->basicRentalPrice;
}

public function setBasicRentalPrice(?int $basicRentalPrice): void
{
$this->basicRentalPrice = $basicRentalPrice;
}

public function getProductPageUrl(): ?string
{
return $this->productPageUrl;
}

public function setProductPageUrl(?string $productPageUrl): void
{
$this->productPageUrl = $productPageUrl;
}

public function getAvatar(): ?string
{
return $this->avatar;
}

public function setAvatar(?string $avatar): void
{
$this->avatar = $avatar;
}

/**
* @return string[]
*/
public function getAttachments(): array
{
return $this->attachments;
}

/**
* @param string[] $attachments
*/
public function setAttachments(array $attachments): void
{
$this->attachments = $attachments;
}

public function getWeight(): ?int
{
return $this->weight;
}

public function setWeight(?int $weight): void
{
$this->weight = $weight;
}
}
30 changes: 30 additions & 0 deletions src/Migrations/Version20180223161324.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types = 1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20180223161324 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE TABLE item_type (id UUID NOT NULL, common_name VARCHAR(255) NOT NULL, official_name VARCHAR(1023) DEFAULT NULL, basic_rental_price INT DEFAULT NULL, product_page_url VARCHAR(255) DEFAULT NULL, avatar VARCHAR(255) DEFAULT NULL, attachments JSON DEFAULT NULL, weight INT DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('COMMENT ON COLUMN item_type.attachments IS \'(DC2Type:json_array)\'');
}

public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('DROP TABLE item_type');
}
}
6 changes: 6 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
"ocramius/proxy-manager": {
"version": "2.1.1"
},
"paragonie/random_compat": {
"version": "v2.0.11"
},
"psr/cache": {
"version": "1.0.1"
},
Expand All @@ -77,6 +80,9 @@
"psr/simple-cache": {
"version": "1.0.0"
},
"ramsey/uuid": {
"version": "3.7.3"
},
"symfony/cache": {
"version": "v4.0.3"
},
Expand Down