Skip to content

Commit

Permalink
Updating the Base Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Feb 6, 2016
1 parent a67416f commit e431142
Showing 1 changed file with 84 additions and 21 deletions.
105 changes: 84 additions & 21 deletions src/Bases/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ abstract class Migration extends IlluminateMigration
| Properties
| ------------------------------------------------------------------------------------------------
*/
/**
* The name of the database connection to use.
*
* @var string|null
*/
protected $connection;

/**
* The table name.
*
Expand All @@ -41,20 +34,78 @@ abstract class Migration extends IlluminateMigration
| Getters & Setters
| ------------------------------------------------------------------------------------------------
*/
/**
* Set the migration connection name.
*
* @param string $connection
*
* @return self
*/
public function setConnection($connection)
{
$this->connection = $connection;

return $this;
}

/**
* Get the table name.
*
* @return null|string
*/
public function getTable()
{
return $this->table;
}

/**
* Get the prefixed table name.
*
* @return string
*/
public function getTableName()
{
$table = $this->table;
return $this->hasPrefix()
? $this->getPrefix() . $this->getTable()
: $this->getTable();
}

if ($this->isPrefixed()) {
$table = $this->prefix . $table;
}
/**
* Set the table name.
*
* @param string $table
*
* @return self
*/
public function setTable($table)
{
$this->table = $table;

return $table;
return $this;
}

/**
* Get the prefix name.
*
* @return null|string
*/
public function getPrefix()
{
return $this->prefix;
}

/**
* Set the prefix name.
*
* @param string $prefix
*
* @return self
*/
public function setPrefix($prefix)
{
$this->prefix = $prefix;

return $this;
}

/* ------------------------------------------------------------------------------------------------
Expand All @@ -77,7 +128,7 @@ public function down()
return;
}

Schema::connection($this->connection)->dropIfExists($this->getTableName());
Schema::connection($this->getConnection())->dropIfExists($this->getTableName());
}

/**
Expand All @@ -87,13 +138,13 @@ public function down()
*/
protected function createSchema(Closure $blueprint)
{
if ( ! $this->hasConnection()) {
if ($this->hasConnection()) {
Schema::connection($this->getConnection())
->create($this->getTableName(), $blueprint);
}
else {
Schema::create($this->getTableName(), $blueprint);

return;
}

Schema::connection($this->connection)->create($this->getTableName(), $blueprint);
}

/* ------------------------------------------------------------------------------------------------
Expand All @@ -107,16 +158,28 @@ protected function createSchema(Closure $blueprint)
*/
protected function hasConnection()
{
return ! (is_null($this->connection) || empty($this->connection));
return $this->isNotEmpty($this->getConnection());
}

/**
* Check if table has prefix.
*
* @return bool
*/
protected function isPrefixed()
protected function hasPrefix()
{
return $this->isNotEmpty($this->getPrefix());
}

/**
* Check if the value is not empty.
*
* @param string $value
*
* @return bool
*/
private function isNotEmpty($value)
{
return ! (is_null($this->prefix) || empty($this->prefix));
return ! (is_null($value) || empty($value));
}
}

0 comments on commit e431142

Please sign in to comment.