Skip to content

Commit 0e6002f

Browse files
author
Francois Suter
committed
[FOLLOWUP] Added missing class
1 parent 15bc6b6 commit 0e6002f

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
namespace Cobweb\Linkhandler\Domain\Model;
3+
4+
/*
5+
* This file is part of the TYPO3 CMS project.
6+
*
7+
* It is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, either version 2
9+
* of the License, or any later version.
10+
*
11+
* For the full copyright and license information, please read the
12+
* LICENSE.txt file that was distributed with this source code.
13+
*
14+
* The TYPO3 project - inspiring people to share!
15+
*/
16+
17+
/**
18+
* Container for the parts of a linkhandler record reference.
19+
*
20+
* @todo: use that class in all possible places
21+
*
22+
* @package Cobweb\Linkhandler\Domain\Model
23+
*/
24+
class RecordLink {
25+
/**
26+
* @var string Name of the linkhandler configuration
27+
*/
28+
protected $configurationKey;
29+
30+
/**
31+
* @var string Name of the table being linked to
32+
*/
33+
protected $table;
34+
35+
/**
36+
* @var int Primary key of the record being linked to
37+
*/
38+
protected $id;
39+
40+
/**
41+
* @var string Full record reference in linkhandler syntax, i.e record:key:table:id
42+
*/
43+
protected $recordReference;
44+
45+
public function __construct($recordReference = null)
46+
{
47+
if ($recordReference !== null) {
48+
$this->setRecordReference($recordReference);
49+
}
50+
}
51+
52+
/**
53+
* @return string
54+
*/
55+
public function getConfigurationKey()
56+
{
57+
return $this->configurationKey;
58+
}
59+
60+
/**
61+
* @param string $configurationKey
62+
*/
63+
public function setConfigurationKey($configurationKey)
64+
{
65+
$this->configurationKey = $configurationKey;
66+
}
67+
68+
/**
69+
* @return string
70+
*/
71+
public function getTable()
72+
{
73+
return $this->table;
74+
}
75+
76+
/**
77+
* @param string $table
78+
*/
79+
public function setTable($table)
80+
{
81+
$this->table = $table;
82+
}
83+
84+
/**
85+
* @return int
86+
*/
87+
public function getId()
88+
{
89+
return $this->id;
90+
}
91+
92+
/**
93+
* @param int $id
94+
*/
95+
public function setId($id)
96+
{
97+
$this->id = $id;
98+
}
99+
100+
/**
101+
* @return string
102+
*/
103+
public function getRecordReference()
104+
{
105+
return $this->recordReference;
106+
}
107+
108+
/**
109+
* @param string $recordReference
110+
* @throws \InvalidArgumentException
111+
*/
112+
public function setRecordReference($recordReference)
113+
{
114+
if (empty($recordReference)) {
115+
throw new \InvalidArgumentException(
116+
'Record reference cannot be empty',
117+
1457367830
118+
);
119+
}
120+
$referenceParts = explode(':', $recordReference);
121+
if (count($referenceParts) === 4) {
122+
$this->recordReference = $recordReference;
123+
$this->configurationKey = $referenceParts[1];
124+
$this->table = $referenceParts[2];
125+
$this->id = (int)$referenceParts[3];
126+
} else {
127+
throw new \InvalidArgumentException(
128+
'Expected record reference structure is "record:key:table:id"',
129+
1457367830
130+
);
131+
}
132+
}
133+
134+
}

0 commit comments

Comments
 (0)