Skip to content

Commit fa91649

Browse files
pref: trait getter and setter convert class
1 parent f7d71a5 commit fa91649

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/api/category/Category.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
namespace RestJS\Api\Category;
44

55
use Doctrine\ORM\Mapping as ORM;
6-
use RestJS\Trait\GetterAndSetter;
6+
use RestJS\Class\GetterAndSetter;
77

88
#[ORM\Entity]
99
#[ORM\Table('category')]
10-
class Category {
11-
12-
// Trait Getter and Setter
13-
use GetterAndSetter;
10+
class Category extends GetterAndSetter {
1411

1512
#[ORM\Id]
1613
#[ORM\Column, ORM\GeneratedValue]

src/api/user/User.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
use Doctrine\ORM\Mapping as ORM;
66
use Doctrine\ORM\Event as Event;
77
use Firebase\JWT\JWT;
8-
use RestJS\Trait\GetterAndSetter;
8+
use RestJS\Class\GetterAndSetter;
99

1010
#[ORM\Entity]
1111
#[ORM\Table('user')]
1212
#[ORM\HasLifecycleCallbacks]
13-
class User {
14-
15-
// Trait Getter and Setter
16-
use GetterAndSetter;
13+
class User extends GetterAndSetter {
1714

1815
#[ORM\Id]
1916
#[ORM\Column, ORM\GeneratedValue]
@@ -26,7 +23,7 @@ class User {
2623
public string $username;
2724

2825
#[ORM\Column]
29-
private string $password;
26+
protected string $password;
3027

3128
#[ORM\Column(nullable: true)]
3229
public string $image;

src/class/getterandsetter.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
namespace RestJS\Class;
4+
5+
/** Getter and Setter Functions */
6+
class GetterAndSetter {
7+
8+
/** Get Value by Column */
9+
public function __get($key) {
10+
return $this->$key;
11+
}
12+
13+
/** Set Value by Column */
14+
public function __set($key, $value) {
15+
$this->$key = $value;
16+
}
17+
}

0 commit comments

Comments
 (0)