Skip to content

Commit

Permalink
Rework methods in Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Oct 13, 2024
1 parent d0de623 commit 070a238
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ protected function getTemplate($type)
return new Repository($table, $cols, $this->excluded);
}

$layout = $this->hasLayout();
$route = new Controller($table, $cols);

return new Controller($table, $type, $layout);
$route->useLayout($this->hasLayout());

return $route->setType($type)->init();
}

/**
Expand Down
59 changes: 45 additions & 14 deletions src/Template/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,47 @@ class Controller extends Classidy

const TYPE_DOCTRINE = 1;

/**
* @var \Rougin\Describe\Column[]
*/
protected $cols;

/**
* @var boolean
*/
protected $layout = false;

/**
* @var string
*/
protected $table;

/**
* @var integer
*/
protected $type;

/**
* @param string $table
* @param integer $type
* @param boolean $layout
* @param string $table
* @param \Rougin\Describe\Column[] $cols
*/
public function __construct($table, $type, $layout = false)
public function __construct($table, $cols)
{
$this->type = $type;

$this->layout = $layout;
$this->cols = $cols;

$this->init($table);
$this->table = $table;
}

/**
* Configures the current class.
*
* @param string $table
*
* @return void
* @return self
*/
public function init($table)
public function init()
{
$name = Inflector::plural($table);
$name = Inflector::plural($this->table);

$model = Inflector::singular($table);
$model = Inflector::singular($this->table);

/** @var class-string */
$class = ucfirst($model);
Expand Down Expand Up @@ -98,6 +103,32 @@ public function init($table)
$this->setEditMethod($name, $model, $type);

$this->setIndexMethod($name, $model, $type);

return $this;
}

/**
* @param integer $type
*
* @return self
*/
public function setType($type)
{
$this->type = $type;

return $this;
}

/**
* @param boolean $layout
*
* @return self
*/
public function useLayout($layout = true)
{
$this->layout = $layout;

return $this;
}

/**
Expand Down

0 comments on commit 070a238

Please sign in to comment.