예제 #1
0
파일: TestBean.php 프로젝트: justinlyon/scc
 function testDemoBean()
 {
     $bean = new DemoBean();
     // defined in BaseBean file
     // Java style methods
     $bean->setDemo('v1');
     $this->assertEqual($bean->getDemo(), 'v1');
     // PHP style methods
     $bean->set_demo('v2');
     $this->assertEqual($bean->get_demo(), 'v2');
     // direct access (not recommended)
     $bean->demo = 'v3';
     $this->assertEqual($bean->demo, 'v3');
     $this->assertError($bean->testUnknown());
 }
예제 #2
0
파일: BaseBean.php 프로젝트: justinlyon/scc
     *
     * @param $hdr True to include a header row with the resulting HTML
     * @return An HTML string containing the bean attribute values
     */
    public function toHtml($hdr = false)
    {
        $header = $detail = '<tr>';
        $map = get_object_vars($this);
        foreach ($map as $label => $value) {
            if ($hdr) {
                $header .= "<th>{$label}</th>";
            }
            $detail .= "<td>{$value}</td>";
        }
        $result = $hdr ? "{$header}</tr>" : '';
        $result .= "{$detail}</tr>";
    }
}
/**
 * Subclass to demonstrate usage and initialization for bean classes.
 */
class DemoBean extends BaseBean
{
    var $demo;
}
// Usage example
$bean = new DemoBean();
$bean->setDemo(true);
// Java style
assert($bean->get_demo());
// PHP style