Model   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getContext() 0 4 1
A initialize() 0 4 1
A __sleep() 0 7 1
A __wakeup() 0 5 1
1
<?php
2
namespace Agavi\Model;
3
4
// +---------------------------------------------------------------------------+
5
// | This file is part of the Agavi package.                                   |
6
// | Copyright (c) 2005-2011 the Agavi Project.                                |
7
// | Based on the Mojavi3 MVC Framework, Copyright (c) 2003-2005 Sean Kerr.    |
8
// |                                                                           |
9
// | For the full copyright and license information, please view the LICENSE   |
10
// | file that was distributed with this source code. You can also view the    |
11
// | LICENSE file online at http://www.agavi.org/LICENSE.txt                   |
12
// |   vi: set noexpandtab:                                                    |
13
// |   Local Variables:                                                        |
14
// |   indent-tabs-mode: t                                                     |
15
// |   End:                                                                    |
16
// +---------------------------------------------------------------------------+
17
use Agavi\Core\Context;
18
19
/**
20
 * Model provides a convention for separating business logic from
21
 * application logic. When using a model you're providing a globally accessible
22
 * API for other modules to access, which will boost interoperability among
23
 * modules in your web application.
24
 *
25
 * @package    agavi
26
 * @subpackage model
27
 *
28
 * @author     Sean Kerr <[email protected]>
29
 * @author     David Zülke <[email protected]>
30
 * @copyright  Authors
31
 * @copyright  The Agavi Project
32
 *
33
 * @since      0.9.0
34
 *
35
 * @version    $Id$
36
 */
37
abstract class Model implements ModelInterface
38
{
39
    /**
40
     * @var        Context A Context instance.
41
     */
42
    protected $context = null;
43
44
    /**
45
     * @var string The context name
46
     */
47
    protected $_contextName = null;
48
    /**
49
     * Retrieve the current application context.
50
     *
51
     * @return     Context The current Context instance.
52
     *
53
     * @author     Sean Kerr <[email protected]>
54
     * @since      0.9.0
55
     */
56
    final public function getContext()
57
    {
58
        return $this->context;
59
    }
60
61
    /**
62
     * Initialize this model.
63
     *
64
     * @param      Context $context The current application context.
65
     *
66
     * @author     Sean Kerr <[email protected]>
67
     * @since      0.9.0
68
     */
69
    public function initialize(Context $context, array $parameters = array())
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        $this->context = $context;
72
    }
73
74
    /**
75
     * Pre-serialization callback.
76
     *
77
     * Will set the name of the context and exclude the instance from serializing.
78
     *
79
     * @author     David Zülke <[email protected]>
80
     * @since      0.11.0
81
     */
82
    public function __sleep()
83
    {
84
        $this->_contextName = $this->context->getName();
85
        $arr = get_object_vars($this);
86
        unset($arr['context']);
87
        return array_keys($arr);
88
    }
89
90
    /**
91
     * Post-unserialization callback.
92
     *
93
     * Will restore the context based on the names set by __sleep.
94
     *
95
     * @author     David Zülke <[email protected]>
96
     * @since      0.11.0
97
     */
98
    public function __wakeup()
99
    {
100
        $this->context = Context::getInstance($this->_contextName);
101
        unset($this->_contextName);
102
    }
103
}
104