Issues (113)

lib/Component/XMLBodyComponent.php (1 issue)

1
<?php
2
/**
3
 * The MIT License
4
 *
5
 * Copyright 2017 Julien Fastré <[email protected]>.
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25
26
namespace i3Soft\CDA\Component;
27
28
use i3Soft\CDA\Interfaces\ClassCodeInterface;
29
use i3Soft\CDA\Interfaces\MoodCodeInterface;
30
use i3Soft\CDA\Traits\ClassCodeTrait;
31
use i3Soft\CDA\Traits\MoodCodeTrait;
32
use i3Soft\CDA\Traits\SingleComponentTrait;
33
34
/**
35
 * @author Julien Fastré <[email protected]>
36
 */
37
class XMLBodyComponent extends AbstractComponent implements ClassCodeInterface, MoodCodeInterface
38
{
39
  use SingleComponentTrait;
40
  use ClassCodeTrait;
41
  use MoodCodeTrait;
42
43
  /**
44
   * XMLBodyComponent constructor.
45
   *
46
   * @param null $component
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $component is correct as it would always require null to be passed?
Loading history...
47
   */
48
  public function __construct ($component = NULL)
49
  {
50
    $acceptable_values = array(
51
      '',
52
      MoodCodeInterface::EVENT,
53
      MoodCodeInterface::GOAL,
54
      MoodCodeInterface::INTENT,
55
      MoodCodeInterface::PROMISE,
56
      MoodCodeInterface::PROPOSAL,
57
      MoodCodeInterface::REQUEST
58
    );
59
    $this->setAcceptableClassCodes(ClassCodeInterface::ActClass)
60
      ->setAcceptableMoodCodes($acceptable_values)
61
      ->setClassCode(ClassCodeInterface::DOCUMENT_BODY)
62
      ->setMoodCode('');
63
    if ($component instanceof SingleComponent)
64
    {
65
      $this->addComponent($component);
66
    }
67
  }
68
69
70
  /**
71
   * @param \DOMDocument $doc
72
   *
73
   * @return \DOMElement
74
   */
75
  public function toDOMElement (\DOMDocument $doc): \DOMElement
76
  {
77
    $el = $this->createElement($doc);
78
79
    foreach ($this->getComponents() as $component)
80
    {
81
      $el->appendChild($component->toDOMElement($doc));
82
    }
83
84
    return $el;
85
  }
86
87
88
  /**
89
   * get the element tag name
90
   *
91
   * @return string
92
   */
93
  protected function getElementTag (): string
94
  {
95
    return 'structuredBody';
96
  }
97
}
98