init
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
|
||||
|
||||
namespace MailPoet\Doctrine\EntityTraits;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
|
||||
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait AutoincrementedIdTrait {
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @var int|null
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/** @return int|null */
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/** @param int|null $id */
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
|
||||
|
||||
namespace MailPoet\Doctrine\EntityTraits;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
|
||||
use DateTimeInterface;
|
||||
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait CreatedAtTrait {
|
||||
/**
|
||||
* @ORM\Column(type="datetimetz", nullable=true)
|
||||
* @var DateTimeInterface|null
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
public function getCreatedAt(): ?DateTimeInterface {
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(DateTimeInterface $createdAt): void {
|
||||
$this->createdAt = $createdAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
|
||||
|
||||
namespace MailPoet\Doctrine\EntityTraits;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
|
||||
use DateTimeInterface;
|
||||
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait DeletedAtTrait {
|
||||
/**
|
||||
* @ORM\Column(type="datetimetz", nullable=true)
|
||||
* @var DateTimeInterface|null
|
||||
*/
|
||||
private $deletedAt;
|
||||
|
||||
/** @return DateTimeInterface|null */
|
||||
public function getDeletedAt() {
|
||||
return $this->deletedAt;
|
||||
}
|
||||
|
||||
/** @param DateTimeInterface|null $deletedAt */
|
||||
public function setDeletedAt($deletedAt) {
|
||||
$this->deletedAt = $deletedAt;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
|
||||
|
||||
namespace MailPoet\Doctrine\EntityTraits;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
|
||||
use MailPoetVendor\Doctrine\ORM\EntityNotFoundException;
|
||||
use MailPoetVendor\Doctrine\ORM\Proxy\Proxy;
|
||||
|
||||
trait SafeToOneAssociationLoadTrait {
|
||||
private function safelyLoadToOneAssociation(string $propertyName, $emptyValue = null) {
|
||||
if (!property_exists($this, $propertyName)) {
|
||||
throw new \InvalidArgumentException("Property '$propertyName' does not exist on class '" . get_class($this) . "'");
|
||||
}
|
||||
|
||||
if (!$this->$propertyName instanceof Proxy) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->$propertyName->__isInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if a proxy exists (= we have related entity ID), try to load it
|
||||
// to see if it is a valid ID referencing an existing entity
|
||||
try {
|
||||
$this->$propertyName->__load();
|
||||
} catch (EntityNotFoundException $e) {
|
||||
$this->$propertyName = $emptyValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
|
||||
|
||||
namespace MailPoet\Doctrine\EntityTraits;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
|
||||
use DateTimeInterface;
|
||||
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait UpdatedAtTrait {
|
||||
/**
|
||||
* @ORM\Column(type="datetimetz")
|
||||
* @var DateTimeInterface
|
||||
*/
|
||||
private $updatedAt;
|
||||
|
||||
/** @return DateTimeInterface */
|
||||
public function getUpdatedAt() {
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
public function setUpdatedAt(DateTimeInterface $updatedAt) {
|
||||
$this->updatedAt = $updatedAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Doctrine\EntityTraits;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
|
||||
trait ValidationGroupsTrait {
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
private $validationGroups;
|
||||
|
||||
public function getValidationGroups(): ?array {
|
||||
return $this->validationGroups;
|
||||
}
|
||||
|
||||
public function setValidationGroups(?array $validationGroups): void {
|
||||
$this->validationGroups = $validationGroups;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
Reference in New Issue
Block a user