| 1 |
1
|
kore |
<?php |
|
| 2 |
↓
|
kore |
/** |
|
| 3 |
2
|
kore |
* phpillow CouchDB backend |
|
| 4 |
1
|
kore |
* |
|
| 5 |
2
|
kore |
* This file is part of phpillow. |
|
| 6 |
1
|
kore |
* |
|
| 7 |
3
|
kore |
* phpillow is free software; you can redistribute it and/or modify it under |
|
| 8 |
↓
|
kore |
* the terms of the GNU Lesser General Public License as published by the Free |
|
| 9 |
↓
|
kore |
* Software Foundation; version 3 of the License. |
|
| 10 |
1
|
kore |
* |
|
| 11 |
3
|
kore |
* phpillow is distributed in the hope that it will be useful, but WITHOUT ANY |
|
| 12 |
↓
|
kore |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
| 13 |
↓
|
kore |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
|
| 14 |
↓
|
kore |
* more details. |
|
| 15 |
1
|
kore |
* |
|
| 16 |
3
|
kore |
* You should have received a copy of the GNU Lesser General Public License |
|
| 17 |
↓
|
kore |
* along with phpillow; if not, write to the Free Software Foundation, Inc., 51 |
|
| 18 |
↓
|
kore |
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 19 |
1
|
kore |
* |
|
| 20 |
↓
|
kore |
* @package Core |
|
| 21 |
4
|
kore |
* @version $Revision: 159 $ |
|
| 22 |
3
|
kore |
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL |
|
| 23 |
1
|
kore |
*/ |
|
| 24 |
↓
|
kore |
|
|
| 25 |
↓
|
kore |
/** |
|
| 26 |
↓
|
kore |
* Document representing the users |
|
| 27 |
↓
|
kore |
* |
|
| 28 |
↓
|
kore |
* @package Core |
|
| 29 |
4
|
kore |
* @version $Revision: 159 $ |
|
| 30 |
3
|
kore |
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL |
|
| 31 |
1
|
kore |
*/ |
|
| 32 |
4
|
kore |
class phpillowUserDocument extends phpillowDocument |
|
| 33 |
1
|
kore |
{ |
|
| 34 |
↓
|
kore |
/** |
|
| 35 |
↓
|
kore |
* Document type, may be a string matching the regular expression: |
|
| 36 |
↓
|
kore |
* (^[a-zA-Z0-9_]+$) |
|
| 37 |
159
|
kore |
* |
|
| 38 |
1
|
kore |
* @var string |
|
| 39 |
↓
|
kore |
*/ |
|
| 40 |
↓
|
kore |
protected static $type = 'user'; |
|
| 41 |
↓
|
kore |
|
|
| 42 |
↓
|
kore |
/** |
|
| 43 |
↓
|
kore |
* List of required properties. For each required property, which is not |
|
| 44 |
↓
|
kore |
* set, a validation exception will be thrown on save. |
|
| 45 |
159
|
kore |
* |
|
| 46 |
1
|
kore |
* @var array |
|
| 47 |
↓
|
kore |
*/ |
|
| 48 |
↓
|
kore |
protected $requiredProperties = array( |
|
| 49 |
↓
|
kore |
'login', |
|
| 50 |
↓
|
kore |
); |
|
| 51 |
↓
|
kore |
|
|
| 52 |
↓
|
kore |
/** |
|
| 53 |
↓
|
kore |
* Construct new book document |
|
| 54 |
159
|
kore |
* |
|
| 55 |
1
|
kore |
* Construct new book document and set its property validators. |
|
| 56 |
159
|
kore |
* |
|
| 57 |
1
|
kore |
* @return void |
|
| 58 |
↓
|
kore |
*/ |
|
| 59 |
94
|
kore |
public function __construct() |
|
| 60 |
1
|
kore |
{ |
|
| 61 |
↓
|
kore |
$this->properties = array( |
|
| 62 |
3
|
kore |
'login' => new phpillowRegexpValidator( '(^[\x21-\x7e]+$)i' ), |
|
| 63 |
↓
|
kore |
'email' => new phpillowEmailValidator(), |
|
| 64 |
↓
|
kore |
'name' => new phpillowStringValidator(), |
|
| 65 |
↓
|
kore |
'valid' => new phpillowRegexpValidator( '(^0|1|[a-f0-9]{32}$)' ), |
|
| 66 |
↓
|
kore |
'auth_type' => new phpillowStringValidator(), |
|
| 67 |
↓
|
kore |
'auth_infos' => new phpillowNoValidator(), |
|
| 68 |
1
|
kore |
); |
|
| 69 |
↓
|
kore |
|
|
| 70 |
↓
|
kore |
parent::__construct(); |
|
| 71 |
↓
|
kore |
} |
|
| 72 |
↓
|
kore |
|
|
| 73 |
↓
|
kore |
/** |
|
| 74 |
↓
|
kore |
* Get ID from document |
|
| 75 |
↓
|
kore |
* |
|
| 76 |
↓
|
kore |
* The ID normally should be calculated on some meaningful / unique |
|
| 77 |
159
|
kore |
* property for the current type of documents. The returned string should |
|
| 78 |
1
|
kore |
* not be too long and should not contain multibyte characters. |
|
| 79 |
41
|
kore |
* |
|
| 80 |
↓
|
kore |
* You can return null instead of an ID string, to trigger the ID |
|
| 81 |
↓
|
kore |
* autogeneration. |
|
| 82 |
159
|
kore |
* |
|
| 83 |
41
|
kore |
* @return mixed |
|
| 84 |
1
|
kore |
*/ |
|
| 85 |
↓
|
kore |
protected function generateId() |
|
| 86 |
↓
|
kore |
{ |
|
| 87 |
↓
|
kore |
return $this->stringToId( $this->storage->login ); |
|
| 88 |
↓
|
kore |
} |
|
| 89 |
94
|
kore |
|
|
| 90 |
↓
|
kore |
/** |
|
| 91 |
↓
|
kore |
* Return document type name |
|
| 92 |
↓
|
kore |
* |
|
| 93 |
↓
|
kore |
* This method is required to be implemented to return the document type |
|
| 94 |
↓
|
kore |
* for PHP versions lower then 5.2. When only using PHP 5.3 and higher you |
|
| 95 |
↓
|
kore |
* might just implement a method which does "return static:$type" in a base |
|
| 96 |
↓
|
kore |
* class. |
|
| 97 |
159
|
kore |
* |
|
| 98 |
94
|
kore |
* @return void |
|
| 99 |
↓
|
kore |
*/ |
|
| 100 |
↓
|
kore |
protected function getType() |
|
| 101 |
↓
|
kore |
{ |
|
| 102 |
↓
|
kore |
return self::$type; |
|
| 103 |
↓
|
kore |
} |
|
| 104 |
↓
|
kore |
|
|
| 105 |
↓
|
kore |
/** |
|
| 106 |
↓
|
kore |
* Create a new instance of the document class |
|
| 107 |
↓
|
kore |
* |
|
| 108 |
↓
|
kore |
* Create a new instance of the statically called document class. |
|
| 109 |
↓
|
kore |
* Implementing this method should only be required when using PHP 5.2 and |
|
| 110 |
↓
|
kore |
* lower, otherwise the class can be determined using LSB. |
|
| 111 |
↓
|
kore |
* |
|
| 112 |
↓
|
kore |
* Do not pass a parameter to this method, this is only used to maintain |
|
| 113 |
↓
|
kore |
* the called class information for PHP 5.2 and lower. |
|
| 114 |
↓
|
kore |
* |
|
| 115 |
↓
|
kore |
* @param mixed $docType |
|
| 116 |
159
|
kore |
* @return phpillowDocument |
|
| 117 |
94
|
kore |
*/ |
|
| 118 |
↓
|
kore |
public static function createNew( $docType = null ) |
|
| 119 |
↓
|
kore |
{ |
|
| 120 |
↓
|
kore |
return parent::createNew( $docType === null ? __CLASS__ : $docType ); |
|
| 121 |
↓
|
kore |
} |
|
| 122 |
1
|
kore |
} |
|
| 123 |
↓
|
kore |
|
|