-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathField.php
More file actions
77 lines (64 loc) · 1.95 KB
/
Field.php
File metadata and controls
77 lines (64 loc) · 1.95 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\KlicktippPhpClient\Entities;
use Assert\Assert;
use D3\KlicktippPhpClient\Exceptions\CommunicationException;
use D3\KlicktippPhpClient\Exceptions\MissingEndpointException;
use D3\KlicktippPhpClient\Resources\Field as FieldEndpoint;
class Field extends Entity
{
private ?FieldEndpoint $endpoint;
public function __construct(array $elements = [], ?FieldEndpoint $endpoint = null)
{
$this->endpoint = $endpoint;
parent::__construct($elements);
}
private function getEndpoint(): FieldEndpoint
{
Assert::lazy()
->setExceptionClass(MissingEndpointException::class)
->that($this->endpoint)
->isInstanceOf(FieldEndpoint::class)
->verifyNow();
return $this->endpoint;
}
public function getId(): ?string
{
return $this->getStringOrNullValue($this->get(FieldEndpoint::ID));
}
public function getName(): ?string
{
return $this->getStringOrNullValue($this->get(FieldEndpoint::NAME));
}
public function setName(string $name): void
{
$this->set(FieldEndpoint::NAME, $name);
// use persist method to send to Klicktipp
}
/**
* @return null|bool
* @throws CommunicationException
* @throws MissingEndpointException
*/
public function persist(): ?bool
{
return !is_null($this->getId()) ?
$this->getEndpoint()->update(
$this->getId(),
$this->getName() ?? ''
) :
null;
}
}