Commit 9737b9bb authored by Jens Segers's avatar Jens Segers

Move hybrid relation logic to its own trait

parent 6460d584
This diff is collapsed.
......@@ -22,7 +22,6 @@ class Connection extends \Illuminate\Database\Connection {
* Create a new database connection instance.
*
* @param array $config
* @return void
*/
public function __construct(array $config)
{
......@@ -143,7 +142,7 @@ class Connection extends \Illuminate\Database\Connection {
}
// By default driver options is an empty array.
$driverOptions = array();
$driverOptions = [];
if (isset($config['driver_options']) && is_array($config['driver_options']))
{
......@@ -155,8 +154,6 @@ class Connection extends \Illuminate\Database\Connection {
/**
* Disconnect from the underlying MongoClient connection.
*
* @return void
*/
public function disconnect()
{
......@@ -229,7 +226,7 @@ class Connection extends \Illuminate\Database\Connection {
*/
public function __call($method, $parameters)
{
return call_user_func_array(array($this->db, $method), $parameters);
return call_user_func_array([$this->db, $method], $parameters);
}
}
<?php namespace Jenssegers\Mongodb\Eloquent;
use MongoCursor;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\Relation;
use MongoCursor;
class Builder extends EloquentBuilder {
......@@ -11,10 +11,10 @@ class Builder extends EloquentBuilder {
*
* @var array
*/
protected $passthru = array(
protected $passthru = [
'toSql', 'lists', 'insert', 'insertGetId', 'pluck',
'count', 'min', 'max', 'avg', 'sum', 'exists', 'push', 'pull',
);
];
/**
* Update a record in the database.
......@@ -104,7 +104,7 @@ class Builder extends EloquentBuilder {
* @param array $extra
* @return int
*/
public function increment($column, $amount = 1, array $extra = array())
public function increment($column, $amount = 1, array $extra = [])
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
......@@ -119,7 +119,7 @@ class Builder extends EloquentBuilder {
$this->model->syncOriginalAttribute($column);
$result = $this->model->update(array($column => $value));
$result = $this->model->update([$column => $value]);
return $result;
}
......@@ -135,7 +135,7 @@ class Builder extends EloquentBuilder {
* @param array $extra
* @return int
*/
public function decrement($column, $amount = 1, array $extra = array())
public function decrement($column, $amount = 1, array $extra = [])
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
......@@ -150,7 +150,7 @@ class Builder extends EloquentBuilder {
$this->model->syncOriginalAttribute($column);
return $this->model->update(array($column => $value));
return $this->model->update([$column => $value]);
}
return parent::decrement($column, $amount, $extra);
......@@ -194,7 +194,7 @@ class Builder extends EloquentBuilder {
});
// If the operator is <, <= or !=, we will use whereNotIn.
$not = in_array($operator, array('<', '<=', '!='));
$not = in_array($operator, ['<', '<=', '!=']);
// If we are comparing to 0, we need an additional $not flip.
if ($count == 0) $not = !$not;
......
......@@ -37,7 +37,7 @@ class Collection extends EloquentCollection {
// and keep going.
if (func_num_args() == 2)
{
list($value, $operator) = array($operator, '=');
list($value, $operator) = [$operator, '='];
}
return $this->filter(function ($item) use ($key, $operator, $value)
......
<?php namespace Jenssegers\Mongodb\Eloquent;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Jenssegers\Mongodb\Model;
use Jenssegers\Mongodb\Relations\BelongsTo;
use Jenssegers\Mongodb\Relations\BelongsToMany;
use Jenssegers\Mongodb\Relations\HasMany;
use Jenssegers\Mongodb\Relations\HasOne;
use Jenssegers\Mongodb\Relations\MorphTo;
trait HybridRelations {
/**
* Define a one-to-one relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function hasOne($related, $foreignKey = null, $localKey = null)
{
// Check if it is a relation with an original model.
if ($related instanceof Model)
{
return parent::hasOne($related, $foreignKey, $localKey);
}
$foreignKey = $foreignKey ?: $this->getForeignKey();
$instance = new $related;
$localKey = $localKey ?: $this->getKeyName();
return new HasOne($instance->newQuery(), $this, $foreignKey, $localKey);
}
/**
* Define a polymorphic one-to-one relationship.
*
* @param string $related
* @param string $name
* @param string $type
* @param string $id
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphOne
*/
public function morphOne($related, $name, $type = null, $id = null, $localKey = null)
{
// Check if it is a relation with an original model.
if ($related instanceof Model)
{
return parent::morphOne($related, $name, $type, $id, $localKey );
}
$instance = new $related;
list($type, $id) = $this->getMorphs($name, $type, $id);
$table = $instance->getTable();
$localKey = $localKey ?: $this->getKeyName();
return new MorphOne($instance->newQuery(), $this, $type, $id, $localKey);
}
/**
* Define a one-to-many relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function hasMany($related, $foreignKey = null, $localKey = null)
{
// Check if it is a relation with an original model.
if ($related instanceof Model)
{
return parent::hasMany($related, $foreignKey, $localKey);
}
$foreignKey = $foreignKey ?: $this->getForeignKey();
$instance = new $related;
$localKey = $localKey ?: $this->getKeyName();
return new HasMany($instance->newQuery(), $this, $foreignKey, $localKey);
}
/**
* Define a polymorphic one-to-many relationship.
*
* @param string $related
* @param string $name
* @param string $type
* @param string $id
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
{
// Check if it is a relation with an original model.
if ($related instanceof Model)
{
return parent::morphMany($related, $name, $type, $id, $localKey);
}
$instance = new $related;
// Here we will gather up the morph type and ID for the relationship so that we
// can properly query the intermediate table of a relation. Finally, we will
// get the table and create the relationship instances for the developers.
list($type, $id) = $this->getMorphs($name, $type, $id);
$table = $instance->getTable();
$localKey = $localKey ?: $this->getKeyName();
return new MorphMany($instance->newQuery(), $this, $type, $id, $localKey);
}
/**
* Define an inverse one-to-one or many relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $otherKey
* @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relatinoships.
if (is_null($relation))
{
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
}
// Check if it is a relation with an original model.
if ($related instanceof Model)
{
return parent::belongsTo($related, $foreignKey, $otherKey, $relation);
}
// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
if (is_null($foreignKey))
{
$foreignKey = snake_case($relation) . '_id';
}
$instance = new $related;
// Once we have the foreign key names, we'll just create a new Eloquent query
// for the related models and returns the relationship instance which will
// actually be responsible for retrieving and hydrating every relations.
$query = $instance->newQuery();
$otherKey = $otherKey ?: $instance->getKeyName();
return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation);
}
/**
* Define a polymorphic, inverse one-to-one or many relationship.
*
* @param string $name
* @param string $type
* @param string $id
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function morphTo($name = null, $type = null, $id = null)
{
// If no name is provided, we will use the backtrace to get the function name
// since that is most likely the name of the polymorphic interface. We can
// use that to get both the class and foreign key that will be utilized.
if (is_null($name))
{
list(, $caller) = debug_backtrace(false);
$name = snake_case($caller['function']);
}
list($type, $id) = $this->getMorphs($name, $type, $id);
// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
// there are multiple types in the morph and we can't use single queries.
if (is_null($class = $this->$type))
{
return new MorphTo(
$this->newQuery(), $this, $id, null, $type, $name
);
}
// If we are not eager loading the relatinship, we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
else
{
$instance = new $class;
return new MorphTo(
with($instance)->newQuery(), $this, $id, $instance->getKeyName(), $type, $name
);
}
}
/**
* Define a many-to-many relationship.
*
* @param string $related
* @param string $collection
* @param string $foreignKey
* @param string $otherKey
* @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null)
{
// If no relationship name was passed, we will pull backtraces to get the
// name of the calling function. We will use that function name as the
// title of this relation since that is a great convention to apply.
if (is_null($relation))
{
$relation = $this->getBelongsToManyCaller();
}
// Check if it is a relation with an original model.
if ($related instanceof Model)
{
return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation);
}
// First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this.
$foreignKey = $foreignKey ?: $this->getForeignKey() . 's';
$instance = new $related;
$otherKey = $otherKey ?: $instance->getForeignKey() . 's';
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
if (is_null($collection))
{
$collection = $instance->getTable();
}
// Now we're ready to create a new query builder for the related model and
// the relationship instances for the relation. The relations will set
// appropriate query constraint and entirely manages the hydrations.
$query = $instance->newQuery();
return new BelongsToMany($query, $this, $collection, $foreignKey, $otherKey, $relation);
}
}
......@@ -2,16 +2,21 @@
use Carbon\Carbon;
use DateTime;
use MongoDate;
use MongoId;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\Relation;
use Jenssegers\Mongodb\Eloquent\Builder;
use Jenssegers\Mongodb\Eloquent\HybridRelations;
use Jenssegers\Mongodb\Query\Builder as QueryBuilder;
use Jenssegers\Mongodb\Relations\EmbedsMany;
use Jenssegers\Mongodb\Relations\EmbedsOne;
use Jenssegers\Mongodb\Relations\EmbedsOneOrMany;
use MongoDate;
use MongoId;
use ReflectionMethod;
abstract class Model extends \Jenssegers\Eloquent\Model {
abstract class Model extends BaseModel {
use HybridRelations;
/**
* The collection associated with the model.
......@@ -292,7 +297,6 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*
* @param string $key
* @param mixed $value
* @return void
*/
public function setAttribute($key, $value)
{
......@@ -361,7 +365,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*/
public function drop($columns)
{
if ( ! is_array($columns)) $columns = array($columns);
if ( ! is_array($columns)) $columns = [$columns];
// Unset attributes
foreach ($columns as $column)
......@@ -394,7 +398,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
}
// Do batch push by default.
if ( ! is_array($values)) $values = array($values);
if ( ! is_array($values)) $values = [$values];
$query = $this->setKeysForSaveQuery($this->newQuery());
......@@ -416,7 +420,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
public function pull($column, $values)
{
// Do batch pull by default.
if ( ! is_array($values)) $values = array($values);
if ( ! is_array($values)) $values = [$values];
$query = $this->setKeysForSaveQuery($this->newQuery());
......@@ -431,11 +435,10 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
* @param string $column
* @param array $values
* @param bool $unique
* @return void
*/
protected function pushAttributeValues($column, array $values, $unique = false)
{
$current = $this->getAttributeFromArray($column) ?: array();
$current = $this->getAttributeFromArray($column) ?: [];
foreach ($values as $value)
{
......@@ -455,11 +458,10 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*
* @param string $column
* @param array $values
* @return void
*/
protected function pullAttributeValues($column, array $values)
{
$current = $this->getAttributeFromArray($column) ?: array();
$current = $this->getAttributeFromArray($column) ?: [];
foreach ($values as $value)
{
......@@ -507,6 +509,18 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
return new Builder($query);
}
/**
* Get a new query builder instance for the connection.
*
* @return Builder
*/
protected function newBaseQueryBuilder()
{
$connection = $this->getConnection();
return new QueryBuilder($connection, $connection->getPostProcessor());
}
/**
* Handle dynamic method calls into the method.
*
......@@ -519,7 +533,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
// Unset method
if ($method == 'unset')
{
return call_user_func_array(array($this, 'drop'), $parameters);
return call_user_func_array([$this, 'drop'], $parameters);
}
return parent::__call($method, $parameters);
......
......@@ -6,8 +6,6 @@ class MongodbServiceProvider extends ServiceProvider {
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
......@@ -18,8 +16,6 @@ class MongodbServiceProvider extends ServiceProvider {
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
......
This diff is collapsed.
......@@ -4,8 +4,6 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
/**
* Set the base constraints on the relation query.
*
* @return void
*/
public function addConstraints()
{
......@@ -22,7 +20,6 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
* Set the constraints for an eager load of the relation.
*
* @param array $models
* @return void
*/
public function addEagerConstraints(array $models)
{
......
<?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany;
class BelongsToMany extends EloquentBelongsToMany {
......@@ -10,7 +10,6 @@ class BelongsToMany extends EloquentBelongsToMany {
* Hydrate the pivot table relationship on the models.
*
* @param array $models
* @return void
*/
protected function hydratePivotRelation(array $models)
{
......@@ -23,15 +22,13 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param array $columns
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
protected function getSelectColumns(array $columns = array('*'))
protected function getSelectColumns(array $columns = ['*'])
{
return $columns;
}
/**
* Set the base constraints on the relation query.
*
* @return void
*/
public function addConstraints()
{
......@@ -60,9 +57,9 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
*/
public function save(Model $model, array $joining = array(), $touch = true)
public function save(Model $model, array $joining = [], $touch = true)
{
$model->save(array('touch' => false));
$model->save(['touch' => false]);
$this->attach($model, $joining, $touch);
......@@ -77,14 +74,14 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
*/
public function create(array $attributes, array $joining = array(), $touch = true)
public function create(array $attributes, array $joining = [], $touch = true)
{
$instance = $this->related->newInstance($attributes);
// Once we save the related model, we need to attach it to the base model via
// through intermediate table so we'll use the existing "attach" method to
// accomplish this which will insert the record and any more attributes.
$instance->save(array('touch' => false));
$instance->save(['touch' => false]);
$this->attach($instance, $joining, $touch);
......@@ -100,16 +97,16 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
public function sync($ids, $detaching = true)
{
$changes = array(
'attached' => array(), 'detached' => array(), 'updated' => array(),
);
$changes = [
'attached' => [], 'detached' => [], 'updated' => [],
];
if ($ids instanceof Collection) $ids = $ids->modelKeys();
// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
// if they exist in the array of current ones, and if not we will insert.
$current = $this->parent->{$this->otherKey} ?: array();
$current = $this->parent->{$this->otherKey} ?: [];
// See issue #256.
if ($current instanceof Collection) $current = $ids->modelKeys();
......@@ -153,7 +150,6 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param mixed $id
* @param array $attributes
* @param bool $touch
* @return void
*/
public function updateExistingPivot($id, array $attributes, $touch = true)
{
......@@ -166,9 +162,8 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param mixed $id
* @param array $attributes
* @param bool $touch
* @return void
*/
public function attach($id, array $attributes = array(), $touch = true)
public function attach($id, array $attributes = [], $touch = true)
{
if ($id instanceof Model)
{
......@@ -202,7 +197,7 @@ class BelongsToMany extends EloquentBelongsToMany {
* @param bool $touch
* @return int
*/
public function detach($ids = array(), $touch = true)
public function detach($ids = [], $touch = true)
{
if ($ids instanceof Model) $ids = (array) $ids->getKey();
......@@ -243,7 +238,7 @@ class BelongsToMany extends EloquentBelongsToMany {
// First we will build a dictionary of child models keyed by the foreign key
// of the relation so that we will easily and quickly match them to their
// parents without having a possibly slow inner loops for every models.
$dictionary = array();
$dictionary = [];
foreach ($results as $result)
{
......
......@@ -99,7 +99,7 @@ class EmbedsMany extends EmbedsOneOrMany {
// Get the correct foreign key value.
$foreignKey = $this->getForeignKeyValue($model);
$result = $this->getBaseQuery()->pull($this->localKey, array($model->getKeyName() => $foreignKey));
$result = $this->getBaseQuery()->pull($this->localKey, [$model->getKeyName() => $foreignKey]);
if ($result) $this->dissociate($model);
......@@ -130,7 +130,7 @@ class EmbedsMany extends EmbedsOneOrMany {
* @param mixed $ids
* @return int
*/
public function dissociate($ids = array())
public function dissociate($ids = [])
{
$ids = $this->getIdsArrayFrom($ids);
......@@ -161,7 +161,7 @@ class EmbedsMany extends EmbedsOneOrMany {
* @param mixed $ids
* @return int
*/
public function destroy($ids = array())
public function destroy($ids = [])
{
$count = 0;
......@@ -187,9 +187,9 @@ class EmbedsMany extends EmbedsOneOrMany {
public function delete()
{
// Overwrite the local key with an empty array.
$result = $this->query->update(array($this->localKey => array()));
$result = $this->query->update([$this->localKey => []]);
if ($result) $this->setEmbedded(array());
if ($result) $this->setEmbedded([]);
return $result;
}
......@@ -200,7 +200,7 @@ class EmbedsMany extends EmbedsOneOrMany {
* @param mixed $ids
* @return int
*/
public function detach($ids = array())
public function detach($ids = [])
{
return $this->destroy($ids);
}
......@@ -296,18 +296,17 @@ class EmbedsMany extends EmbedsOneOrMany {
*/
protected function getEmbedded()
{
return parent::getEmbedded() ?: array();
return parent::getEmbedded() ?: [];
}
/**
* Set the embedded records array.
*
* @param array $models
* @return void
*/
protected function setEmbedded($models)
{
if ( ! is_array($models)) $models = array($models);
if ( ! is_array($models)) $models = [$models];
return parent::setEmbedded(array_values($models));
}
......@@ -324,7 +323,7 @@ class EmbedsMany extends EmbedsOneOrMany {
// Collection methods
if (method_exists('Jenssegers\Mongodb\Eloquent\Collection', $method))
{
return call_user_func_array(array($this->getResults(), $method), $parameters);
return call_user_func_array([$this->getResults(), $method], $parameters);
}
return parent::__call($method, $parameters);
......
......@@ -37,7 +37,7 @@ class EmbedsOne extends EmbedsOneOrMany {
return $this->parent->save();
}
$result = $this->getBaseQuery()->update(array($this->localKey => $model->getAttributes()));
$result = $this->getBaseQuery()->update([$this->localKey => $model->getAttributes()]);
// Attach the model to its parent.
if ($result) $this->associate($model);
......@@ -88,7 +88,7 @@ class EmbedsOne extends EmbedsOneOrMany {
}
// Overwrite the local key with an empty array.
$result = $this->getBaseQuery()->update(array($this->localKey => null));
$result = $this->getBaseQuery()->update([$this->localKey => null]);
// Detach the model from its parent.
if ($result) $this->dissociate();
......
......@@ -59,8 +59,6 @@ abstract class EmbedsOneOrMany extends Relation {
/**
* Set the base constraints on the relation query.
*
* @return void
*/
public function addConstraints()
{
......@@ -74,7 +72,6 @@ abstract class EmbedsOneOrMany extends Relation {
* Set the constraints for an eager load of the relation.
*
* @param array $models
* @return void
*/
public function addEagerConstraints(array $models)
{
......@@ -86,7 +83,6 @@ abstract class EmbedsOneOrMany extends Relation {
*
* @param array $models
* @param string $relation
* @return void
*/
public function initRelation(array $models, $relation)
{
......@@ -198,7 +194,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
public function createMany(array $records)
{
$instances = array();
$instances = [];
foreach ($records as $record)
{
......@@ -216,7 +212,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
protected function getIdsArrayFrom($ids)
{
if ( ! is_array($ids)) $ids = array($ids);
if ( ! is_array($ids)) $ids = [$ids];
foreach ($ids as &$id)
{
......@@ -281,9 +277,9 @@ abstract class EmbedsOneOrMany extends Relation {
* @param array $records
* @return \Jenssegers\Mongodb\Eloquent\Collection
*/
protected function toCollection(array $records = array())
protected function toCollection(array $records = [])
{
$models = array();
$models = [];
foreach ($records as $attributes)
{
......@@ -304,7 +300,7 @@ abstract class EmbedsOneOrMany extends Relation {
* @param array $attributes
* @return \Illuminate\Database\Eloquent\Model
*/
protected function toModel($attributes = array())
protected function toModel($attributes = [])
{
if (is_null($attributes)) return;
......@@ -315,7 +311,7 @@ abstract class EmbedsOneOrMany extends Relation {
$model->setRelation($this->foreignKey, $this->parent);
// If you remove this, you will get segmentation faults!
$model->setHidden(array_merge($model->getHidden(), array($this->foreignKey)));
$model->setHidden(array_merge($model->getHidden(), [$this->foreignKey]));
return $model;
}
......@@ -357,7 +353,7 @@ abstract class EmbedsOneOrMany extends Relation {
/**
* Check if this relation is nested in another relation.
*
* @return boolean
* @return bool
*/
protected function isNested()
{
......
......@@ -6,8 +6,6 @@ class MorphTo extends EloquentMorphTo {
/**
* Set the base constraints on the relation query.
*
* @return void
*/
public function addConstraints()
{
......
......@@ -24,14 +24,13 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
*
* @var array
*/
protected $columns = array();
protected $columns = [];
/**
* Create a new schema blueprint.
*
* @param string $table
* @param Closure $callback
* @return void
*/
public function __construct(Connection $connection, $collection)
{
......@@ -47,7 +46,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
* @param array $options
* @return Blueprint
*/
public function index($columns = null, $options = array())
public function index($columns = null, $options = [])
{
$columns = $this->fluent($columns);
......@@ -55,7 +54,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
if (is_array($columns) && is_int(key($columns)))
{
// Transform the columns to the required array format.
$transform = array();
$transform = [];
foreach ($columns as $column)
{
......@@ -77,7 +76,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
* @param array $options
* @return \Illuminate\Support\Fluent
*/
public function primary($columns = null, $options = array())
public function primary($columns = null, $options = [])
{
return $this->unique($columns, $options);
}
......@@ -96,7 +95,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
if (is_array($columns) && is_int(key($columns)))
{
// Transform the columns to the required array format.
$transform = array();
$transform = [];
foreach ($columns as $column)
{
......@@ -121,7 +120,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
{
$columns = $this->fluent($columns);
$this->index($columns, array('unique' => true));
$this->index($columns, ['unique' => true]);
return $this;
}
......@@ -136,7 +135,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
{
$columns = $this->fluent($columns);
$this->index($columns, array('background' => true));
$this->index($columns, ['background' => true]);
return $this;
}
......@@ -150,7 +149,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
public function sparse($columns = null)
{
$columns = $this->fluent($columns);
$this->index($columns, array('sparse' => true));
$this->index($columns, ['sparse' => true]);
return $this;
}
......@@ -167,7 +166,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
{
$columns = $this->fluent($columns);
$this->index($columns, array('expireAfterSeconds' => $seconds));
$this->index($columns, ['expireAfterSeconds' => $seconds]);
return $this;
}
......@@ -205,7 +204,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
* @param array $parameters
* @return Blueprint
*/
protected function addColumn($type, $name, array $parameters = array())
protected function addColumn($type, $name, array $parameters = [])
{
$this->fluent($name);
......@@ -226,7 +225,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
}
elseif (is_string($columns))
{
return $this->columns = array($columns);
return $this->columns = [$columns];
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment