Completed
Push — master ( fa4413...d72830 )
by Damien
09:02
created

SerializeHelper::isBase64String()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 */
6
7
namespace flipbox\saml\core\helpers;
8
9
use craft\web\Response;
10
11
class SerializeHelper
12
{
13
    /**
14
     * @param $parameter
15
     * @return string
16
     */
17
    public static function toBase64($parameter)
18
    {
19
        return base64_encode($parameter);
20
    }
21
22
    /**
23
     * @param string $str
24
     * @return bool
25
     */
26
    public static function isBase64String(string $str): bool
27
    {
28
        return base64_encode(base64_decode($str)) === $str;
29
    }
30
31
    /**
32
     * set proper headers to present xml correctly
33
     */
34
    public static function xmlContentType()
35
    {
36
        \Craft::$app->getResponse()->format = Response::FORMAT_RAW;
37
        \Craft::$app->getResponse()->getHeaders()->add('Content-Type', 'text/xml');
38
    }
39
40
    /**
41
     * @param string $location
42
     * @param array $parameters
43
     * @return string
44
     */
45
    public static function redirectUrl(string $location, array $parameters)
46
    {
47
48
        return $location .
49
            (strpos($location, '?') === false ? '?' : '&') .
50
            http_build_query($parameters);
51
    }
52
}
53