File tree 3 files changed +21
-2
lines changed
3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Composite \Sync \Attributes ;
4
4
5
- #[\Attribute(\Attribute::TARGET_PARAMETER | \Attribute::TARGET_PROPERTY )]
5
+ #[\Attribute(\Attribute::TARGET_PARAMETER | \Attribute::TARGET_PROPERTY | \Attribute:: TARGET_CLASS )]
6
6
class Column
7
7
{
8
8
public function __construct (
Original file line number Diff line number Diff line change 3
3
namespace Composite \Sync \Providers ;
4
4
5
5
use Composite \Entity \Columns \AbstractColumn ;
6
+ use Composite \Entity \Columns \CastableColumn ;
7
+ use Composite \Entity \Columns \EntityColumn ;
8
+ use Composite \Sync \Attributes \Column ;
6
9
7
10
abstract class AbstractSQLColumn
8
11
{
@@ -50,4 +53,20 @@ public function getColumnAttributeProperties(): array
50
53
}
51
54
return $ result ;
52
55
}
56
+
57
+ public static function getColumnAttribute (AbstractColumn $ entityColumn ): ?Column
58
+ {
59
+ if ($ attribute = $ entityColumn ->getFirstAttributeByClass (Column::class)) {
60
+ return $ attribute ;
61
+ }
62
+ $ columnIsClass = $ entityColumn instanceof CastableColumn || $ entityColumn instanceof EntityColumn;
63
+ if (!$ columnIsClass ) {
64
+ return null ;
65
+ }
66
+ $ reflection = new \ReflectionClass ($ entityColumn ->type );
67
+ foreach ($ reflection ->getAttributes (Column::class) as $ attribute ) {
68
+ return $ attribute ->newInstance ();
69
+ }
70
+ return null ;
71
+ }
53
72
}
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ public function __construct(
59
59
*/
60
60
public static function fromEntityColumn (AbstractColumn $ entityColumn ): self
61
61
{
62
- $ columnAttribute = $ entityColumn -> getFirstAttributeByClass (Column::class );
62
+ $ columnAttribute = self :: getColumnAttribute ( $ entityColumn );
63
63
$ primaryKeyAttribute = $ entityColumn ->getFirstAttributeByClass (PrimaryKey::class);
64
64
$ isAutoIncrement = $ primaryKeyAttribute ?->autoIncrement ?? false ;
65
65
$ type = $ columnAttribute ?->type ?
You can’t perform that action at this time.
0 commit comments