function init($modelClassName, $relationshipName) { $this->localClass = $modelClassName; $this->name = $relationshipName; $this->onDelete = Relationship::NULLIFY; $this->foreignKey = Inflector::toCamelCaps($relationshipName) . 'Id'; $this->foreignClass = Inflector::toProperCaps($relationshipName); }
function init($modelClassName, $relationshipName) { $this->localClass = $modelClassName; $this->name = $relationshipName; $this->foreignKey = Inflector::toCamelCaps($modelClassName) . 'Id'; $this->foreignClass = Inflector::toSingular(Inflector::toProperCaps($relationshipName)); $this->onDelete = Relationship::UNSPECIFIED; }
/** !Route GET, $app/model/$model/scaffolding */ public function generateScaffolding($app, $model) { $app = new $app(); if (strpos($app->controllersPrefix, 'recess.apps.') !== false) { $base = $_ENV['dir.recess']; } else { $base = $_ENV['dir.apps']; } Library::import('recess.lang.Inflector'); $controllersDir = $base . str_replace(Library::dotSeparator, Library::pathSeparator, $app->controllersPrefix); $viewsDir = $app->viewsDir; Library::import($app->modelsPrefix . $model); $replacements = array('modelName' => $model, 'modelNameLower' => Inflector::toCamelCaps($model), 'fullyQualifiedModel' => $app->modelsPrefix . $model, 'primaryKey' => Model::primaryKeyName($model), 'viewsPrefix' => Inflector::toCamelCaps($model), 'routesPrefix' => Inflector::toCamelCaps($model)); $this->messages[] = $this->tryGeneratingFile('RESTful ' . $model . ' Controller', $this->application->codeTemplatesDir . 'scaffolding/controllers/ResourceController.template.php', $controllersDir . $model . 'Controller.class.php', $replacements); $indexFieldTemplate = $this->getTemplate($this->application->codeTemplatesDir . 'scaffolding/views/resource/indexField.template.php'); $indexDateFieldTemplate = $this->getTemplate($this->application->codeTemplatesDir . 'scaffolding/views/resource/indexDateField.template.php'); $editFormInputTemplate = $this->getTemplate($this->application->codeTemplatesDir . 'scaffolding/views/resource/editFormInput.template.php'); $indexFields = ''; $formFields = ''; foreach (Model::getProperties($model) as $property) { if ($property->isPrimaryKey) { continue; } $values = array('fieldName' => $property->name, 'primaryKey' => Model::primaryKeyName($model), 'modelName' => $model, 'modelNameLower' => Inflector::toCamelCaps($model), 'fieldNameEnglish' => Inflector::toEnglish($property->name)); switch ($property->type) { case RecessType::DATE: case RecessType::DATETIME: case RecessType::TIME: case RecessType::TIMESTAMP: $template = $indexDateFieldTemplate; break; default: $template = $indexFieldTemplate; break; } $formFields .= $this->fillTemplate($editFormInputTemplate, $values); $indexFields .= $this->fillTemplate($template, $values); } $replacements['fields'] = $indexFields; $replacements['editFields'] = $formFields; $viewsDir = $app->viewsDir . $replacements['viewsPrefix'] . '/'; $this->messages[] = $this->tryCreatingDirectory($viewsDir, $model . ' views dir'); $this->messages[] = $this->tryGeneratingFile('resource layout', $this->application->codeTemplatesDir . 'scaffolding/views/resource/resource.layout.template.php', $viewsDir . '../layouts/' . $replacements['viewsPrefix'] . '.layout.php', $replacements); $this->messages[] = $this->tryGeneratingFile('index view', $this->application->codeTemplatesDir . 'scaffolding/views/resource/index.template.php', $viewsDir . 'index.html.php', $replacements); $this->messages[] = $this->tryGeneratingFile('editForm view', $this->application->codeTemplatesDir . 'scaffolding/views/resource/editForm.template.php', $viewsDir . 'editForm.html.php', $replacements, true); $this->messages[] = $this->tryGeneratingFile('form part', $this->application->codeTemplatesDir . 'scaffolding/views/resource/form.part.template.php', $viewsDir . 'form.part.php', $replacements, true); $this->messages[] = $this->tryGeneratingFile('static details', $this->application->codeTemplatesDir . 'scaffolding/views/resource/details.template.php', $viewsDir . 'details.html.php', $replacements); $this->messages[] = $this->tryGeneratingFile('details part', $this->application->codeTemplatesDir . 'scaffolding/views/resource/details.part.template.php', $viewsDir . 'details.part.php', $replacements); $this->appName = get_class($app); $this->modelName = $model; }
function testToCamelCaps() { $this->assertEquals('camelCaps', Inflector::toCamelCaps('CamelCaps')); $this->assertEquals('camelCaps', Inflector::toCamelCaps('camel_caps')); }