aboutsummaryrefslogtreecommitdiff
path: root/docs/08_Format_API/02_FormatInterface.md
blob: 88448c383c96524ca287e71cb57c24e2ddcf3d41 (plain) (blame)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
The `FormatInterface`interface defines functions that need to be implemented by all formats:

* [display](#the-display-function)
* [stringify](#the-stringify-function)
* [setItems](#the-setitems-function)
* [getItems](#the-getitems-function)
* [setCharset](#the-setcharset-function)
* [getCharset](#the-getcharset-function)
* [setExtraInfos](#the-setextrainfos-function)
* [getExtraInfos](#the-getextrainfos-function)
* [getMimeType](#the-getmimetype-function)

Find a [template](#template) at the end of this file

# Functions

## The `stringify` function

The `stringify` function returns the items received by [`setItems`](#the-setitem-function) as string.

```PHP
stringify(): string
```

## The `setItems` function

The `setItems` function receives an array of items generated by the bridge and must return the object instance. Each item represents an entry in the feed. For more information refer to the [collectData](../05_Bridge_API/02_BridgeAbstract.md#collectdata) function.

```PHP
setItems(array $items): self
```

## The `getItems` function

The `getItems` function returns the items previously set by the [`setItems`](#the-setitems-function) function. If no items where set previously this function returns an error.

```PHP
getItems(): array
```

## The `setCharset` function

The `setCharset` function receives the character set value as string and returns the object instance.

```PHP
setCharset(string): self
```

## The `getCharset` function

The `getCharset` function returns the character set value.

```PHP
getCharset(): string
```

## The `setExtraInfos` function

The `setExtraInfos` function receives an array of elements with additional information to generate format outputs and must return the object instance.

```PHP
setExtraInfos(array $infos): self
```

Currently supported information are:

Name | Description
-----|------------
`name` | Defines the name as generated by the bridge
`uri` | Defines the URI of the feed as generated by the bridge

## The `getExtraInfos` function

The `getExtraInfos` function returns the information previously set via the [`setExtraInfos`](#the-setextrainfos-function) function.

```PHP
getExtraInfos(): array
```

## The `getMimeType` function

The `getMimeType` function returns the expected [MIME type](https://en.wikipedia.org/wiki/Media_type#Common_examples) of the format's output.

```PHP
getMimeType(): string
```

# Template

This is a bare minimum template for a format:

```PHP
<?php
class MyTypeFormat implements FormatInterface {
    private $items;
    private $charset;
    private $extraInfos;

    public function stringify(){
        // Implement your code here
        return ''; // Return items as string
    }

    public function setItems(array $items){
        $this->items = $items;
        return $this;
    }

    public function getItems(){
        return $this->items;
    }

    public function setCharset($charset){
        $this->charset = $charset;
        return $this;
    }

    public function getCharset(){
        return $this->charset;
    }

    public function setExtraInfos(array $infos){
        $this->extraInfos = $infos;
        return $this;
    }

    public function getExtraInfos(){
        return $this->extraInfos;
    }
}
// Imaginary empty line!
```