00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009 class DelegateCommandImpl extends CommandDelegate {
00010 public function __construct($op, $obj, $params) {
00011 $delegate = null;
00012
00013 $delegate_directory = dirname(dirname(__FILE__));
00014 $obj_name = $this->get_obj_name($obj);
00015 $file_name = implode('.', array($op, $obj_name, 'cmd.php'));
00016 $file_path = implode('/', array($delegate_directory, $obj_name, $file_name));
00017 if (file_exists($file_path)) {
00018 require_once($file_path);
00019 $func = 'create_' . $op . $obj_name . '_command';
00020 if (function_exists($func)) {
00021 $delegate = $func($params, $obj);
00022 }
00023 }
00024
00025 parent::__construct($delegate);
00026 }
00027
00028 protected function get_obj_name($obj) {
00029 $ret = false;
00030 if (is_object($obj)) {
00031 if (method_exists($obj, 'tableName')) {
00032 $ret = $obj->tableName();
00033 }
00034 else {
00035 $ret = get_class($obj);
00036 }
00037 }
00038 else {
00039 $ret = basename((string)$obj);
00040 }
00041 return $ret;
00042 }
00043 }
00044 ?>