use Doctrine\ORM\Event\PreUpdateEventArgs;
/**
- * Resource
+ * Asset
*/
-class Resource {
+class Asset {
/**
- * @var int
+ * @var ?int
*/
private ?int $id;
/**
* Constructor
*
- * @param string $path The resource path
+ * @param ?string $path The asset path
*/
- public function __construct(private Album $album, private User $user, private string $path) {
+ public function __construct(private Album $album, private User $user, private ?string $path = null) {
$this->created = new \DateTime('now');
$this->updated = new \DateTime('now');
}
*
* @param \Rapsys\TreeBundle\Entity\Album $album
*
- * @return Resource
+ * @return Asset
*/
- public function setAlbum(Album $album): Resource {
+ public function setAlbum(Album $album): Asset {
$this->album = $album;
return $this;
*
* @param \Rapsys\TreeBundle\Entity\User $user
*
- * @return Resource
+ * @return Asset
*/
- public function setUser(User $user): Resource {
+ public function setUser(User $user): Asset {
$this->user = $user;
return $this;
/**
* Set path
*
- * @param string $path
+ * @param ?string $path
*
- * @return Resource
+ * @return Asset
*/
- public function setPath(string $path): Resource {
+ public function setPath(?string $path): Asset {
$this->path = $path;
return $this;
/**
* Get path
*
- * @return string
+ * @return ?string
*/
- public function getPath(): string {
+ public function getPath(): ?string {
return $this->path;
}
*
* @param \DateTime $created
*
- * @return Resource
+ * @return Asset
*/
- public function setCreated(\DateTime $created): Resource {
+ public function setCreated(\DateTime $created): Asset {
$this->created = $created;
return $this;
*
* @param \DateTime $updated
*
- * @return Resource
+ * @return Asset
*/
- public function setUpdated(\DateTime $updated): Resource {
+ public function setUpdated(\DateTime $updated): Asset {
$this->updated = $updated;
return $this;
/**
* {@inheritdoc}
*/
- public function preUpdate(PreUpdateEventArgs $eventArgs): ?Resource {
+ public function preUpdate(PreUpdateEventArgs $eventArgs): ?Asset {
//Check that we have an snippet instance
- if (($entity = $eventArgs->getEntity()) instanceof Resource) {
+ if (($entity = $eventArgs->getEntity()) instanceof Asset) {
//Set updated value
return $entity->setUpdated(new \DateTime('now'));
}
-Rapsys\TreeBundle\Entity\Resource:
+Rapsys\TreeBundle\Entity\Asset:
type: entity
- #repositoryClass: Rapsys\TreeBundle\Repository\ResourceRepository
- table: resources
+ #repositoryClass: Rapsys\TreeBundle\Repository\AssetRepository
+ table: assets
id:
id:
type: integer
manyToOne:
album:
targetEntity: Rapsys\TreeBundle\Entity\Album
- inversedBy: resources
+ inversedBy: assets
user:
targetEntity: Rapsys\TreeBundle\Entity\User
- inversedBy: resources
+ inversedBy: assets
+ uniqueConstraints:
+ album_user_path:
+ columns: [ album_id, user_id, path ]
lifecycleCallbacks:
preUpdate: ['preUpdate']