-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapper.php
More file actions
54 lines (41 loc) · 1.33 KB
/
Mapper.php
File metadata and controls
54 lines (41 loc) · 1.33 KB
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
class Mapper extends \LeanMapper\DefaultMapper
{
public function getTable(string $entityClass): string
{
return self::toUnderScore($this->trimNamespace($entityClass));
}
public function getEntityClass(string $table, LeanMapper\Row $row = null): string
{
return ($this->defaultEntityNamespace !== NULL ? $this->defaultEntityNamespace . '\\' : '')
. ucfirst(self::toCamelCase($table)); // Název třídy začíná velkým písmenem
}
public function getColumn(string $entityClass, string $field): string
{
return self::toUnderScore($field);
}
public function getEntityField(string $table, string $column): string
{
return self::toCamelCase($column);
}
public function getTableByRepositoryClass(string $repositoryClass): string
{
$matches = array();
if (preg_match('#([a-z0-9]+)repository$#i', $repositoryClass, $matches)) {
return self::toUnderScore($matches[1]);
}
throw new LeanMapper\Exception\InvalidStateException('Cannot determine table name.');
}
public static function toUnderScore(string $str): string
{
return lcfirst(preg_replace_callback('#(?<=.)([A-Z])#', function ($m) {
return '_' . strtolower($m[1]);
}, $str));
}
public static function toCamelCase(string $str): string
{
return preg_replace_callback('#_(.)#', function ($m) {
return strtoupper($m[1]);
}, $str);
}
}