1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.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 license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Centinel
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Abstract Validation State Model
29: */
30: abstract class Mage_Centinel_Model_StateAbstract extends Varien_Object
31: {
32: /**
33: * Storage data model
34: *
35: * @var Varien_Object
36: */
37: private $_dataStorage = false;
38:
39: /**
40: * Setter for storage data model
41: *
42: * @param Varien_Object $dataStorageModel
43: * @return Mage_Centinel_Model_StateAbstract
44: */
45: public function setDataStorage($dataStorageModel)
46: {
47: $this->_dataStorage = $dataStorageModel;
48: return $this;
49: }
50:
51: /**
52: * Getter for storage data model
53: *
54: * @return Varien_Object
55: */
56: public function getDataStorage()
57: {
58: return $this->_dataStorage;
59: }
60:
61: /**
62: * Retrieves data from the object
63: *
64: * If $key is empty will return all the data as an array
65: * Otherwise it will return value of the attribute specified by $key
66: *
67: * $index parameter is ignored
68: * @see Mage_Core_Model_Session_Abstract::getData()
69: *
70: * @param string $key
71: * @param string|int $index
72: * @return mixed
73: */
74: public function getData($key='', $index=null)
75: {
76: return $this->getDataStorage()->getData($key);
77: }
78:
79: /**
80: * Overwrite data in the object.
81: *
82: * $key can be string or array.
83: * If $key is string, the attribute value will be overwritten by $value
84: *
85: * If $key is an array, it will overwrite all the data in the object.
86: *
87: * @param string|array $key
88: * @param mixed $value
89: * @return Mage_Centinel_Model_StateAbstract
90: */
91: public function setData($key, $value=null)
92: {
93: $this->getDataStorage()->setData($key, $value);
94: return $this;
95: }
96:
97: /**
98: * Save lookup result in state model
99: *
100: * @param Varien_Object $result
101: * @return Mage_Centinel_Model_StateAbstract
102: */
103: public function setLookupResult($result)
104: {
105: foreach ($result->getData() as $key => $value) {
106: $this->setData('lookup_' . $key, $value);
107: }
108: return $this;
109: }
110:
111: /**
112: * Save authenticate result in state model
113: *
114: * @param Varien_Object $result
115: * @return Mage_Centinel_Model_StateAbstract
116: */
117: public function setAuthenticateResult($result)
118: {
119: foreach ($result->getData() as $key => $value) {
120: $this->setData('authenticate_' . $key, $value);
121: }
122: return $this;
123: }
124:
125: /**
126: * Analyse lookup`s results. If lookup is successful return true and false if it failure
127: * Result depends from flag self::getIsModeStrict()
128: *
129: * @return bool
130: */
131: final public function isLookupSuccessful()
132: {
133: if ($this->_isLookupStrictSuccessful()) {
134: return true;
135: } elseif (!$this->getIsModeStrict() && $this->_isLookupSoftSuccessful()) {
136: return true;
137: }
138: return false;
139: }
140:
141: /**
142: * Analyse lookup`s results. If lookup is strict successful return true
143: *
144: * @return bool
145: */
146: abstract protected function _isLookupStrictSuccessful();
147:
148: /**
149: * Analyse lookup`s results. If lookup is soft successful return true
150: *
151: * @return bool
152: */
153: abstract protected function _isLookupSoftSuccessful();
154:
155: /**
156: * Analyse lookup`s results. If it has require params for authenticate, return true
157: *
158: * @return bool
159: */
160: abstract public function isAuthenticateAllowed();
161:
162: /**
163: * Analyse authenticate`s results. If authenticate is successful return true and false if it failure
164: * Result depends from flag self::getIsModeStrict()
165: *
166: * @return bool
167: */
168: abstract public function isAuthenticateSuccessful();
169: }
170: