/** * Set the error handler sets * * @return void */ public function __construct() { $config = Load::factory('Config')->error; if (!in_array('Error', Tk::$helper)) { Tk::instance()->Load->helper('error'); } if (array_key_exists('reporting', $config)) { set_error_handler('error_handler', $config['reporting']); error_reporting($config['reporting']); } set_exception_handler('exception_handler'); }
#!/usr/local/bin/php -q <?php //ini_set('memory_limit', '-1'); dl('tk.so'); $root = new Tk(); $root->wmTitle('"Hello World"'); $label = new Label($root, '-text "Hello, world!"'); $label->pack('-side left', '-padx 15', '-pady 15'); Tk_MainLoop();
if (!file_exists($path . $module)) { $module = $this->Config->module['error_module']; } //add specific routing rules ;D if (file_exists("{$path}{$module}/route" . Tk::$ext)) { $this->import("{$path}{$module}/route" . Tk::$ext); } //verify action information $action = isset($_GET['action']) && !empty($_GET['action']) ? $_GET['action'] : $module; $prefix = isset($this->Config->prefix['action']) ? $this->Config->prefix['action'] : ''; $file = "{$path}{$module}/{$prefix}{$action}" . Tk::$ext; if (!file_exists($file)) { $module = $this->Config->module['error_module']; $action = $prefix . $module; $file = "{$path}{$module}/{$action}" . Tk::$ext; } $_GET['module'] = $module; $_GET['action'] = $action; //verify if there is an init module $init_module = "{$path}{$this->Config->module['init_module']}/{$this->Config->module['init_filename']}" . Tk::$ext; if (file_exists($init_module)) { Tk::import($init_module); } //verify if there is an init file $init_file = "{$path}{$module}/init" . Tk::$ext; if (file_exists($init_file)) { $this->import($init_file); } $this->import($file); $this->Template->add_html($this->Config->template['content_div'], $this->Output->get_buffer()); $this->Template->render();
/** * Sets an instance of Tk object * * @return void */ public function __construct() { self::$Tk = Tk::instance(); }
/** * Run the validation based on the $this->rules list * * @param array $data * @param array $rules * @return boolean */ public function validate($data, $rules = array()) { if (!is_array($data) || empty($data)) { return false; } if (!empty($rules)) { $this->rules = $rules; } Tk::instance()->Load->helper('validation'); //keeps the results of the validation $result = array(); //determine if the ruel is a callback if there is an extra parameter $param = false; foreach ($data as $field => $value) { //keep the raw value of the field $this->values[$field] = $value; if (array_key_exists($field, $this->rules)) { $rules = explode('|', $this->rules[$field]); if (!in_array('required', $rules) && (empty($value) || is_null($value))) { $this->sanitized_result[$field] = $value; continue; } foreach ($rules as $rule) { $param = false; if (preg_match("/(.*?)\\[(.*?)\\]/", $rule, $match)) { $rule = $match[1]; $param = $match[2]; } if (function_exists($rule)) { $r = $rule($value, $param); if ($r == false) { $this->result[$field] = false; } else { $this->sanitized_result[$field] = $r; } } } if (isset($this->result[$field])) { $this->error_string .= isset($this->messages) && array_key_exists($field, $this->messages) ? "<li>{$this->messages[$field]}</li>" : "<li>{$field} invalid</li>"; $this->errors[$field] = array_key_exists($field, $this->messages) ? $this->messages[$field] : "{$field} invalid"; } } } $this->error_string = !empty($this->error_string) ? "<ul>{$this->error_string}</ul>" : ''; return !empty($this->result) ? false : true; }
/** * Method to obtain an instance of the object * * @return object */ public static function instance() { if (!isset(Tk::$instance)) { self::$instance = new Tk(); } return self::$instance; }