From 2e8392156067c128dea0620dc6a22d7b3f485d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Ho=C5=A1na?= Date: Fri, 9 Feb 2018 14:57:25 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Example=20Entity=20=E2=80=98ItemType?= =?UTF-8?q?=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Entity/ItemType.php | 192 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 src/Entity/ItemType.php diff --git a/src/Entity/ItemType.php b/src/Entity/ItemType.php new file mode 100644 index 0000000..0822b5e --- /dev/null +++ b/src/Entity/ItemType.php @@ -0,0 +1,192 @@ +commonName = $commonName; + $this->id = Uuid::uuid4(); + } + + /** + * @return string + */ + public function getCommonName(): string + { + return $this->commonName; + } + + /** + * @param string $commonName + */ + public function setCommonName(string $commonName): void + { + $this->commonName = $commonName; + } + + /** + * @return null|string + */ + public function getOfficialName(): ?string + { + return $this->officialName; + } + + /** + * @param null|string $officialName + */ + public function setOfficialName(?string $officialName): void + { + $this->officialName = $officialName; + } + + /** + * @return int|null + */ + public function getBasicRentalPrice(): ?int + { + return $this->basicRentalPrice; + } + + /** + * @param int|null $basicRentalPrice + */ + public function setBasicRentalPrice(?int $basicRentalPrice): void + { + $this->basicRentalPrice = $basicRentalPrice; + } + + /** + * @return null|string + */ + public function getProductPageUrl(): ?string + { + return $this->productPageUrl; + } + + /** + * @param null|string $productPageUrl + */ + public function setProductPageUrl(?string $productPageUrl): void + { + $this->productPageUrl = $productPageUrl; + } + + /** + * @return null|string + */ + public function getAvatar(): ?string + { + return $this->avatar; + } + + /** + * @param null|string $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; + } + + /** + * @return int|null + */ + public function getWeight(): ?int + { + return $this->weight; + } + + /** + * @param int|null $weight + */ + public function setWeight(?int $weight): void + { + $this->weight = $weight; + } + +} From 5e8141b3f669f804b73b32709323875919ea23b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Ho=C5=A1na?= Date: Fri, 9 Feb 2018 23:45:36 +0100 Subject: [PATCH 2/4] CS Fix - example --- src/Entity/ItemType.php | 320 ++++++++++++++++++---------------------- 1 file changed, 141 insertions(+), 179 deletions(-) diff --git a/src/Entity/ItemType.php b/src/Entity/ItemType.php index 0822b5e..5b832bf 100644 --- a/src/Entity/ItemType.php +++ b/src/Entity/ItemType.php @@ -1,5 +1,4 @@ -commonName = $commonName; - $this->id = Uuid::uuid4(); - } - - /** - * @return string - */ - public function getCommonName(): string - { - return $this->commonName; - } - - /** - * @param string $commonName - */ - public function setCommonName(string $commonName): void - { - $this->commonName = $commonName; - } - - /** - * @return null|string - */ - public function getOfficialName(): ?string - { - return $this->officialName; - } - - /** - * @param null|string $officialName - */ - public function setOfficialName(?string $officialName): void - { - $this->officialName = $officialName; - } - - /** - * @return int|null - */ - public function getBasicRentalPrice(): ?int - { - return $this->basicRentalPrice; - } - - /** - * @param int|null $basicRentalPrice - */ - public function setBasicRentalPrice(?int $basicRentalPrice): void - { - $this->basicRentalPrice = $basicRentalPrice; - } - - /** - * @return null|string - */ - public function getProductPageUrl(): ?string - { - return $this->productPageUrl; - } - - /** - * @param null|string $productPageUrl - */ - public function setProductPageUrl(?string $productPageUrl): void - { - $this->productPageUrl = $productPageUrl; - } - - /** - * @return null|string - */ - public function getAvatar(): ?string - { - return $this->avatar; - } - - /** - * @param null|string $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; - } - - /** - * @return int|null - */ - public function getWeight(): ?int - { - return $this->weight; - } - - /** - * @param int|null $weight - */ - public function setWeight(?int $weight): void - { - $this->weight = $weight; - } - + /** + * @var UuidInterface + * + * @ORM\Id + * @ORM\Column(type="Uuid", 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; + } } From a17951a774dc591ce8ccd3a30bd364770ff00366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Ho=C5=A1na?= Date: Fri, 23 Feb 2018 17:20:32 +0100 Subject: [PATCH 3/4] Instal UUID generator --- composer.json | 1 + composer.lock | 130 +++++++++++++++++++++++++++++++++++++++++++++++++- symfony.lock | 6 +++ 3 files changed, 136 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b65f8a8..344f97e 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 4d5c7f4..2fa81a4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "6ddfd2d9adacc6e6d8b6e715d904c7ab", + "content-hash": "e5302db1e14db935b39e1b6d45d2f761", "packages": [ { "name": "doctrine/annotations", @@ -1092,6 +1092,54 @@ ], "time": "2017-05-04T11:12:50+00:00" }, + { + "name": "paragonie/random_compat", + "version": "v2.0.11", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/5da4d3c796c275c55f057af5a643ae297d96b4d8", + "reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "autoload": { + "files": [ + "lib/random.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "pseudorandom", + "random" + ], + "time": "2017-09-27T21:40:39+00:00" + }, { "name": "psr/cache", "version": "1.0.1", @@ -1282,6 +1330,86 @@ ], "time": "2017-01-02T13:31:39+00:00" }, + { + "name": "ramsey/uuid", + "version": "3.7.3", + "source": { + "type": "git", + "url": "https://github.com/ramsey/uuid.git", + "reference": "44abcdad877d9a46685a3a4d221e3b2c4b87cb76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/44abcdad877d9a46685a3a4d221e3b2c4b87cb76", + "reference": "44abcdad877d9a46685a3a4d221e3b2c4b87cb76", + "shasum": "" + }, + "require": { + "paragonie/random_compat": "^1.0|^2.0", + "php": "^5.4 || ^7.0" + }, + "replace": { + "rhumsaa/uuid": "self.version" + }, + "require-dev": { + "codeception/aspect-mock": "^1.0 | ~2.0.0", + "doctrine/annotations": "~1.2.0", + "goaop/framework": "1.0.0-alpha.2 | ^1.0 | ^2.1", + "ircmaxell/random-lib": "^1.1", + "jakub-onderka/php-parallel-lint": "^0.9.0", + "mockery/mockery": "^0.9.9", + "moontoast/math": "^1.1", + "php-mock/php-mock-phpunit": "^0.3|^1.1", + "phpunit/phpunit": "^4.7|^5.0", + "squizlabs/php_codesniffer": "^2.3" + }, + "suggest": { + "ext-libsodium": "Provides the PECL libsodium extension for use with the SodiumRandomGenerator", + "ext-uuid": "Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator", + "ircmaxell/random-lib": "Provides RandomLib for use with the RandomLibAdapter", + "moontoast/math": "Provides support for converting UUID to 128-bit integer (in string form).", + "ramsey/uuid-console": "A console application for generating UUIDs with ramsey/uuid", + "ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Ramsey\\Uuid\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marijn Huizendveld", + "email": "marijn.huizendveld@gmail.com" + }, + { + "name": "Thibaud Fabre", + "email": "thibaud@aztech.io" + }, + { + "name": "Ben Ramsey", + "email": "ben@benramsey.com", + "homepage": "https://benramsey.com" + } + ], + "description": "Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID).", + "homepage": "https://github.com/ramsey/uuid", + "keywords": [ + "guid", + "identifier", + "uuid" + ], + "time": "2018-01-20T00:28:24+00:00" + }, { "name": "symfony/cache", "version": "v4.0.3", diff --git a/symfony.lock b/symfony.lock index 5dc50b3..eb6887d 100644 --- a/symfony.lock +++ b/symfony.lock @@ -65,6 +65,9 @@ "ocramius/proxy-manager": { "version": "2.1.1" }, + "paragonie/random_compat": { + "version": "v2.0.11" + }, "psr/cache": { "version": "1.0.1" }, @@ -77,6 +80,9 @@ "psr/simple-cache": { "version": "1.0.0" }, + "ramsey/uuid": { + "version": "3.7.3" + }, "symfony/cache": { "version": "v4.0.3" }, From be64e844d9898431d66906957c4ccc91b01a8e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Ho=C5=A1na?= Date: Fri, 23 Feb 2018 17:20:47 +0100 Subject: [PATCH 4/4] Migration and proper doctrine type --- src/Entity/ItemType.php | 2 +- src/Migrations/Version20180223161324.php | 30 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/Migrations/Version20180223161324.php diff --git a/src/Entity/ItemType.php b/src/Entity/ItemType.php index 5b832bf..c816993 100644 --- a/src/Entity/ItemType.php +++ b/src/Entity/ItemType.php @@ -15,7 +15,7 @@ class ItemType * @var UuidInterface * * @ORM\Id - * @ORM\Column(type="Uuid", unique=true) + * @ORM\Column(type="guid", unique=true) */ protected $id; diff --git a/src/Migrations/Version20180223161324.php b/src/Migrations/Version20180223161324.php new file mode 100644 index 0000000..6ba7b53 --- /dev/null +++ b/src/Migrations/Version20180223161324.php @@ -0,0 +1,30 @@ +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'); + } +}