Completed
Push — 2.0 ( 143803...4e64fa )
by grégoire
08:42 queued 04:22
created

ClientTrait::shutdown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Pomm's Foundation package.
4
 *
5
 * (c) 2014 - 2015 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\Foundation\Client;
11
12
use PommProject\Foundation\Session\Session;
13
use PommProject\Foundation\Exception\FoundationException;
14
15
/**
16
 * ClientTrait
17
 *
18
 * Abstract class for Session clients.
19
 *
20
 * @package   Foundation
21
 * @copyright 2014 - 2015 Grégoire HUBERT
22
 * @author    Grégoire HUBERT
23
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
24
 * @see       ClientInterface
25
 * @abstract
26
 */
27
trait ClientTrait
28
{
29
    private $session;
30
31
    /**
32
     * @see ClientInterface
33
     */
34
    public function initialize(Session $session)
35
    {
36
        $this->session = $session;
37
    }
38
39
    /**
40
     * Most of the time, there is nothing to be done at shutdown.
41
     * @see ClientInterface
42
     */
43
    public function shutdown()
44
    {
45
    }
46
47
    /**
48
     * getSession
49
     *
50
     * All subclasses of Client have to use this method to access the session.
51
     *
52
     * @access protected
53
     * @throws  FoundationException if Session is not set.
54
     * @return Session
55
     */
56 View Code Duplication
    protected function getSession()
57
    {
58
        if ($this->session === null) {
59
            throw new FoundationException(
60
                sprintf(
61
                    "Client '%s' is not initialized hence does not have a session.",
62
                    get_class($this)
63
                )
64
            );
65
        }
66
67
        return $this->session;
68
    }
69
}
70