So my brain of mine is not present enough to both read and understand what is said on http://se2.php.net/lsb. But I can assure that some late, restless night I will study that page into oblivion. Until then I have a questions about the code you posted.
I first want to figure out what the code is doing. I hope to pick at it until i am comfortable I understand what going on. Unfortunately the code does not execute. I have found a few errors but I am now stuck. Below is what I have found so far. The ode generates an error at line 16. Says that isValid is undefined. I cant figure out why.
function word was missing from the original code and so was the $ at line 3. private static $buttons
I also have a question, the code you posted. Is the read and write static? As in once it is set can I not change it as need be. Some buttons may require a lower accesslevel.
Anyway, thank you for your patience.
<?php
class Button{
private static $buttons = array('register' => array('read' => 0, 'write' => 0, 'value' => 'Submit'),'edit_post' => array('read' => 10, 'write' => 100, 'value' => 'Update'));
public static function isValid($name){
return in_array(self::$buttons);
}
public static function canRead($name, $userPriv) {
if(!isValid($name))
return false; // possibly throwing exception or error logging might be an idea.
return self::$buttons[$name]['read'] <= $userPriv;
}
public static function canWrite($name, $userPriv) {
if(!isValid($name))
return false; // possibly throwing exception or error logging might be an idea.
return self::$buttons[$name]['write'] <= $userPriv;
}
// if you're using XHTML close input with /> instead of >
public static function display($name, $userPriv) {
if(self::canWrite($name, $userPriv))
echo '<input type="button" name="'.$name.'" value="'.self::$buttons[$name]['value'].'"/>';
else if (self::canRead($name, $userPriv))
echo '<input type="button" name="'.$name.'" value="'.self::$buttons[$name]['value'].'" disabled="disabled"/>';
return true;
}
// if you're using XHTML close input with /> instead of >
public static function fetch($name, $userPriv) {
if (self::canWrite($name, $userPriv))
return '<input type="button" name="'.$name.'" value="'.self::$buttons[$name]['value'].'"/>';
else if (self::canRead($name, $userPriv))
return '<input type="button" name="'.$name.'" value="'.self::$buttons[$name]['value'].'" disabled="disabled"/>';
}
}
Button::display('this_is_a_name',40);