@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * GET variable name for return url |
| 49 | 49 | */ |
| 50 | - const RETURN_URL_VAR = 'ReturnUrl'; |
|
| 50 | + const RETURN_URL_VAR='ReturnUrl'; |
|
| 51 | 51 | /** |
| 52 | 52 | * @var boolean if the module has been initialized |
| 53 | 53 | */ |
| 54 | - private $_initialized = false; |
|
| 54 | + private $_initialized=false; |
|
| 55 | 55 | /** |
| 56 | 56 | * @var IUserManager user manager instance |
| 57 | 57 | */ |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * @var boolean whether authorization should be skipped |
| 65 | 65 | */ |
| 66 | - private $_skipAuthorization = false; |
|
| 66 | + private $_skipAuthorization=false; |
|
| 67 | 67 | /** |
| 68 | 68 | * @var string the session var name for storing return URL |
| 69 | 69 | */ |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | /** |
| 72 | 72 | * @var boolean whether to allow auto login (using cookie) |
| 73 | 73 | */ |
| 74 | - private $_allowAutoLogin = false; |
|
| 74 | + private $_allowAutoLogin=false; |
|
| 75 | 75 | /** |
| 76 | 76 | * @var string variable name used to store user session or cookie |
| 77 | 77 | */ |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | /** |
| 80 | 80 | * @var integer authentication expiration time in seconds. Defaults to zero (no expiration) |
| 81 | 81 | */ |
| 82 | - private $_authExpire = 0; |
|
| 82 | + private $_authExpire=0; |
|
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * Initializes this module. |
@@ -89,23 +89,23 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function init($config) |
| 91 | 91 | { |
| 92 | - if($this->_userManager === null) |
|
| 92 | + if($this->_userManager===null) |
|
| 93 | 93 | throw new TConfigurationException('authmanager_usermanager_required'); |
| 94 | - if($this->_returnUrlVarName === null) |
|
| 95 | - $this->_returnUrlVarName = $this->getApplication()->getID() . ':' . self::RETURN_URL_VAR; |
|
| 96 | - $application = $this->getApplication(); |
|
| 94 | + if($this->_returnUrlVarName===null) |
|
| 95 | + $this->_returnUrlVarName=$this->getApplication()->getID().':'.self::RETURN_URL_VAR; |
|
| 96 | + $application=$this->getApplication(); |
|
| 97 | 97 | if(is_string($this->_userManager)) |
| 98 | 98 | { |
| 99 | - if(($users = $application->getModule($this->_userManager)) === null) |
|
| 99 | + if(($users=$application->getModule($this->_userManager))===null) |
|
| 100 | 100 | throw new TConfigurationException('authmanager_usermanager_inexistent', $this->_userManager); |
| 101 | 101 | if(!($users instanceof IUserManager)) |
| 102 | 102 | throw new TConfigurationException('authmanager_usermanager_invalid', $this->_userManager); |
| 103 | - $this->_userManager = $users; |
|
| 103 | + $this->_userManager=$users; |
|
| 104 | 104 | } |
| 105 | - $application->attachEventHandler('OnAuthentication', [$this,'doAuthentication']); |
|
| 106 | - $application->attachEventHandler('OnEndRequest', [$this,'leave']); |
|
| 107 | - $application->attachEventHandler('OnAuthorization', [$this,'doAuthorization']); |
|
| 108 | - $this->_initialized = true; |
|
| 105 | + $application->attachEventHandler('OnAuthentication', [$this, 'doAuthentication']); |
|
| 106 | + $application->attachEventHandler('OnEndRequest', [$this, 'leave']); |
|
| 107 | + $application->attachEventHandler('OnAuthorization', [$this, 'doAuthorization']); |
|
| 108 | + $this->_initialized=true; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | throw new TInvalidOperationException('authmanager_usermanager_unchangeable'); |
| 127 | 127 | if(!is_string($provider) && !($provider instanceof IUserManager)) |
| 128 | 128 | throw new TConfigurationException('authmanager_usermanager_invalid', $this->_userManager); |
| 129 | - $this->_userManager = $provider; |
|
| 129 | + $this->_userManager=$provider; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public function setLoginPage($pagePath) |
| 147 | 147 | { |
| 148 | - $this->_loginPage = $pagePath; |
|
| 148 | + $this->_loginPage=$pagePath; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | { |
| 160 | 160 | $this->onAuthenticate($param); |
| 161 | 161 | |
| 162 | - $service = $this->getService(); |
|
| 163 | - if(($service instanceof TPageService) && $service->getRequestedPagePath() === $this->getLoginPage()) |
|
| 164 | - $this->_skipAuthorization = true; |
|
| 162 | + $service=$this->getService(); |
|
| 163 | + if(($service instanceof TPageService) && $service->getRequestedPagePath()===$this->getLoginPage()) |
|
| 164 | + $this->_skipAuthorization=true; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -188,15 +188,15 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | public function leave($sender, $param) |
| 190 | 190 | { |
| 191 | - $application = $this->getApplication(); |
|
| 192 | - if($application->getResponse()->getStatusCode() === 401) |
|
| 191 | + $application=$this->getApplication(); |
|
| 192 | + if($application->getResponse()->getStatusCode()===401) |
|
| 193 | 193 | { |
| 194 | - $service = $application->getService(); |
|
| 194 | + $service=$application->getService(); |
|
| 195 | 195 | if($service instanceof TPageService) |
| 196 | 196 | { |
| 197 | - $returnUrl = $application->getRequest()->getRequestUri(); |
|
| 197 | + $returnUrl=$application->getRequest()->getRequestUri(); |
|
| 198 | 198 | $this->setReturnUrl($returnUrl); |
| 199 | - $url = $service->constructUrl($this->getLoginPage()); |
|
| 199 | + $url=$service->constructUrl($this->getLoginPage()); |
|
| 200 | 200 | $application->getResponse()->redirect($url); |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | public function setReturnUrlVarName($value) |
| 217 | 217 | { |
| 218 | - $this->_returnUrlVarName = $value; |
|
| 218 | + $this->_returnUrlVarName=$value; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | public function setAllowAutoLogin($value) |
| 252 | 252 | { |
| 253 | - $this->_allowAutoLogin = TPropertyValue::ensureBoolean($value); |
|
| 253 | + $this->_allowAutoLogin=TPropertyValue::ensureBoolean($value); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | */ |
| 269 | 269 | public function setAuthExpire($value) |
| 270 | 270 | { |
| 271 | - $this->_authExpire = TPropertyValue::ensureInteger($value); |
|
| 271 | + $this->_authExpire=TPropertyValue::ensureInteger($value); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -281,31 +281,31 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | public function onAuthenticate($param) |
| 283 | 283 | { |
| 284 | - $application = $this->getApplication(); |
|
| 284 | + $application=$this->getApplication(); |
|
| 285 | 285 | |
| 286 | 286 | // restoring user info from session |
| 287 | - if(($session = $application->getSession()) === null) |
|
| 287 | + if(($session=$application->getSession())===null) |
|
| 288 | 288 | throw new TConfigurationException('authmanager_session_required'); |
| 289 | 289 | $session->open(); |
| 290 | - $sessionInfo = $session->itemAt($this->getUserKey()); |
|
| 291 | - $user = $this->_userManager->getUser(null)->loadFromString($sessionInfo); |
|
| 290 | + $sessionInfo=$session->itemAt($this->getUserKey()); |
|
| 291 | + $user=$this->_userManager->getUser(null)->loadFromString($sessionInfo); |
|
| 292 | 292 | |
| 293 | 293 | // check for authentication expiration |
| 294 | - $isAuthExpired = $this->_authExpire > 0 && !$user->getIsGuest() && |
|
| 295 | - ($expiretime = $session->itemAt('AuthExpireTime')) && $expiretime < time(); |
|
| 294 | + $isAuthExpired=$this->_authExpire > 0 && !$user->getIsGuest() && |
|
| 295 | + ($expiretime=$session->itemAt('AuthExpireTime')) && $expiretime < time(); |
|
| 296 | 296 | |
| 297 | 297 | // try authenticating through cookie if possible |
| 298 | 298 | if($this->getAllowAutoLogin() && ($user->getIsGuest() || $isAuthExpired)) |
| 299 | 299 | { |
| 300 | - $cookie = $this->getRequest()->getCookies()->itemAt($this->getUserKey()); |
|
| 300 | + $cookie=$this->getRequest()->getCookies()->itemAt($this->getUserKey()); |
|
| 301 | 301 | if($cookie instanceof THttpCookie) |
| 302 | 302 | { |
| 303 | - if(($user2 = $this->_userManager->getUserFromCookie($cookie)) !== null) |
|
| 303 | + if(($user2=$this->_userManager->getUserFromCookie($cookie))!==null) |
|
| 304 | 304 | { |
| 305 | - $user = $user2; |
|
| 305 | + $user=$user2; |
|
| 306 | 306 | $this->updateSessionUser($user); |
| 307 | 307 | // user is restored from cookie, auth may not expire |
| 308 | - $isAuthExpired = false; |
|
| 308 | + $isAuthExpired=false; |
|
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | public function onAuthorize($param) |
| 346 | 346 | { |
| 347 | - $application = $this->getApplication(); |
|
| 347 | + $application=$this->getApplication(); |
|
| 348 | 348 | if($this->hasEventHandler('OnAuthorize')) |
| 349 | 349 | $this->raiseEvent('OnAuthorize', $this, $application); |
| 350 | 350 | if(!$application->getAuthorizationRules()->isUserAllowed($application->getUser(), $application->getRequest()->getRequestType(), $application->getRequest()->getUserHostAddress())) |
@@ -360,8 +360,8 @@ discard block |
||
| 360 | 360 | */ |
| 361 | 361 | public function getUserKey() |
| 362 | 362 | { |
| 363 | - if($this->_userKey === null) |
|
| 364 | - $this->_userKey = $this->generateUserKey(); |
|
| 363 | + if($this->_userKey===null) |
|
| 364 | + $this->_userKey=$this->generateUserKey(); |
|
| 365 | 365 | return $this->_userKey; |
| 366 | 366 | } |
| 367 | 367 | |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | protected function generateUserKey() |
| 373 | 373 | { |
| 374 | - return md5($this->getApplication()->getUniqueID() . 'prado:user'); |
|
| 374 | + return md5($this->getApplication()->getUniqueID().'prado:user'); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | { |
| 384 | 384 | if(!$user->getIsGuest()) |
| 385 | 385 | { |
| 386 | - if(($session = $this->getSession()) === null) |
|
| 386 | + if(($session=$this->getSession())===null) |
|
| 387 | 387 | throw new TConfigurationException('authmanager_session_required'); |
| 388 | 388 | else |
| 389 | 389 | $session->add($this->getUserKey(), $user->saveToString()); |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | */ |
| 399 | 399 | public function switchUser($username) |
| 400 | 400 | { |
| 401 | - if(($user = $this->_userManager->getUser($username)) === null) |
|
| 401 | + if(($user=$this->_userManager->getUser($username))===null) |
|
| 402 | 402 | return false; |
| 403 | 403 | $this->updateSessionUser($user); |
| 404 | 404 | $this->getApplication()->setUser($user); |
@@ -414,18 +414,18 @@ discard block |
||
| 414 | 414 | * @param integer number of seconds that automatic login will remain effective. If 0, it means user logs out when session ends. This parameter is added since 3.1.1. |
| 415 | 415 | * @return boolean if login is successful |
| 416 | 416 | */ |
| 417 | - public function login($username, $password, $expire = 0) |
|
| 417 | + public function login($username, $password, $expire=0) |
|
| 418 | 418 | { |
| 419 | 419 | if($this->_userManager->validateUser($username, $password)) |
| 420 | 420 | { |
| 421 | - if(($user = $this->_userManager->getUser($username)) === null) |
|
| 421 | + if(($user=$this->_userManager->getUser($username))===null) |
|
| 422 | 422 | return false; |
| 423 | 423 | $this->updateSessionUser($user); |
| 424 | 424 | $this->getApplication()->setUser($user); |
| 425 | 425 | |
| 426 | 426 | if($expire > 0) |
| 427 | 427 | { |
| 428 | - $cookie = new THttpCookie($this->getUserKey(), ''); |
|
| 428 | + $cookie=new THttpCookie($this->getUserKey(), ''); |
|
| 429 | 429 | $cookie->setExpire(time() + $expire); |
| 430 | 430 | $this->_userManager->saveUserToCookie($cookie); |
| 431 | 431 | $this->getResponse()->getCookies()->add($cookie); |
@@ -443,13 +443,13 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | public function logout() |
| 445 | 445 | { |
| 446 | - if(($session = $this->getSession()) === null) |
|
| 446 | + if(($session=$this->getSession())===null) |
|
| 447 | 447 | throw new TConfigurationException('authmanager_session_required'); |
| 448 | 448 | $this->getApplication()->getUser()->setIsGuest(true); |
| 449 | 449 | $session->destroy(); |
| 450 | 450 | if($this->getAllowAutoLogin()) |
| 451 | 451 | { |
| 452 | - $cookie = new THttpCookie($this->getUserKey(), ''); |
|
| 452 | + $cookie=new THttpCookie($this->getUserKey(), ''); |
|
| 453 | 453 | $this->getResponse()->getCookies()->add($cookie); |
| 454 | 454 | } |
| 455 | 455 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @var boolean whether user state is changed |
| 39 | 39 | */ |
| 40 | - private $_stateChanged = false; |
|
| 40 | + private $_stateChanged=false; |
|
| 41 | 41 | /** |
| 42 | 42 | * @var IUserManager user manager |
| 43 | 43 | */ |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function __construct(IUserManager $manager) |
| 51 | 51 | { |
| 52 | - $this->_state = []; |
|
| 53 | - $this->_manager = $manager; |
|
| 52 | + $this->_state=[]; |
|
| 53 | + $this->_manager=$manager; |
|
| 54 | 54 | $this->setName($manager->getGuestName()); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function setIsGuest($value) |
| 93 | 93 | { |
| 94 | - if($isGuest = TPropertyValue::ensureBoolean($value)) |
|
| 94 | + if($isGuest=TPropertyValue::ensureBoolean($value)) |
|
| 95 | 95 | { |
| 96 | 96 | $this->setName($this->_manager->getGuestName()); |
| 97 | 97 | $this->setRoles([]); |
@@ -116,11 +116,11 @@ discard block |
||
| 116 | 116 | $this->setState('Roles', $value, []); |
| 117 | 117 | else |
| 118 | 118 | { |
| 119 | - $roles = []; |
|
| 119 | + $roles=[]; |
|
| 120 | 120 | foreach(explode(',', $value) as $role) |
| 121 | 121 | { |
| 122 | - if(($role = trim($role)) !== '') |
|
| 123 | - $roles[] = $role; |
|
| 122 | + if(($role=trim($role))!=='') |
|
| 123 | + $roles[]=$role; |
|
| 124 | 124 | } |
| 125 | 125 | $this->setState('Roles', $roles, []); |
| 126 | 126 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | public function isInRole($role) |
| 134 | 134 | { |
| 135 | 135 | foreach($this->getRoles() as $r) |
| 136 | - if(strcasecmp($role, $r) === 0) |
|
| 136 | + if(strcasecmp($role, $r)===0) |
|
| 137 | 137 | return true; |
| 138 | 138 | return false; |
| 139 | 139 | } |
@@ -153,9 +153,9 @@ discard block |
||
| 153 | 153 | public function loadFromString($data) |
| 154 | 154 | { |
| 155 | 155 | if(!empty($data)) |
| 156 | - $this->_state = unserialize($data); |
|
| 156 | + $this->_state=unserialize($data); |
|
| 157 | 157 | if(!is_array($this->_state)) |
| 158 | - $this->_state = []; |
|
| 158 | + $this->_state=[]; |
|
| 159 | 159 | return $this; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -172,9 +172,9 @@ discard block |
||
| 172 | 172 | * @return mixed the value of the variable. If it doesn't exist, the provided default value will be returned |
| 173 | 173 | * @see setState |
| 174 | 174 | */ |
| 175 | - protected function getState($key, $defaultValue = null) |
|
| 175 | + protected function getState($key, $defaultValue=null) |
|
| 176 | 176 | { |
| 177 | - return isset($this->_state[$key])?$this->_state[$key]:$defaultValue; |
|
| 177 | + return isset($this->_state[$key]) ? $this->_state[$key] : $defaultValue; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | * @param mixed default value. If $value===$defaultValue, the variable will be removed from persistent storage. |
| 192 | 192 | * @see getState |
| 193 | 193 | */ |
| 194 | - protected function setState($key, $value, $defaultValue = null) |
|
| 194 | + protected function setState($key, $value, $defaultValue=null) |
|
| 195 | 195 | { |
| 196 | - if($value === $defaultValue) |
|
| 196 | + if($value===$defaultValue) |
|
| 197 | 197 | unset($this->_state[$key]); |
| 198 | 198 | else |
| 199 | - $this->_state[$key] = $value; |
|
| 200 | - $this->_stateChanged = true; |
|
| 199 | + $this->_state[$key]=$value; |
|
| 200 | + $this->_stateChanged=true; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | public function setStateChanged($value) |
| 215 | 215 | { |
| 216 | - $this->_stateChanged = TPropertyValue::ensureBoolean($value); |
|
| 216 | + $this->_stateChanged=TPropertyValue::ensureBoolean($value); |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | class TDbUserManager extends \Prado\TModule implements IUserManager |
| 50 | 50 | { |
| 51 | - private $_connID = ''; |
|
| 51 | + private $_connID=''; |
|
| 52 | 52 | private $_conn; |
| 53 | - private $_guestName = 'Guest'; |
|
| 54 | - private $_userClass = ''; |
|
| 53 | + private $_guestName='Guest'; |
|
| 54 | + private $_userClass=''; |
|
| 55 | 55 | private $_userFactory; |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function init($config) |
| 63 | 63 | { |
| 64 | - if($this->_userClass === '') |
|
| 64 | + if($this->_userClass==='') |
|
| 65 | 65 | throw new TConfigurationException('dbusermanager_userclass_required'); |
| 66 | - $this->_userFactory = Prado::createComponent($this->_userClass, $this); |
|
| 66 | + $this->_userFactory=Prado::createComponent($this->_userClass, $this); |
|
| 67 | 67 | if(!($this->_userFactory instanceof TDbUser)) |
| 68 | 68 | throw new TInvalidDataTypeException('dbusermanager_userclass_invalid', $this->_userClass); |
| 69 | 69 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function setUserClass($value) |
| 83 | 83 | { |
| 84 | - $this->_userClass = $value; |
|
| 84 | + $this->_userClass=$value; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function setGuestName($value) |
| 99 | 99 | { |
| 100 | - $this->_guestName = $value; |
|
| 100 | + $this->_guestName=$value; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -116,11 +116,11 @@ discard block |
||
| 116 | 116 | * @param string user name, null if it is a guest. |
| 117 | 117 | * @return TUser the user instance, null if the specified username is not in the user database. |
| 118 | 118 | */ |
| 119 | - public function getUser($username = null) |
|
| 119 | + public function getUser($username=null) |
|
| 120 | 120 | { |
| 121 | - if($username === null) |
|
| 121 | + if($username===null) |
|
| 122 | 122 | { |
| 123 | - $user = Prado::createComponent($this->_userClass, $this); |
|
| 123 | + $user=Prado::createComponent($this->_userClass, $this); |
|
| 124 | 124 | $user->setIsGuest(true); |
| 125 | 125 | return $user; |
| 126 | 126 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function setConnectionID($value) |
| 146 | 146 | { |
| 147 | - $this->_connID = $value; |
|
| 147 | + $this->_connID=$value; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function getDbConnection() |
| 154 | 154 | { |
| 155 | - if($this->_conn === null) |
|
| 155 | + if($this->_conn===null) |
|
| 156 | 156 | { |
| 157 | - $this->_conn = $this->createDbConnection($this->_connID); |
|
| 157 | + $this->_conn=$this->createDbConnection($this->_connID); |
|
| 158 | 158 | $this->_conn->setActive(true); |
| 159 | 159 | } |
| 160 | 160 | return $this->_conn; |
@@ -168,9 +168,9 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | protected function createDbConnection($connectionID) |
| 170 | 170 | { |
| 171 | - if($connectionID !== '') |
|
| 171 | + if($connectionID!=='') |
|
| 172 | 172 | { |
| 173 | - $conn = $this->getApplication()->getModule($connectionID); |
|
| 173 | + $conn=$this->getApplication()->getModule($connectionID); |
|
| 174 | 174 | if($conn instanceof TDataSourceConfig) |
| 175 | 175 | return $conn->getDbConnection(); |
| 176 | 176 | else |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | public function saveUserToCookie($cookie) |
| 200 | 200 | { |
| 201 | - $user = $this->getApplication()->getUser(); |
|
| 201 | + $user=$this->getApplication()->getUser(); |
|
| 202 | 202 | if($user instanceof TDbUser) |
| 203 | 203 | $user->saveUserToCookie($cookie); |
| 204 | 204 | } |
@@ -50,13 +50,13 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | class TSecurityManager extends \Prado\TModule |
| 52 | 52 | { |
| 53 | - const STATE_VALIDATION_KEY = 'prado:securitymanager:validationkey'; |
|
| 54 | - const STATE_ENCRYPTION_KEY = 'prado:securitymanager:encryptionkey'; |
|
| 53 | + const STATE_VALIDATION_KEY='prado:securitymanager:validationkey'; |
|
| 54 | + const STATE_ENCRYPTION_KEY='prado:securitymanager:encryptionkey'; |
|
| 55 | 55 | |
| 56 | 56 | private $_validationKey; |
| 57 | 57 | private $_encryptionKey; |
| 58 | - private $_hashAlgorithm = 'sha256'; |
|
| 59 | - private $_cryptAlgorithm = 'aes-256-cbc'; |
|
| 58 | + private $_hashAlgorithm='sha256'; |
|
| 59 | + private $_cryptAlgorithm='aes-256-cbc'; |
|
| 60 | 60 | private $_mbstring; |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function init($config) |
| 68 | 68 | { |
| 69 | - $this->_mbstring = extension_loaded('mbstring'); |
|
| 69 | + $this->_mbstring=extension_loaded('mbstring'); |
|
| 70 | 70 | $this->getApplication()->setSecurityManager($this); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function getValidationKey() |
| 86 | 86 | { |
| 87 | - if(null === $this->_validationKey) { |
|
| 88 | - if(null === ($this->_validationKey = $this->getApplication()->getGlobalState(self::STATE_VALIDATION_KEY))) { |
|
| 89 | - $this->_validationKey = $this->generateRandomKey(); |
|
| 87 | + if(null===$this->_validationKey) { |
|
| 88 | + if(null===($this->_validationKey=$this->getApplication()->getGlobalState(self::STATE_VALIDATION_KEY))) { |
|
| 89 | + $this->_validationKey=$this->generateRandomKey(); |
|
| 90 | 90 | $this->getApplication()->setGlobalState(self::STATE_VALIDATION_KEY, $this->_validationKey, null, true); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function setValidationKey($value) |
| 101 | 101 | { |
| 102 | - if('' === $value) |
|
| 102 | + if(''===$value) |
|
| 103 | 103 | throw new TInvalidDataValueException('securitymanager_validationkey_invalid'); |
| 104 | 104 | |
| 105 | - $this->_validationKey = $value; |
|
| 105 | + $this->_validationKey=$value; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function getEncryptionKey() |
| 113 | 113 | { |
| 114 | - if(null === $this->_encryptionKey) { |
|
| 115 | - if(null === ($this->_encryptionKey = $this->getApplication()->getGlobalState(self::STATE_ENCRYPTION_KEY))) { |
|
| 116 | - $this->_encryptionKey = $this->generateRandomKey(); |
|
| 114 | + if(null===$this->_encryptionKey) { |
|
| 115 | + if(null===($this->_encryptionKey=$this->getApplication()->getGlobalState(self::STATE_ENCRYPTION_KEY))) { |
|
| 116 | + $this->_encryptionKey=$this->generateRandomKey(); |
|
| 117 | 117 | $this->getApplication()->setGlobalState(self::STATE_ENCRYPTION_KEY, $this->_encryptionKey, null, true); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -126,10 +126,10 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function setEncryptionKey($value) |
| 128 | 128 | { |
| 129 | - if('' === $value) |
|
| 129 | + if(''===$value) |
|
| 130 | 130 | throw new TInvalidDataValueException('securitymanager_encryptionkey_invalid'); |
| 131 | 131 | |
| 132 | - $this->_encryptionKey = $value; |
|
| 132 | + $this->_encryptionKey=$value; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function setHashAlgorithm($value) |
| 149 | 149 | { |
| 150 | - $this->_hashAlgorithm = TPropertyValue::ensureString($value); |
|
| 150 | + $this->_hashAlgorithm=TPropertyValue::ensureString($value); |
|
| 151 | 151 | if(!in_array($this->_hashAlgorithm, hash_algos())) |
| 152 | 152 | throw new TInvalidDataValueException('securitymanager_hash_algorithm_invalid'); |
| 153 | 153 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function setCryptAlgorithm($value) |
| 168 | 168 | { |
| 169 | - $this->_cryptAlgorithm = TPropertyValue::ensureString($value); |
|
| 169 | + $this->_cryptAlgorithm=TPropertyValue::ensureString($value); |
|
| 170 | 170 | if(!in_array($this->_hashAlgorithm, openssl_get_cipher_methods())) |
| 171 | 171 | throw new TInvalidDataValueException('securitymanager_crypt_algorithm_invalid'); |
| 172 | 172 | } |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | { |
| 182 | 182 | if(extension_loaded('openssl')) |
| 183 | 183 | { |
| 184 | - $key = md5($this->getEncryptionKey()); |
|
| 185 | - $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->_cryptAlgorithm)); |
|
| 186 | - return $iv . openssl_encrypt($data, $this->_cryptAlgorithm, $key, null, $iv); |
|
| 184 | + $key=md5($this->getEncryptionKey()); |
|
| 185 | + $iv=openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->_cryptAlgorithm)); |
|
| 186 | + return $iv.openssl_encrypt($data, $this->_cryptAlgorithm, $key, null, $iv); |
|
| 187 | 187 | } |
| 188 | 188 | else |
| 189 | 189 | throw new TNotSupportedException('securitymanager_openssl_required'); |
@@ -199,8 +199,8 @@ discard block |
||
| 199 | 199 | { |
| 200 | 200 | if(extension_loaded('openssl')) |
| 201 | 201 | { |
| 202 | - $key = md5($this->getEncryptionKey()); |
|
| 203 | - $iv = $this->substr($data, 0, openssl_cipher_iv_length($this->_cryptAlgorithm)); |
|
| 202 | + $key=md5($this->getEncryptionKey()); |
|
| 203 | + $iv=$this->substr($data, 0, openssl_cipher_iv_length($this->_cryptAlgorithm)); |
|
| 204 | 204 | return openssl_decrypt($this->substr($data, $this->strlen($iv), $this->strlen($data)), $this->_cryptAlgorithm, $key, null, $iv); |
| 205 | 205 | } |
| 206 | 206 | else |
@@ -214,8 +214,8 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | public function hashData($data) |
| 216 | 216 | { |
| 217 | - $hmac = $this->computeHMAC($data); |
|
| 218 | - return $hmac . $data; |
|
| 217 | + $hmac=$this->computeHMAC($data); |
|
| 218 | + return $hmac.$data; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -227,14 +227,14 @@ discard block |
||
| 227 | 227 | */ |
| 228 | 228 | public function validateData($data) |
| 229 | 229 | { |
| 230 | - $len = $this->strlen($this->computeHMAC('test')); |
|
| 230 | + $len=$this->strlen($this->computeHMAC('test')); |
|
| 231 | 231 | |
| 232 | 232 | if($this->strlen($data) < $len) |
| 233 | 233 | return false; |
| 234 | 234 | |
| 235 | - $hmac = $this->substr($data, 0, $len); |
|
| 236 | - $data2 = $this->substr($data, $len, $this->strlen($data)); |
|
| 237 | - return $hmac === $this->computeHMAC($data2) ? $data2 : false; |
|
| 235 | + $hmac=$this->substr($data, 0, $len); |
|
| 236 | + $data2=$this->substr($data, $len, $this->strlen($data)); |
|
| 237 | + return $hmac===$this->computeHMAC($data2) ? $data2 : false; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | * @param string user name, null if it is a guest. |
| 34 | 34 | * @return TUser the user instance, null if the specified username is not in the user database. |
| 35 | 35 | */ |
| 36 | - public function getUser($username = null); |
|
| 36 | + public function getUser($username=null); |
|
| 37 | 37 | /** |
| 38 | 38 | * Returns a user instance according to auth data stored in a cookie. |
| 39 | 39 | * @param THttpCookie the cookie storing user authentication information |
@@ -75,61 +75,61 @@ discard block |
||
| 75 | 75 | * @param string verb, can be empty, 'get', or 'post' |
| 76 | 76 | * @param string IP rules (separated by comma, can contain wild card *) |
| 77 | 77 | */ |
| 78 | - public function __construct($action, $users, $roles, $verb = '', $ipRules = '') |
|
| 78 | + public function __construct($action, $users, $roles, $verb='', $ipRules='') |
|
| 79 | 79 | { |
| 80 | - $action = strtolower(trim($action)); |
|
| 81 | - if($action === 'allow' || $action === 'deny') |
|
| 82 | - $this->_action = $action; |
|
| 80 | + $action=strtolower(trim($action)); |
|
| 81 | + if($action==='allow' || $action==='deny') |
|
| 82 | + $this->_action=$action; |
|
| 83 | 83 | else |
| 84 | 84 | throw new TInvalidDataValueException('authorizationrule_action_invalid', $action); |
| 85 | - $this->_users = []; |
|
| 86 | - $this->_roles = []; |
|
| 87 | - $this->_ipRules = []; |
|
| 88 | - $this->_everyone = false; |
|
| 89 | - $this->_guest = false; |
|
| 90 | - $this->_authenticated = false; |
|
| 91 | - |
|
| 92 | - if(trim($users) === '') |
|
| 93 | - $users = '*'; |
|
| 85 | + $this->_users=[]; |
|
| 86 | + $this->_roles=[]; |
|
| 87 | + $this->_ipRules=[]; |
|
| 88 | + $this->_everyone=false; |
|
| 89 | + $this->_guest=false; |
|
| 90 | + $this->_authenticated=false; |
|
| 91 | + |
|
| 92 | + if(trim($users)==='') |
|
| 93 | + $users='*'; |
|
| 94 | 94 | foreach(explode(',', $users) as $user) |
| 95 | 95 | { |
| 96 | - if(($user = trim(strtolower($user))) !== '') |
|
| 96 | + if(($user=trim(strtolower($user)))!=='') |
|
| 97 | 97 | { |
| 98 | - if($user === '*') |
|
| 98 | + if($user==='*') |
|
| 99 | 99 | { |
| 100 | - $this->_everyone = true; |
|
| 100 | + $this->_everyone=true; |
|
| 101 | 101 | break; |
| 102 | 102 | } |
| 103 | - elseif($user === '?') |
|
| 104 | - $this->_guest = true; |
|
| 105 | - elseif($user === '@') |
|
| 106 | - $this->_authenticated = true; |
|
| 103 | + elseif($user==='?') |
|
| 104 | + $this->_guest=true; |
|
| 105 | + elseif($user==='@') |
|
| 106 | + $this->_authenticated=true; |
|
| 107 | 107 | else |
| 108 | - $this->_users[] = $user; |
|
| 108 | + $this->_users[]=$user; |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if(trim($roles) === '') |
|
| 113 | - $roles = '*'; |
|
| 112 | + if(trim($roles)==='') |
|
| 113 | + $roles='*'; |
|
| 114 | 114 | foreach(explode(',', $roles) as $role) |
| 115 | 115 | { |
| 116 | - if(($role = trim(strtolower($role))) !== '') |
|
| 117 | - $this->_roles[] = $role; |
|
| 116 | + if(($role=trim(strtolower($role)))!=='') |
|
| 117 | + $this->_roles[]=$role; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if(($verb = trim(strtolower($verb))) === '') |
|
| 121 | - $verb = '*'; |
|
| 122 | - if($verb === '*' || $verb === 'get' || $verb === 'post') |
|
| 123 | - $this->_verb = $verb; |
|
| 120 | + if(($verb=trim(strtolower($verb)))==='') |
|
| 121 | + $verb='*'; |
|
| 122 | + if($verb==='*' || $verb==='get' || $verb==='post') |
|
| 123 | + $this->_verb=$verb; |
|
| 124 | 124 | else |
| 125 | 125 | throw new TInvalidDataValueException('authorizationrule_verb_invalid', $verb); |
| 126 | 126 | |
| 127 | - if(trim($ipRules) === '') |
|
| 128 | - $ipRules = '*'; |
|
| 127 | + if(trim($ipRules)==='') |
|
| 128 | + $ipRules='*'; |
|
| 129 | 129 | foreach(explode(',', $ipRules) as $ipRule) |
| 130 | 130 | { |
| 131 | - if(($ipRule = trim($ipRule)) !== '') |
|
| 132 | - $this->_ipRules[] = $ipRule; |
|
| 131 | + if(($ipRule=trim($ipRule))!=='') |
|
| 132 | + $this->_ipRules[]=$ipRule; |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public function isUserAllowed(IUser $user, $verb, $ip) |
| 208 | 208 | { |
| 209 | 209 | if($this->isVerbMatched($verb) && $this->isIpMatched($ip) && $this->isUserMatched($user) && $this->isRoleMatched($user)) |
| 210 | - return ($this->_action === 'allow')?1:-1; |
|
| 210 | + return ($this->_action==='allow') ? 1 : -1; |
|
| 211 | 211 | else |
| 212 | 212 | return 0; |
| 213 | 213 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | return 1; |
| 219 | 219 | foreach($this->_ipRules as $rule) |
| 220 | 220 | { |
| 221 | - if($rule === '*' || $rule === $ip || (($pos = strpos($rule, '*')) !== false && strncmp($ip, $rule, $pos) === 0)) |
|
| 221 | + if($rule==='*' || $rule===$ip || (($pos=strpos($rule, '*'))!==false && strncmp($ip, $rule, $pos)===0)) |
|
| 222 | 222 | return 1; |
| 223 | 223 | } |
| 224 | 224 | return 0; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | { |
| 234 | 234 | foreach($this->_roles as $role) |
| 235 | 235 | { |
| 236 | - if($role === '*' || $user->isInRole($role)) |
|
| 236 | + if($role==='*' || $user->isInRole($role)) |
|
| 237 | 237 | return true; |
| 238 | 238 | } |
| 239 | 239 | return false; |
@@ -241,6 +241,6 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | private function isVerbMatched($verb) |
| 243 | 243 | { |
| 244 | - return ($this->_verb === '*' || strcasecmp($verb, $this->_verb) === 0); |
|
| 244 | + return ($this->_verb==='*' || strcasecmp($verb, $this->_verb)===0); |
|
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | \ No newline at end of file |
@@ -40,12 +40,12 @@ discard block |
||
| 40 | 40 | * internal data storage |
| 41 | 41 | * @var array |
| 42 | 42 | */ |
| 43 | - private $_d = []; |
|
| 43 | + private $_d=[]; |
|
| 44 | 44 | /** |
| 45 | 45 | * number of items |
| 46 | 46 | * @var integer |
| 47 | 47 | */ |
| 48 | - private $_c = 0; |
|
| 48 | + private $_c=0; |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Constructor. |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | * @param array|Iterator the initial data. Default is null, meaning no initialization. |
| 54 | 54 | * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator. |
| 55 | 55 | */ |
| 56 | - public function __construct($data = null) |
|
| 56 | + public function __construct($data=null) |
|
| 57 | 57 | { |
| 58 | - if($data !== null) |
|
| 58 | + if($data!==null) |
|
| 59 | 59 | $this->copyFrom($data); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | $this->clear(); |
| 81 | 81 | foreach($data as $item) |
| 82 | 82 | { |
| 83 | - $this->_d[] = $item; |
|
| 83 | + $this->_d[]=$item; |
|
| 84 | 84 | ++$this->_c; |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | - elseif($data !== null) |
|
| 87 | + elseif($data!==null) |
|
| 88 | 88 | throw new TInvalidDataTypeException('stack_data_not_iterable'); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function clear() |
| 95 | 95 | { |
| 96 | - $this->_c = 0; |
|
| 97 | - $this->_d = []; |
|
| 96 | + $this->_c=0; |
|
| 97 | + $this->_d=[]; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function contains($item) |
| 105 | 105 | { |
| 106 | - return array_search($item, $this->_d, true) !== false; |
|
| 106 | + return array_search($item, $this->_d, true)!==false; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function peek() |
| 116 | 116 | { |
| 117 | - if($this->_c === 0) |
|
| 117 | + if($this->_c===0) |
|
| 118 | 118 | throw new TInvalidOperationException('stack_empty'); |
| 119 | 119 | else |
| 120 | 120 | return $this->_d[$this->_c - 1]; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function pop() |
| 129 | 129 | { |
| 130 | - if($this->_c === 0) |
|
| 130 | + if($this->_c===0) |
|
| 131 | 131 | throw new TInvalidOperationException('stack_empty'); |
| 132 | 132 | else |
| 133 | 133 | { |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | public function push($item) |
| 144 | 144 | { |
| 145 | 145 | ++$this->_c; |
| 146 | - $this->_d[] = $item; |
|
| 146 | + $this->_d[]=$item; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @var array internal data storage |
| 67 | 67 | */ |
| 68 | - private $_d = []; |
|
| 68 | + private $_d=[]; |
|
| 69 | 69 | /** |
| 70 | 70 | * @var boolean whether this list is read-only |
| 71 | 71 | */ |
| 72 | - private $_r = false; |
|
| 72 | + private $_r=false; |
|
| 73 | 73 | /** |
| 74 | 74 | * @var boolean indicates if the _d is currently ordered. |
| 75 | 75 | */ |
| 76 | - private $_o = false; |
|
| 76 | + private $_o=false; |
|
| 77 | 77 | /** |
| 78 | 78 | * @var array cached flattened internal data storage |
| 79 | 79 | */ |
@@ -81,15 +81,15 @@ discard block |
||
| 81 | 81 | /** |
| 82 | 82 | * @var integer number of items contain within the map |
| 83 | 83 | */ |
| 84 | - private $_c = 0; |
|
| 84 | + private $_c=0; |
|
| 85 | 85 | /** |
| 86 | 86 | * @var numeric the default priority of items without specified priorities |
| 87 | 87 | */ |
| 88 | - private $_dp = 10; |
|
| 88 | + private $_dp=10; |
|
| 89 | 89 | /** |
| 90 | 90 | * @var integer the precision of the numeric priorities within this priority list. |
| 91 | 91 | */ |
| 92 | - private $_p = 8; |
|
| 92 | + private $_p=8; |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * Constructor. |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | * @param integer the precision of the numeric priorities |
| 101 | 101 | * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator. |
| 102 | 102 | */ |
| 103 | - public function __construct($data = null, $readOnly = false, $defaultPriority = 10, $precision = 8) |
|
| 103 | + public function __construct($data=null, $readOnly=false, $defaultPriority=10, $precision=8) |
|
| 104 | 104 | { |
| 105 | - if($data !== null) |
|
| 105 | + if($data!==null) |
|
| 106 | 106 | $this->copyFrom($data); |
| 107 | 107 | $this->setReadOnly($readOnly); |
| 108 | 108 | $this->setPrecision($precision); |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | protected function setReadOnly($value) |
| 124 | 124 | { |
| 125 | - $this->_r = TPropertyValue::ensureBoolean($value); |
|
| 125 | + $this->_r=TPropertyValue::ensureBoolean($value); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | protected function setDefaultPriority($value) |
| 141 | 141 | { |
| 142 | - $this->_dp = (string)round(TPropertyValue::ensureFloat($value), $this->_p); |
|
| 142 | + $this->_dp=(string) round(TPropertyValue::ensureFloat($value), $this->_p); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function setPrecision($value) |
| 158 | 158 | { |
| 159 | - $this->_p = TPropertyValue::ensureInteger($value); |
|
| 159 | + $this->_p=TPropertyValue::ensureInteger($value); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | protected function sortPriorities() { |
| 177 | 177 | if(!$this->_o) { |
| 178 | 178 | ksort($this->_d, SORT_NUMERIC); |
| 179 | - $this->_o = true; |
|
| 179 | + $this->_o=true; |
|
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | return $this->_fd; |
| 190 | 190 | |
| 191 | 191 | $this->sortPriorities(); |
| 192 | - $this->_fd = []; |
|
| 192 | + $this->_fd=[]; |
|
| 193 | 193 | foreach($this->_d as $priority => $itemsatpriority) |
| 194 | - $this->_fd = array_merge($this->_fd, $itemsatpriority); |
|
| 194 | + $this->_fd=array_merge($this->_fd, $itemsatpriority); |
|
| 195 | 195 | return $this->_fd; |
| 196 | 196 | } |
| 197 | 197 | |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | * it will be set to the default {@link getDefaultPriority} |
| 220 | 220 | * @return integer the number of items in the map at the specified priority |
| 221 | 221 | */ |
| 222 | - public function getPriorityCount($priority = null) |
|
| 222 | + public function getPriorityCount($priority=null) |
|
| 223 | 223 | { |
| 224 | - if($priority === null) |
|
| 225 | - $priority = $this->getDefaultPriority(); |
|
| 226 | - $priority = (string)round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 224 | + if($priority===null) |
|
| 225 | + $priority=$this->getDefaultPriority(); |
|
| 226 | + $priority=(string) round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 227 | 227 | |
| 228 | 228 | if(!isset($this->_d[$priority]) || !is_array($this->_d[$priority])) |
| 229 | 229 | return false; |
@@ -257,16 +257,16 @@ discard block |
||
| 257 | 257 | * and numeric is a specific priority. default: false, any priority. |
| 258 | 258 | * @return mixed the element at the offset, null if no element is found at the offset |
| 259 | 259 | */ |
| 260 | - public function itemAt($key, $priority = false) |
|
| 260 | + public function itemAt($key, $priority=false) |
|
| 261 | 261 | { |
| 262 | - if($priority === false){ |
|
| 263 | - $map = $this->flattenPriorities(); |
|
| 264 | - return isset($map[$key])?$map[$key]:null; |
|
| 262 | + if($priority===false) { |
|
| 263 | + $map=$this->flattenPriorities(); |
|
| 264 | + return isset($map[$key]) ? $map[$key] : null; |
|
| 265 | 265 | } else { |
| 266 | - if($priority === null) |
|
| 267 | - $priority = $this->getDefaultPriority(); |
|
| 268 | - $priority = (string)round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 269 | - return (isset($this->_d[$priority]) && isset($this->_d[$priority][$key]))?$this->_d[$priority][$key]:null; |
|
| 266 | + if($priority===null) |
|
| 267 | + $priority=$this->getDefaultPriority(); |
|
| 268 | + $priority=(string) round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 269 | + return (isset($this->_d[$priority]) && isset($this->_d[$priority][$key])) ? $this->_d[$priority][$key] : null; |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | |
@@ -277,15 +277,15 @@ discard block |
||
| 277 | 277 | * @param numeric|null the priority. default: null, filled in with the default priority numeric. |
| 278 | 278 | * @return numeric old priority of the item |
| 279 | 279 | */ |
| 280 | - public function setPriorityAt($key, $priority = null) |
|
| 280 | + public function setPriorityAt($key, $priority=null) |
|
| 281 | 281 | { |
| 282 | - if($priority === null) |
|
| 283 | - $priority = $this->getDefaultPriority(); |
|
| 284 | - $priority = (string)round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 282 | + if($priority===null) |
|
| 283 | + $priority=$this->getDefaultPriority(); |
|
| 284 | + $priority=(string) round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 285 | 285 | |
| 286 | - $oldpriority = $this->priorityAt($key); |
|
| 287 | - if($oldpriority !== false && $oldpriority != $priority) { |
|
| 288 | - $value = $this->remove($key, $oldpriority); |
|
| 286 | + $oldpriority=$this->priorityAt($key); |
|
| 287 | + if($oldpriority!==false && $oldpriority!=$priority) { |
|
| 288 | + $value=$this->remove($key, $oldpriority); |
|
| 289 | 289 | $this->add($key, $value, $priority); |
| 290 | 290 | } |
| 291 | 291 | return $oldpriority; |
@@ -296,13 +296,13 @@ discard block |
||
| 296 | 296 | * @param numeric priority of the items to get. Defaults to null, filled in with the default priority, if left blank. |
| 297 | 297 | * @return array all items at priority in index order, null if there are no items at that priority |
| 298 | 298 | */ |
| 299 | - public function itemsAtPriority($priority = null) |
|
| 299 | + public function itemsAtPriority($priority=null) |
|
| 300 | 300 | { |
| 301 | - if($priority === null) |
|
| 302 | - $priority = $this->getDefaultPriority(); |
|
| 303 | - $priority = (string)round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 301 | + if($priority===null) |
|
| 302 | + $priority=$this->getDefaultPriority(); |
|
| 303 | + $priority=(string) round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 304 | 304 | |
| 305 | - return isset($this->_d[$priority])?$this->_d[$priority]:null; |
|
| 305 | + return isset($this->_d[$priority]) ? $this->_d[$priority] : null; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | { |
| 315 | 315 | $this->sortPriorities(); |
| 316 | 316 | foreach($this->_d as $priority => $items) |
| 317 | - if(($index = array_search($item, $items, true)) !== false) |
|
| 317 | + if(($index=array_search($item, $items, true))!==false) |
|
| 318 | 318 | return $priority; |
| 319 | 319 | return false; |
| 320 | 320 | } |
@@ -346,11 +346,11 @@ discard block |
||
| 346 | 346 | * @return numeric priority at which the pair was added |
| 347 | 347 | * @throws TInvalidOperationException if the map is read-only |
| 348 | 348 | */ |
| 349 | - public function add($key, $value, $priority = null) |
|
| 349 | + public function add($key, $value, $priority=null) |
|
| 350 | 350 | { |
| 351 | - if($priority === null) |
|
| 352 | - $priority = $this->getDefaultPriority(); |
|
| 353 | - $priority = (string)round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 351 | + if($priority===null) |
|
| 352 | + $priority=$this->getDefaultPriority(); |
|
| 353 | + $priority=(string) round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 354 | 354 | |
| 355 | 355 | if(!$this->_r) |
| 356 | 356 | { |
@@ -359,17 +359,17 @@ discard block |
||
| 359 | 359 | { |
| 360 | 360 | unset($this->_d[$innerpriority][$key]); |
| 361 | 361 | $this->_c--; |
| 362 | - if(count($this->_d[$innerpriority]) === 0) |
|
| 362 | + if(count($this->_d[$innerpriority])===0) |
|
| 363 | 363 | unset($this->_d[$innerpriority]); |
| 364 | 364 | } |
| 365 | 365 | if(!isset($this->_d[$priority])) { |
| 366 | - $this->_d[$priority] = [$key => $value]; |
|
| 367 | - $this->_o = false; |
|
| 366 | + $this->_d[$priority]=[$key => $value]; |
|
| 367 | + $this->_o=false; |
|
| 368 | 368 | } |
| 369 | 369 | else |
| 370 | - $this->_d[$priority][$key] = $value; |
|
| 370 | + $this->_d[$priority][$key]=$value; |
|
| 371 | 371 | $this->_c++; |
| 372 | - $this->_fd = null; |
|
| 372 | + $this->_fd=null; |
|
| 373 | 373 | } |
| 374 | 374 | else |
| 375 | 375 | throw new TInvalidOperationException('map_readonly', get_class($this)); |
@@ -388,45 +388,45 @@ discard block |
||
| 388 | 388 | * @return mixed the removed value, null if no such key exists. |
| 389 | 389 | * @throws TInvalidOperationException if the map is read-only |
| 390 | 390 | */ |
| 391 | - public function remove($key, $priority = false) |
|
| 391 | + public function remove($key, $priority=false) |
|
| 392 | 392 | { |
| 393 | 393 | if(!$this->_r) |
| 394 | 394 | { |
| 395 | - if($priority === null) |
|
| 396 | - $priority = $this->getDefaultPriority(); |
|
| 395 | + if($priority===null) |
|
| 396 | + $priority=$this->getDefaultPriority(); |
|
| 397 | 397 | |
| 398 | - if($priority === false) |
|
| 398 | + if($priority===false) |
|
| 399 | 399 | { |
| 400 | 400 | $this->sortPriorities(); |
| 401 | 401 | foreach($this->_d as $priority => $items) |
| 402 | 402 | if(array_key_exists($key, $items)) |
| 403 | 403 | { |
| 404 | - $value = $this->_d[$priority][$key]; |
|
| 404 | + $value=$this->_d[$priority][$key]; |
|
| 405 | 405 | unset($this->_d[$priority][$key]); |
| 406 | 406 | $this->_c--; |
| 407 | - if(count($this->_d[$priority]) === 0) |
|
| 407 | + if(count($this->_d[$priority])===0) |
|
| 408 | 408 | { |
| 409 | 409 | unset($this->_d[$priority]); |
| 410 | - $this->_o = false; |
|
| 410 | + $this->_o=false; |
|
| 411 | 411 | } |
| 412 | - $this->_fd = null; |
|
| 412 | + $this->_fd=null; |
|
| 413 | 413 | return $value; |
| 414 | 414 | } |
| 415 | 415 | return null; |
| 416 | 416 | } |
| 417 | 417 | else |
| 418 | 418 | { |
| 419 | - $priority = (string)round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 419 | + $priority=(string) round(TPropertyValue::ensureFloat($priority), $this->_p); |
|
| 420 | 420 | if(isset($this->_d[$priority]) && (isset($this->_d[$priority][$key]) || array_key_exists($key, $this->_d[$priority]))) |
| 421 | 421 | { |
| 422 | - $value = $this->_d[$priority][$key]; |
|
| 422 | + $value=$this->_d[$priority][$key]; |
|
| 423 | 423 | unset($this->_d[$priority][$key]); |
| 424 | 424 | $this->_c--; |
| 425 | - if(count($this->_d[$priority]) === 0) { |
|
| 425 | + if(count($this->_d[$priority])===0) { |
|
| 426 | 426 | unset($this->_d[$priority]); |
| 427 | - $this->_o = false; |
|
| 427 | + $this->_o=false; |
|
| 428 | 428 | } |
| 429 | - $this->_fd = null; |
|
| 429 | + $this->_fd=null; |
|
| 430 | 430 | return $value; |
| 431 | 431 | } |
| 432 | 432 | else |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | */ |
| 454 | 454 | public function contains($key) |
| 455 | 455 | { |
| 456 | - $map = $this->flattenPriorities(); |
|
| 456 | + $map=$this->flattenPriorities(); |
|
| 457 | 457 | return isset($map[$key]) || array_key_exists($key, $map); |
| 458 | 458 | } |
| 459 | 459 | |
@@ -475,15 +475,15 @@ discard block |
||
| 475 | 475 | * @return array the array of priorities keys with values of arrays of items that are below a specified priority. |
| 476 | 476 | * The priorities are sorted so important priorities, lower numerics, are first. |
| 477 | 477 | */ |
| 478 | - public function toArrayBelowPriority($priority, $inclusive = false) |
|
| 478 | + public function toArrayBelowPriority($priority, $inclusive=false) |
|
| 479 | 479 | { |
| 480 | 480 | $this->sortPriorities(); |
| 481 | - $items = []; |
|
| 481 | + $items=[]; |
|
| 482 | 482 | foreach($this->_d as $itemspriority => $itemsatpriority) |
| 483 | 483 | { |
| 484 | 484 | if((!$inclusive && $itemspriority >= $priority) || $itemspriority > $priority) |
| 485 | 485 | break; |
| 486 | - $items = array_merge($items, $itemsatpriority); |
|
| 486 | + $items=array_merge($items, $itemsatpriority); |
|
| 487 | 487 | } |
| 488 | 488 | return $items; |
| 489 | 489 | } |
@@ -495,15 +495,15 @@ discard block |
||
| 495 | 495 | * @return array the array of priorities keys with values of arrays of items that are above a specified priority. |
| 496 | 496 | * The priorities are sorted so important priorities, lower numerics, are first. |
| 497 | 497 | */ |
| 498 | - public function toArrayAbovePriority($priority, $inclusive = true) |
|
| 498 | + public function toArrayAbovePriority($priority, $inclusive=true) |
|
| 499 | 499 | { |
| 500 | 500 | $this->sortPriorities(); |
| 501 | - $items = []; |
|
| 501 | + $items=[]; |
|
| 502 | 502 | foreach($this->_d as $itemspriority => $itemsatpriority) |
| 503 | 503 | { |
| 504 | 504 | if((!$inclusive && $itemspriority <= $priority) || $itemspriority < $priority) |
| 505 | 505 | continue; |
| 506 | - $items = array_merge($items, $itemsatpriority); |
|
| 506 | + $items=array_merge($items, $itemsatpriority); |
|
| 507 | 507 | } |
| 508 | 508 | return $items; |
| 509 | 509 | } |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | foreach($data as $key => $value) |
| 535 | 535 | $this->add($key, $value); |
| 536 | 536 | } |
| 537 | - elseif($data !== null) |
|
| 537 | + elseif($data!==null) |
|
| 538 | 538 | throw new TInvalidDataTypeException('map_data_not_iterable'); |
| 539 | 539 | } |
| 540 | 540 | |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | foreach($data as $key => $value) |
| 561 | 561 | $this->add($key, $value); |
| 562 | 562 | } |
| 563 | - elseif($data !== null) |
|
| 563 | + elseif($data!==null) |
|
| 564 | 564 | throw new TInvalidDataTypeException('map_data_not_iterable'); |
| 565 | 565 | } |
| 566 | 566 | |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * If -1, the item will be appended to the end. |
| 36 | 36 | * @return TListItem list item object |
| 37 | 37 | */ |
| 38 | - public function createListItem($index = -1) |
|
| 38 | + public function createListItem($index=-1) |
|
| 39 | 39 | { |
| 40 | - $item = $this->createNewListItem(); |
|
| 40 | + $item=$this->createNewListItem(); |
|
| 41 | 41 | if($index < 0) |
| 42 | 42 | $this->add($item); |
| 43 | 43 | else |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | /** |
| 49 | 49 | * @return TListItem new item. |
| 50 | 50 | */ |
| 51 | - protected function createNewListItem($text = null) |
|
| 51 | + protected function createNewListItem($text=null) |
|
| 52 | 52 | { |
| 53 | - $item = new TListItem; |
|
| 54 | - if($text !== null) |
|
| 53 | + $item=new TListItem; |
|
| 54 | + if($text!==null) |
|
| 55 | 55 | $item->setText($text); |
| 56 | 56 | return $item; |
| 57 | 57 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public function insertAt($index, $item) |
| 67 | 67 | { |
| 68 | 68 | if(is_string($item)) |
| 69 | - $item = $this->createNewListItem($item); |
|
| 69 | + $item=$this->createNewListItem($item); |
|
| 70 | 70 | if(!($item instanceof TListItem)) |
| 71 | 71 | throw new TInvalidDataTypeException('listitemcollection_item_invalid', get_class($this)); |
| 72 | 72 | parent::insertAt($index, $item); |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | * @param boolean whether to look for disabled items also |
| 79 | 79 | * @return integer the index of the item found, -1 if not found. |
| 80 | 80 | */ |
| 81 | - public function findIndexByValue($value, $includeDisabled = true) |
|
| 81 | + public function findIndexByValue($value, $includeDisabled=true) |
|
| 82 | 82 | { |
| 83 | - $value = TPropertyValue::ensureString($value); |
|
| 84 | - $index = 0; |
|
| 83 | + $value=TPropertyValue::ensureString($value); |
|
| 84 | + $index=0; |
|
| 85 | 85 | foreach($this as $item) |
| 86 | 86 | { |
| 87 | - if($item->getValue() === $value && ($includeDisabled || $item->getEnabled())) |
|
| 87 | + if($item->getValue()===$value && ($includeDisabled || $item->getEnabled())) |
|
| 88 | 88 | return $index; |
| 89 | 89 | $index++; |
| 90 | 90 | } |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | * @param boolean whether to look for disabled items also |
| 98 | 98 | * @return integer the index of the item found, -1 if not found. |
| 99 | 99 | */ |
| 100 | - public function findIndexByText($text, $includeDisabled = true) |
|
| 100 | + public function findIndexByText($text, $includeDisabled=true) |
|
| 101 | 101 | { |
| 102 | - $text = TPropertyValue::ensureString($text); |
|
| 103 | - $index = 0; |
|
| 102 | + $text=TPropertyValue::ensureString($text); |
|
| 103 | + $index=0; |
|
| 104 | 104 | foreach($this as $item) |
| 105 | 105 | { |
| 106 | - if($item->getText() === $text && ($includeDisabled || $item->getEnabled())) |
|
| 106 | + if($item->getText()===$text && ($includeDisabled || $item->getEnabled())) |
|
| 107 | 107 | return $index; |
| 108 | 108 | $index++; |
| 109 | 109 | } |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * @param boolean whether to look for disabled items also |
| 117 | 117 | * @return TListItem the item found, null if not found. |
| 118 | 118 | */ |
| 119 | - public function findItemByValue($value, $includeDisabled = true) |
|
| 119 | + public function findItemByValue($value, $includeDisabled=true) |
|
| 120 | 120 | { |
| 121 | - if(($index = $this->findIndexByValue($value, $includeDisabled)) >= 0) |
|
| 121 | + if(($index=$this->findIndexByValue($value, $includeDisabled)) >= 0) |
|
| 122 | 122 | return $this->itemAt($index); |
| 123 | 123 | else |
| 124 | 124 | return null; |
@@ -130,9 +130,9 @@ discard block |
||
| 130 | 130 | * @param boolean whether to look for disabled items also |
| 131 | 131 | * @return TListItem the item found, null if not found. |
| 132 | 132 | */ |
| 133 | - public function findItemByText($text, $includeDisabled = true) |
|
| 133 | + public function findItemByText($text, $includeDisabled=true) |
|
| 134 | 134 | { |
| 135 | - if(($index = $this->findIndexByText($text, $includeDisabled)) >= 0) |
|
| 135 | + if(($index=$this->findIndexByText($text, $includeDisabled)) >= 0) |
|
| 136 | 136 | return $this->itemAt($index); |
| 137 | 137 | else |
| 138 | 138 | return null; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | public function loadState($state) |
| 147 | 147 | { |
| 148 | 148 | $this->clear(); |
| 149 | - if($state !== null) |
|
| 149 | + if($state!==null) |
|
| 150 | 150 | $this->copyFrom($state); |
| 151 | 151 | } |
| 152 | 152 | |