Completed
Push — v2.0.x ( 7a58b6 )
by Florent
24:58
created

JWSFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2015 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Factory;
13
14
use Base64Url\Base64Url;
15
use Jose\Object\JWS;
16
17
final class JWSFactory
18
{
19
    /**
20
     * JWSFactory constructor.
21
     *
22
     * This factory is not supposed to be instantiated
23
     */
24
    private function __construct() {}
25
26
    /**
27
     * @param mixed $payload
28
     *
29
     * @return \Jose\Object\JWSInterface
30
     */
31
    public static function createJWS($payload)
32
    {
33
        $jws = new JWS();
34
        $jws = $jws->withPayload($payload);
35
36
        return $jws;
37
    }
38
39
    /**
40
     * @param mixed  $payload
41
     * @param string $encoded_payload
42
     *
43
     * @return \Jose\Object\JWSInterface
44
     */
45
    public static function createJWSWithDetachedPayload($payload, &$encoded_payload)
46
    {
47
        $encoded_payload = Base64Url::encode(is_string($payload)?$payload:json_encode($payload));
48
49
        return new JWS();
50
    }
51
}
52