summaryrefslogtreecommitdiffstats
path: root/src/Common/ContextAwareTrait.php
blob: 6513a2a8a2e9a0319d438fa48532eb39f380bc64 (plain)
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
<?php

namespace Aegir\Provision\Common;

use Aegir\Provision;
use Aegir\Provision\Context;

trait ContextAwareTrait
{
    /**
     * @var Context
     */
    protected $context = NULL;
    
    /**
     * @param Context $context
     *
     * @return $this
     */
    public function setContext(Context $context = NULL)
    {
        $this->context = $context;
        
        return $this;
    }
    
    /**
     * @return Context
     */
    public function getContext()
    {
    
        if (is_null($this->context)) {
            return Provision::getContext()();
        }
    
        return $this->context;
    }
}