Skip to content

Commit a97e7a9

Browse files
committed
Typed $fields array
1 parent 36fc3af commit a97e7a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+672
-326
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Performance [comparison of PHPFUI\ORM to Eloquent](https://github.com/phpfui/php
77

88
**PHPFUI\ORM** is not an attempt to write an abstraction around SQL as other ORMs do, rather it is a way to work with SQL that closely matches the semantics of SQL, with the power of PHP objects. It allows PHP to manipulate SQL queries without having to write SQL in plain text. This is very useful for queries generated via user interfaces where the user is given a lot of flexability in how a query is defined.
99

10+
### Version 2.0 requires updated Definition classes
11+
You will need to run the \PHPFUI\ORM\Tool\Generate\CRUD class against your database. See scripts/generateCRUD.php for an example.
12+
1013
## Features
1114
- **Active Records** A fully type checked object interface and implement basic CRUD functionality.
1215
- **Active Tables** Full table operations (select, update, insert and delete) including support for where, having, limits, ordering, grouping, joins and unions.

Tests/Fixtures/Definition/Alpha.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Alpha extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'alpha' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_alpha' => ['sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'alpha' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_alpha' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Alpha_numeric.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Alpha_numeric extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'alpha_numeric' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_alpha_numeric' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'alpha_numeric' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_alpha_numeric' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Card.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Card extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'card' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_card' => ['sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'card' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_card' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Color.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Color extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'color' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_color' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'color' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_color' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Comparison.php

+30-20
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,38 @@ abstract class Comparison extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'equal' => ['sqltype', 'string', 50, false, '', false, ],
11-
'not_equal' => ['sqltype', 'string', 50, false, '', false, ],
12-
'gt_field' => ['sqltype', 'string', 50, false, '', false, ],
13-
'gte_field' => ['sqltype', 'string', 50, false, '', false, ],
14-
'lt_field' => ['sqltype', 'string', 50, false, '', false, ],
15-
'lte_field' => ['sqltype', 'string', 50, false, '', false, ],
16-
'eq_field' => ['sqltype', 'string', 50, false, '', false, ],
17-
'neq_field' => ['sqltype', 'string', 50, false, '', false, ],
18-
'date' => ['date', 'string', 50, false, '', false, ],
19-
'not_equal' => ['sqltype', 'string', 50, false, '', false, ],
20-
'not_not_equal' => ['sqltype', 'string', 50, false, '', false, ],
21-
'not_gt_field' => ['sqltype', 'string', 50, false, '', false, ],
22-
'not_gte_field' => ['sqltype', 'string', 50, false, '', false, ],
23-
'not_lt_field' => ['sqltype', 'string', 50, false, '', false, ],
24-
'not_lte_field' => ['sqltype', 'string', 50, false, '', false, ],
25-
'not_eq_field' => ['sqltype', 'string', 50, false, '', false, ],
26-
'not_neq_field' => ['sqltype', 'string', 50, false, '', false, ],
27-
'not_date' => ['date', 'string', 50, false, '', false, ],
28-
];
9+
public static array $fields = [];
2910

3011
public static string $primaryKey = '';
3112

3213
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'equal' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
21+
'not_equal' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
22+
'gt_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
23+
'gte_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
24+
'lt_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
25+
'lte_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
26+
'eq_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
27+
'neq_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
28+
'date' => new \PHPFUI\ORM\FieldDefinition('date', 'string', 50, false, '', false, ),
29+
'not_equal' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
30+
'not_not_equal' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
31+
'not_gt_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
32+
'not_gte_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
33+
'not_lt_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
34+
'not_lte_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
35+
'not_eq_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
36+
'not_neq_field' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 50, false, '', false, ),
37+
'not_date' => new \PHPFUI\ORM\FieldDefinition('date', 'string', 50, false, '', false, ),
38+
];
39+
}
40+
41+
return $this;
42+
}
3343
}

Tests/Fixtures/Definition/Cvv.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Cvv extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'cvv' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_cvv' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'cvv' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_cvv' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Date.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Date extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'date' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_date' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'date' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_date' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/DateISO.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class DateISO extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'dateISO' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_dateISO' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'dateISO' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_dateISO' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Datetime.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Datetime extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'datetime' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_datetime' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'datetime' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_datetime' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Day_month_year.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Day_month_year extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'day_month_year' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_day_month_year' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'day_month_year' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_day_month_year' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Domain.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Domain extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'domain' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_domain' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'domain' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_domain' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Email.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Email extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'email' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_email' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'email' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_email' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

Tests/Fixtures/Definition/Enum.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ abstract class Enum extends \PHPFUI\ORM\Record
66
{
77
public static bool $autoIncrement = false;
88

9-
public static array $fields = [
10-
'enum' => ['sqltype', 'string', 19, false, '', false, ],
11-
'not_enum' => ['!sqltype', 'string', 19, false, '', false, ],
12-
];
9+
public static array $fields = [];
1310

1411
public static string $primaryKey = '';
1512

1613
public static string $table = '';
14+
15+
public function initFieldDefinitions() : static
16+
{
17+
if (! \count(static::$fields))
18+
{
19+
static::$fields = [
20+
'enum' => new \PHPFUI\ORM\FieldDefinition('sqltype', 'string', 19, false, '', false, ),
21+
'not_enum' => new \PHPFUI\ORM\FieldDefinition('!sqltype', 'string', 19, false, '', false, ),
22+
];
23+
}
24+
25+
return $this;
26+
}
1727
}

0 commit comments

Comments
 (0)