public function generate($name, $colDefs = array()) { if (empty($colDefs)) { $tableName = Inflector::tableize($name); $datasource = ConnectionManager::getDataSource(); $attributes = $datasource->generateAttributeMapFromTable($tableName); } else { $columns = Migration::parseColumnDefinitions($colDefs); $names = array_map(function ($col) { return $col['name']; }, $columns); $types = array_map(function ($col) { return $col['type']; }, $columns); $attributes = array_combine($names, $types); } $templates = array('add', 'edit', 'index', 'view'); $vars = array('attributes' => $attributes, 'friendlyModelName' => Inflector::humanize(Inflector::classify($name)), 'modelVarName' => Inflector::lowerCamelize(Inflector::classify(Inflector::singularize($name))), 'pluralModelVarName' => Inflector::lowerCamelize(Inflector::pluralize($name)), 'controller' => Inflector::tableize($name)); foreach ($templates as $template) { $data = $this->_renderTemplate("views/{$template}", $vars, true); $folder = Inflector::tableize($name); $this->_writeFile("/views/{$folder}/{$template}.html.tpl", $data); } }
public function generate($name) { $vars = array('controller_name' => Inflector::tableize($name), 'controller_class' => Inflector::camelize(Inflector::tableize($name) . '_controller'), 'model_name' => Inflector::underscore(Inflector::singularize($name)), 'model_class' => Inflector::classify($name), 'model_var_name' => Inflector::lowerCamelize(Inflector::classify($name)), 'model_var_plural_name' => Inflector::lowerCamelize(Inflector::tableize($name)), 'friendly_model_name' => Inflector::humanize(Inflector::singularize($name)), 'friendly_controller_name' => Inflector::humanize(Inflector::tableize($name)), 'package_name' => 'App', 'year' => date('Y')); $data = $this->_renderTemplate('controller', $vars); $this->_writeFile('/controllers/' . $vars['controller_class'] . '.php', $data); }
public static function parseUrl($url, Request $request = null) { if ($params = self::_parseUrl($url, $request)) { $defaults = array('action' => 'index', 'extension' => 'html', 'namespace' => false, 'args' => array()); $params += $defaults; $params['action_method'] = Inflector::lowerCamelize($params['action']) . 'Action'; $params['controller_class'] = Inflector::camelize($params['controller']) . 'Controller'; return $params; } return $params; }
/** * Renders the current action */ public function render() { $this->set('rox_page_title', $this->pageTitle); foreach ($this->helpers as $helper) { $helperName = Inflector::lowerCamelize($helper); $this->set($helperName, Rox::getHelper($helper)); } $viewPath = $this->params['controller']; if (!empty($this->params['namespace'])) { $simpleControllerName = substr($this->params['controller'], strlen($this->params['namespace']) + 1); $viewPath = $this->params['namespace'] . '/' . $simpleControllerName; } $viewName = $this->params['action']; $view = new \rox\template\View($this->_viewVars); $view->response = $this->response; $view->params = $this->params; $this->response->body = $view->render($viewPath, $viewName, $this->layout); }
protected function _generateViews($name) { $tableName = Inflector::tableize($name); $datasource = ConnectionManager::getDataSource(); $attributes = $datasource->generateAttributeMapFromTable($tableName); $templates = array('add', 'edit', 'index', 'view'); $vars = array( 'attributes' => $attributes, 'friendlyModelName' => Inflector::humanize(Inflector::classify($name)), 'modelVarName' => Inflector::lowerCamelize(Inflector::classify(Inflector::singularize($name))), 'pluralModelVarName' => Inflector::lowerCamelize(Inflector::pluralize($name)), 'controller' => Inflector::tableize($name) ); foreach ($templates as $template) { $data = $this->_renderTemplate("views/{$template}", $vars, true); $folder = Inflector::tableize($name); $this->_writeFile("/views/{$folder}/{$template}.html.tpl", $data); } }
/** * Mailer::send() * * @param string $mailerAndEmail * @param ... * @return mixed */ public static function send($mailerAndEmail) { if (strpos($mailerAndEmail, '.') == false) { throw new Exception('mailer and email should be separated by a period.'); } list($mailer, $email) = explode('.', $mailerAndEmail); $mailerClass = Inflector::camelize($mailer . '_mailer'); $emailMethod = Inflector::lowerCamelize($email); $args = array_slice(func_get_args(), 1); $mailerInstance = new $mailerClass(); $mailerInstance->params = array('mailer' => $mailer, 'mailer_class' => $mailerClass, 'email' => $email, 'email_method' => $emailMethod); call_user_func_array(array($mailerInstance, $emailMethod), $args); return $mailerInstance->_send(); }