/** * Get link to a dynamic asset. * @param array|Linkable|string|null $route A route, see {@see \Jivoo\Routing\Routing}. * @return string|null Link to asset, or null if not found. */ public function getDynamicAsset($route) { $route = $this->m->Routing->validateRoute($route); if ($route['dispatcher'] instanceof ActionDispatcher) { $path = array_map(array('Jivoo\\Core\\Utilities', 'camelCaseToDashes'), explode('\\', $route['controller'])); $path[] = str_replace('_', '.', Utilities::camelCaseToDashes($route['action'])); } else { if ($route['dispatcher'] instanceof SnippetDispatcher) { $path = explode('\\', str_replace('_', '.', $route['snippet'])); $path = array_map(array('Jivoo\\Core\\Utilities', 'camelCaseToDashes'), $path); } else { return null; } } $suffix = ''; // if ($this->config['mtimeSuffix']) // $suffix = '?' . filemtime($file); return $this->m->Routing->getLinkFromPath(array_merge(array('assets'), $path), $route['query'], $route['fragment']) . $suffix; }
/** * Render a template. * * If $templateName is not set, the path of the template will be computed * based on the name of the controller and the name of the action. * * @param string $templateName Name of template to render. * @return ViewResponse A view response for template. */ protected function render($templateName = null) { if (!$this->response instanceof ViewResponse) { $response = $this->response; $this->response = new ViewResponse(Http::OK, $this->view); return $response; } if (!isset($templateName)) { list(, $caller) = debug_backtrace(false); $class = str_replace($this->app->n('Controllers\\'), '', $caller['class']); $class = preg_replace('/Controller$/', '', $class); $templateName = ''; if ($class != 'App') { $dirs = array_map(array('Jivoo\\Core\\Utilities', 'camelCaseToDashes'), explode('\\', $class)); $templateName = implode('/', $dirs) . '/'; } $type = 'html'; $action = $caller['function']; if (strpos($action, '_') !== false and preg_match('/^(.*)_([a-z0-9]+)$/i', $action, $matches) === 1) { $action = $matches[1]; $type = $matches[2]; } $templateName .= Utilities::camelCaseToDashes($action) . '.' . $type; } $this->response->template = $templateName; $response = $this->response; $this->response = new ViewResponse(Http::OK, $this->view); return $response; }
/** * Declaration getter. * @param string $property Property in camelCase, e.g. backgroundColor, * fontFamily, etc. * @return string|array Value. */ public function __get($property) { $property = Utilities::camelCaseToDashes($property); if (isset($this->declarations[$property])) { return $this->declarations[$property]; } return null; }
/** * {@inheritdoc} */ protected function render($templateName = null) { if (!isset($templateName)) { list(, $caller) = debug_backtrace(false); $class = str_replace($this->app->n('Snippets\\'), '', $caller['class']); $dirs = array_map(array('Jivoo\\Core\\Utilities', 'camelCaseToDashes'), explode('\\', $class)); $templateName = implode('/', $dirs) . '/'; $templateName .= Utilities::camelCaseToDashes($caller['function']) . '.html'; } return parent::render($templateName); }
/** * {@inheritdoc} */ public function autoRoute(RoutingTable $table, $route, $resource = false) { $controller = $route['controller']; $dirs = explode('\\', $controller); if ($dirs == array('App')) { $dirs = array(); } else { $dirs = array_map(array('Jivoo\\Core\\Utilities', 'camelCaseToDashes'), $dirs); } $patternBase = implode('/', $dirs); if ($resource) { $table->match($patternBase, 'action:' . $controller . '::index'); $table->match($patternBase . '/add', 'action:' . $controller . '::add'); //C $table->match($patternBase . '/:0', 'action:' . $controller . '::view'); //R $table->match($patternBase . '/:0/edit', 'action:' . $controller . '::edit'); //U $table->match($patternBase . '/:0/delete', 'action:' . $controller . '::delete'); //D $table->match('DELETE ' . $patternBase . '/:0', 'action:' . $controller . '::delete'); $table->match('PATCH ' . $patternBase . '/:0', 'action:' . $controller . '::edit'); $table->match('PUT ' . $patternBase . '/:0', 'action:' . $controller . '::edit'); $table->match('POST ' . $patternBase, 'action:' . $controller . '::add'); return $patternBase . '/:0'; } else { if (isset($route['action'])) { $action = $route['action']; $class = $this->getClass($controller); if (!$class) { throw new InvalidClassException(tr('Invalid controller: %1', $controller)); } $route = array('controller' => $controller, 'action' => $action); $reflect = new \ReflectionMethod($class, $action); $required = $reflect->getNumberOfRequiredParameters(); $total = $reflect->getNumberOfParameters(); if (!empty($prefix) and substr($prefix, -1) != '/') { $prefix .= '/'; } if ($action == 'index') { $table->match($patternBase, $route); } $patternBase .= '/' . str_replace('_', '.', Utilities::camelCaseToDashes($action)); if ($required < 1) { $table->match($patternBase, $route); } $path = $patternBase; for ($i = 0; $i < $total; $i++) { $path .= '/*'; if ($i <= $required) { $table->match($path, $route); } } return $patternBase; } else { $actions = $this->getActions($controller); if ($actions === false) { throw new InvalidClassException(tr('Invalid controller: %1', $controller)); } foreach ($actions as $action) { $route['action'] = $action; $this->autoRoute($table, $route, false); } return $patternBase; } } }
/** * Render a template. Will look for template in the extension directory. * * @param string $templateName Name of template to render, uses name of class * if not specified. * @return ViewResponse A view response. */ protected function render($templateName = null) { list($key, $path) = $this->info->getKeyPath(); $this->view->addTemplateDir($key, $path, 4); if (!isset($templateName)) { $templateName = Utilities::camelCaseToDashes(get_class($this)) . '.html'; } return $this->view->renderOnly($templateName); }