-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPortalStyle.php
55 lines (45 loc) · 1.38 KB
/
PortalStyle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Routelandia\Data\Styles;
use Respect\Data\Styles\Standard;
/**
* PortalStyle is a Respect/Relational database style that helps the object mapper (Respect/Relational) to understand how the
* database columns are named and how to infer primary/foreign keys and such.
* This style is intended to work with the Portal database, as accessed by the routelandia-server project.
*
* NOTE:
* This style was copied from the NorthWind style that comes with Respect/Relational and modified to work.
*/
class PortalStyle extends Standard
{
public function realName($name)
{
return $this->pluralToSingular($name);
}
public function styledName($name)
{
return $this->pluralToSingular($name);
}
public function composed($left, $right)
{
$left = $this->pluralToSingular($left);
return "{$left}{$right}";
}
public function identifier($name)
{
return $this->pluralToSingular($name) . 'id';
}
public function remoteIdentifier($name)
{
return $this->pluralToSingular($name) . 'id';
}
public function isRemoteIdentifier($name)
{
return (strlen($name) - 2 === strripos($name, 'id'));
}
public function remoteFromIdentifier($name)
{
if ($this->isRemoteIdentifier($name)) {
return $this->singularToPlural(substr($name, 0, -2));
}
}
}