Permalink
Browse files

Remove short-arrays option from model generator

  • Loading branch information...
andrzejo committed Mar 29, 2017
1 parent efa679a commit 8e503d2b98ad9b62b208c5dcf7f59e25834a5f06
@@ -37,8 +37,7 @@ public function configure()
->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'Class file path. If not specified namespace and class name is used.')
->addOption('namespace', 's', InputOption::VALUE_REQUIRED, 'Class namespace (e.g \'Model\MyModel\'). Hint: Remember to escape backslash (\\\\)!', $defaultNamespace)
->addOption('remove-prefix', 'p', InputOption::VALUE_REQUIRED, 'Remove prefix from table name when generating class name.', 't')
->addOption('output-only', 'o', InputOption::VALUE_NONE, 'Only displaying generated model class.')
->addOption('short-arrays', 'a', InputOption::VALUE_NONE, 'Generate model class with short arrays. (PHP 5.4).');
->addOption('output-only', 'o', InputOption::VALUE_NONE, 'Only displaying generated model class.');
}
public function execute(InputInterface $input, OutputInterface $output)
@@ -60,12 +59,11 @@ private function generateModel()
$fileName = $this->input->getOption('file');
$nameSpace = $this->input->getOption('namespace');
$tablePrefixToRemove = $this->input->getOption('remove-prefix') ?: 't';
$shortArrays = $this->input->getOption('short-arrays');
if (empty($tableName)) {
$this->fail("Specify table name e.g. users");
}
try {
$modelGenerator = new Generator($tableName, $className, $nameSpace, $tablePrefixToRemove, $shortArrays);
$modelGenerator = new Generator($tableName, $className, $nameSpace, $tablePrefixToRemove);
$this->output->writeln('---------------------------------');
$this->writeInfo('Database name: <info>%s</info>', Config::getValue('db', 'dbname'));
$this->writeInfo('Class name: <info>%s</info>', $modelGenerator->getTemplateClassName());
@@ -16,23 +16,16 @@ class ClassStub
private $_stubContent;
private $_attributes = [];
private $_placeholderWithReplacements = [];
private $shortArrays;
public function __construct($shortArrays = false)
public function __construct()
{
$this->shortArrays = $shortArrays;
$stubFilePath = $this->_getStubFilePath();
$this->_stubContent = file_get_contents($stubFilePath);
}
private function _getStubFilePath()
{
if ($this->shortArrays) {
$stubFileName = 'class_short_arrays.stub';
} else {
$stubFileName = 'class.stub';
}
return Path::join(__DIR__, 'stubs', $stubFileName);
return Path::join(__DIR__, 'stubs', 'class.stub');
}
public function addColumn(DatabaseColumn $databaseColumn)
@@ -18,12 +18,12 @@ class ClassStubPlaceholderReplacer
private $classStub;
private $classNamespace;
public function __construct($className, $tableInfo, $classNamespace = '', $shortArrays = false)
public function __construct($className, $tableInfo, $classNamespace = '')
{
$this->className = $className;
$this->tableInfo = $tableInfo;
$this->classNamespace = $classNamespace;
$this->classStub = new ClassStub($shortArrays);
$this->classStub = new ClassStub();
}
private function _setupTablePlaceholderReplacements()
@@ -22,17 +22,15 @@ class Generator
private $dialectShortName;
private $tablePrefix;
private $namespace;
private $shortArrays;
public function __construct($tableName, $className = null, $nameSpace = '', $tablePrefix = 't', $shortArrays = false)
public function __construct($tableName, $className = null, $nameSpace = '', $tablePrefix = 't')
{
$this->tableName = $tableName;
$this->className = $className;
$this->namespace = $this->normalizeNameSpace($nameSpace);
$this->tablePrefix = $tablePrefix;
$this->adapter = $this->dialectAdapter();
$this->dialectShortName = $this->getDialectShortName($this->adapter);
$this->shortArrays = $shortArrays;
}
private function normalizeNameSpace($nameSpace)
@@ -89,7 +87,7 @@ public function getTemplateClassName()
public function templateContents()
{
$tableInfo = new TableInfo($this->adapter);
$stubReplacer = new ClassStubPlaceholderReplacer($this->getTemplateClassName(), $tableInfo, $this->getClassNamespace(), $this->shortArrays);
$stubReplacer = new ClassStubPlaceholderReplacer($this->getTemplateClassName(), $tableInfo, $this->getClassNamespace());
return $stubReplacer->contents();
}
@@ -8,14 +8,14 @@ use Ouzo\Model;
*/
class {class} extends Model
{
public function __construct($attributes = array())
public function __construct($attributes = [])
{
parent::__construct(array(
parent::__construct([
{table_table}
{table_primaryKey}
{table_sequence}
'attributes' => $attributes,
'fields' => array({fields})
));
'fields' => [{fields}]
]);
}
}
}

This file was deleted.

Oops, something went wrong.

0 comments on commit 8e503d2

Please sign in to comment.