public function handle($request, $response, $template) { $now = new DateTime(); $time = $now->format(DateTime::RFC850); $trace = TextUtil::tabify($this->getTraceAsString(), 1); $request = $request ? TextUtil::tabify($request, 1) : '(No request information)'; $response = $response ? TextUtil::tabify($response, 1) : '(No response information)'; $view = new View($request, $response); $view->setDecorator($template); $this->message = <<<EOT {$this->message} * Time: {$time} * File: {$this->file} * Line: {$this->line} * Trace: \t{$trace} * Request: \t{$request} * Response: \t{$response} EOT; if (Config::get('development')) { $this->message = "<pre>{$this->message}</pre>"; $view->setText($this->message); } else { Mail::send(Config::get('developers'), 'Application error', $this->message, Mail::PRIORITY_HIGH); $view->setText('An email has been sent to the developers to resolve the issue.' . ' Thank you.'); } $view->render(); $view->show(); }
/** * Constructs a widget * @static * @param string $cog_dashed cog name with dashes instead of uppercased chars (ex: 'user') * @param string $widget_dashed widget name with dashes (ex: 'option-panel') * @param array $params parameters to pass to the widget * @return Cognosys\Widget */ public static function factory($cog_dashed, $widget_dashed, $params = array()) { $cogname = TextUtil::classify($cog_dashed); $widget_class = TextUtil::classify($widget_dashed); $widget_class = "App\\Cogs\\{$cogname}\\Widgets\\{$widget_class}"; return new $widget_class($cogname, $widget_dashed, $params); }
/** * @param string|Closure $content */ public function render($content) { if ($content === null) { $content = TextUtil::humanize($this->for); } elseif ($content instanceof Closure) { //FIXME: closure should receive a FormTag ob_start(); $content(); $content = ob_get_clean(); } return "<label {$this->getAttributes()}>{$content}</label>"; }
public static function forController($request, $response) { $view = new static(); $view->_request = $request; $view->_response = $response; if ($response instanceof Response) { $cog = $response->cog(); $controller = $response->originalController(); $action = $response->action(); $view->setPath(COGS . "{$cog}/Views/{$controller}/"); $view->setFile(TextUtil::dasherize($action)); } return $view; }
/** * Test the validity of a model * @final * @param Cognosys\Model $model * @return bool */ protected final function valid(Model $model) { $model->validate(); $errors = Validator::get(); AlertManager::import($errors); $metadata = $this->getClassMetadata(get_class($model)); foreach ($metadata->associationMappings as $assoc) { $method = TextUtil::camelize($assoc['fieldName']); if (is_numeric($model->{$method}()) && $model->{$method}() > 0) { // transform the identifier to the entity $model->{$method}($this->getReference($assoc['targetEntity'], $model->{$method}())); $this->persist($model->{$method}()); } } return empty($errors); }
public function button($field, $value = null, $params = array()) { ++$this->_btn_count; if ($value === null) { $value = TextUtil::humanize($field); } return $this->input('button', $field . $this->_btn_count, array_merge(array('value' => $value), $params)); }
/** * Renames controller and action * @return void */ private function _renameProperties() { $this->_original_controller = $this->_controller; $this->_controller = $this->_controller === null ? 'IndexController' : ucfirst(TextUtil::camelize($this->_controller)) . 'Controller'; $this->_action = $this->_action === null ? 'index' : TextUtil::camelize($this->_action); }