Created
October 22, 2013 07:38
-
-
Save anytizer/7096589 to your computer and use it in GitHub Desktop.
Fixed parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Controlled way of handling parameter names. | |
* The script cannot add or read new parameters dynamically. | |
*/ | |
abstract class FixedParameters | |
{ | |
/** | |
* Does not allow the script to modify set of parameters later on. | |
*/ | |
public function __set($key='', $value='') | |
{ | |
if(property_exists($this, $key)) | |
{ | |
$this->$key = $value; | |
} | |
else | |
{ | |
throw new Exception('Cannot set value of an undefined key ({$key}).'); | |
} | |
} | |
/** | |
* Does not allow to read the undefined parameters | |
*/ | |
public function __get($key='') | |
{ | |
if(!property_exists($this, $key)) | |
{ | |
throw new Exception("Cannot read undefined key ({$key})."); | |
} | |
return $this->$key; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment