Debian Codegraph @

classes/Sources/Source.php

raw symbols SCIP
1 <?php
2
3 /**
4 * dmarc-srg - A php parser, viewer and summary report generator for incoming DMARC reports.
5 * Copyright (C) 2021-2023 Aleksey Andreev (liuch)
6 *
7 * Available at:
8 * https://github.com/liuch/dmarc-srg
9 *
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation, either version 3 of the License.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * =========================
23 *
24 * This file contains the class Source
25 *
26 * @category API
27 * @package DmarcSrg
28 * @author Aleksey Andreev (liuch)
29 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3
30 */
31
32 namespace Liuch\DmarcSrg\Sources;
33
34 /**
35 * It's an abstract class for easy access to reports of a report source
36 */
37 abstract class Source implements \Iterator
38 {
39 public const SOURCE_UPLOADED_FILE = 1;
40 public const SOURCE_MAILBOX = 2;
41 public const SOURCE_DIRECTORY = 3;
42 public const SOURCE_REMOTE_FILESYSTEM = 4;
43
44 protected $data = null;
45
46 /**
47 * Constructor
48 *
49 * @param mixed $data Data to reach report files
50 *
51 * @return void
52 */
53 public function __construct($data)
54 {
55 $this->data = $data;
56 }
57
58 /**
59 * Sets parameters that define the behavior of the source
60 *
61 * @param $params Key-value array
62 * 'when_done' => one or more rules to be executed after successful report processing
63 * (array|string)
64 * 'when_failed' => one or more rules to be executed after report processing fails
65 * (array|string)
66 *
67 * @return void
68 */
69 public function setParams(array $params): void
70 {
71 }
72
73 /**
74 * Iterator interface methods
75 */
76 abstract public function current(): object;
77 abstract public function key(): int;
78 abstract public function next(): void;
79 abstract public function rewind(): void;
80 abstract public function valid(): bool;
81
82 /**
83 * Called when the current report has been successfully processed.
84 *
85 * @return void
86 */
87 public function accepted(): void
88 {
89 }
90
91 /**
92 * Called when the current report has been rejected.
93 *
94 * @return void
95 */
96 public function rejected(): void
97 {
98 }
99
100 /**
101 * Returns type of source, i.e. one of Source::SOURCE_* values
102 *
103 * @return int
104 */
105 abstract public function type(): int;
106
107 /**
108 * Returns the source itself that was passed to the constructor
109 *
110 * @return mixed
111 */
112 public function container()
113 {
114 return $this->data;
115 }
116 }