http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 5 LOC: 141 Statements: 25

Source file Statements Methods Total coverage
Auth.php 100.0% 100.0% 100.0%
 
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://www.opensource.org/licenses/bsd-license.php
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to xyster@devweblog.org so we can send you a copy immediately.
14
 *
15
 * @category  Xyster
16
 * @package   Xyster_Controller
17
 * @subpackage Plugins
18
 * @copyright Copyright (c) 2007 Irrational Logic (http://devweblog.org)
19
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
20
 * @version   $Id: Auth.php 91 2007-09-19 01:04:42Z doublecompile $
21
 */
22
/**
23
 * Zend_Auth
24
 */
25 1
require_once 'Zend/Auth.php';
26
/**
27
 * Zend_Controller_Plugin_Abstract
28
 */
29 1
require_once 'Zend/Controller/Plugin/Abstract.php';
30
/**
31
 * Authentication plugin
32
 *
33
 * @category  Xyster
34
 * @package   Xyster_Controller
35
 * @subpackage Plugins
36
 * @copyright Copyright (c) 2007 Irrational Logic (http://devweblog.org)
37
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
38
 */
39
class Xyster_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
40
{
41
    /**
42
     * The acl
43
     *
44
     * @var Zend_Acl
45
     */
46
    protected $_acl;
47
48
    /**
49
     * The Auth adapter
50
     *
51
     * @var Zend_Auth_Adapter_Interface
52
     */
53
    protected $_adapter;
54
55
    /**
56
     * The role provider
57
     *
58
     * @var Xyster_Acl_Role_Provider_Interface
59
     */
60
    protected $_provider;
61
62
    /**
63
     * The current authenticated role
64
     *
65
     * @var Zend_Acl_Role_Interface
66
     */
67
    protected $_role;
68
69
    /**
70
     * Creates a new auth plugin
71
     *
72
     * @param Zend_Auth_Adapter_Interface $adapter
73
     * @param Zend_Acl $acl
74
     */
75
    public function __construct( Zend_Auth_Adapter_Interface $adapter = null, Zend_Acl $acl = null )
76
    {
77 4
        $this->_adapter = $adapter;
78 4
        $this->_acl = $acl;
79
    }
80
81
    /**
82
     * Called before Zend_Controller_Front determines the dispatch route
83
     *
84
     * @param Zend_Controller_Request_Abstract $request
85
     */
86
    public function routeStartup(Zend_Controller_Request_Abstract $request)
87
    {
88 1
        $auth = Zend_Auth::getInstance();
89 1
        if ( !$auth->hasIdentity() && $this->_adapter ) {
90 1
            $auth->authenticate($this->_adapter);
91 1
        }
92
93 1
        $role = $this->getRole();
94
95 1
        if ( $role instanceof Zend_Acl_Role_Interface && $this->_acl &&
96 1
            !$this->_acl->hasRole($role) ) {
97 1
            $this->_acl->addRole($role, $this->getRoleProvider()->getRoleParents($role));
98 1
        }
99
    }
100
101
    /**
102
     * Gets the authenticated role
103
     *
104
     * @return Zend_Acl_Role_Interface
105
     */
106
    public function getRole()
107
    {
108 2
        if ( !$this->_role ) {
109 2
            $identity = Zend_Auth::getInstance()->getIdentity();
110 2
            $this->_role = $this->getRoleProvider()->getRole($identity);
111 2
        }
112
113 2
        return $this->_role;
114
    }
115
116
    /**
117
     * Gets the role provider used to translato the identity into a role
118
     *
119
     * @return Xyster_Acl_Role_Provider_Interface
120
     */
121
    public function getRoleProvider()
122
    {
123 4
        if ( !$this->_provider ) {
124 3
            require_once 'Xyster/Acl/Role/Provider.php';
125 3
            $this->_provider = new Xyster_Acl_Role_Provider();
126 3
        }
127 4
        return $this->_provider;
128
    }
129
130
    /**
131
     * Sets the role provider used to translate the identity into a role
132
     *
133
     * @param Xyster_Acl_Role_Provider_Interface $provider
134
     * @return Xyster_Controller_Plugin_Auth
135
     */
136
    public function setRoleProvider( Xyster_Acl_Role_Provider_Interface $provider )
137
    {
138 1
        $this->_provider = $provider;
139 1
        return $this;
140
    }
141
}


Report generated at 2007-10-08T19:32:24-05:00