public function render() { if ($this->callback) { $callback = Callback::prepare($this->callback); is_callable($callback) && $this->setValues(call_user_func($callback)); } $this->getAttributes(); $code[] = HTML::open_tag('select', $this->attributes); foreach ($this->values as $key => $value) { $attributes = array(); if ($key == $this->value) { $attributes['selected'] = 'selected'; } $attributes['value'] = $key; $code[] = HTML::paired_tag('option', $value, $attributes); } $code[] = HTML::close_tag('select'); $code = implode("\n", $code); if ($this->wrapper) { $tpl = new Template($this->wrapper); $tpl->assign($this->attributes); $tpl->code = $code; $code = $tpl->render(); } return $code; }
/** * Check callback to be callable * * @return string */ public function check() { return Callback::prepare($this->callback) ? TRUE : FALSE; }
/** * Run dispatched request */ public function run() { if ($this->has_run) { return; } $cogear = getInstance(); foreach ($this->routes as $route => $callback) { $route = str_replace($this->rules['from'], $this->rules['to'], $route); $clean_route = $route; if (strpos($route, '^') === FALSE) { $route = '^' . $route; } if (strpos($route, '$') === FALSE) { $route .= '$'; } $regexp = '#' . $route . '#isU'; if (preg_match($regexp, $this->uri, $this->matches)) { $args = array(); if (is_array($callback) && sizeof($callback) > 2) { $args = array_slice($callback, 2); $callback = array($callback[0], $callback[1]); } $root = trim(substr($clean_route, 0, strpos($clean_route, '(')), self::DELIM); $exclude = strpos($root, self::DELIM) ? preg_split(self::DELIM, $root, -1, PREG_SPLIT_NO_EMPTY) : (array) $root; $this->args = array_merge($args, array_diff_assoc($this->segments, $exclude)); // We have a nice method in hooks to prepare callback if ($callback = Callback::prepare($callback)) { $this->callback = $callback; event('callback.before', $this); event('callback.' . get_class($callback[0]) . '.before', $this); method_exists($callback[0], 'request') && call_user_func_array(array($callback[0], 'request'), $this->args); call_user_func_array($callback, $this->args); $this->has_run = TRUE; event('callback.' . get_class($callback[0]) . '.after', $this); event('callback.after', $this); return; } } } $this->exec(array($cogear->errors, '_404')); return; }