You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by nd...@apache.org on 2015/05/01 23:33:05 UTC
[18/57] [partial] airavata-php-gateway git commit: AIRAVATA 1632 +
Job Description for Admin Dashboard
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
new file mode 100755
index 0000000..034917d
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
@@ -0,0 +1,1055 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Query\Expression;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\ModelNotFoundException;
+
+class BelongsToMany extends Relation {
+
+ /**
+ * The intermediate table for the relation.
+ *
+ * @var string
+ */
+ protected $table;
+
+ /**
+ * The foreign key of the parent model.
+ *
+ * @var string
+ */
+ protected $foreignKey;
+
+ /**
+ * The associated key of the relation.
+ *
+ * @var string
+ */
+ protected $otherKey;
+
+ /**
+ * The "name" of the relationship.
+ *
+ * @var string
+ */
+ protected $relationName;
+
+ /**
+ * The pivot table columns to retrieve.
+ *
+ * @var array
+ */
+ protected $pivotColumns = array();
+
+ /**
+ * Any pivot table restrictions.
+ *
+ * @var array
+ */
+ protected $pivotWheres = [];
+
+ /**
+ * Create a new has many relationship instance.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Model $parent
+ * @param string $table
+ * @param string $foreignKey
+ * @param string $otherKey
+ * @param string $relationName
+ * @return void
+ */
+ public function __construct(Builder $query, Model $parent, $table, $foreignKey, $otherKey, $relationName = null)
+ {
+ $this->table = $table;
+ $this->otherKey = $otherKey;
+ $this->foreignKey = $foreignKey;
+ $this->relationName = $relationName;
+
+ parent::__construct($query, $parent);
+ }
+
+ /**
+ * Get the results of the relationship.
+ *
+ * @return mixed
+ */
+ public function getResults()
+ {
+ return $this->get();
+ }
+
+ /**
+ * Set a where clause for a pivot table column.
+ *
+ * @param string $column
+ * @param string $operator
+ * @param mixed $value
+ * @param string $boolean
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ */
+ public function wherePivot($column, $operator = null, $value = null, $boolean = 'and')
+ {
+ $this->pivotWheres[] = func_get_args();
+
+ return $this->where($this->table.'.'.$column, $operator, $value, $boolean);
+ }
+
+ /**
+ * Set an or where clause for a pivot table column.
+ *
+ * @param string $column
+ * @param string $operator
+ * @param mixed $value
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ */
+ public function orWherePivot($column, $operator = null, $value = null)
+ {
+ return $this->wherePivot($column, $operator, $value, 'or');
+ }
+
+ /**
+ * Execute the query and get the first result.
+ *
+ * @param array $columns
+ * @return mixed
+ */
+ public function first($columns = array('*'))
+ {
+ $results = $this->take(1)->get($columns);
+
+ return count($results) > 0 ? $results->first() : null;
+ }
+
+ /**
+ * Execute the query and get the first result or throw an exception.
+ *
+ * @param array $columns
+ * @return \Illuminate\Database\Eloquent\Model|static
+ *
+ * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
+ */
+ public function firstOrFail($columns = array('*'))
+ {
+ if ( ! is_null($model = $this->first($columns))) return $model;
+
+ throw new ModelNotFoundException;
+ }
+
+ /**
+ * Execute the query as a "select" statement.
+ *
+ * @param array $columns
+ * @return \Illuminate\Database\Eloquent\Collection
+ */
+ public function get($columns = array('*'))
+ {
+ // First we'll add the proper select columns onto the query so it is run with
+ // the proper columns. Then, we will get the results and hydrate out pivot
+ // models with the result of those columns as a separate model relation.
+ $columns = $this->query->getQuery()->columns ? array() : $columns;
+
+ $select = $this->getSelectColumns($columns);
+
+ $models = $this->query->addSelect($select)->getModels();
+
+ $this->hydratePivotRelation($models);
+
+ // If we actually found models we will also eager load any relationships that
+ // have been specified as needing to be eager loaded. This will solve the
+ // n + 1 query problem for the developer and also increase performance.
+ if (count($models) > 0)
+ {
+ $models = $this->query->eagerLoadRelations($models);
+ }
+
+ return $this->related->newCollection($models);
+ }
+
+ /**
+ * Get a paginator for the "select" statement.
+ *
+ * @param int $perPage
+ * @param array $columns
+ * @return \Illuminate\Pagination\Paginator
+ */
+ public function paginate($perPage = null, $columns = array('*'))
+ {
+ $this->query->addSelect($this->getSelectColumns($columns));
+
+ // When paginating results, we need to add the pivot columns to the query and
+ // then hydrate into the pivot objects once the results have been gathered
+ // from the database since this isn't performed by the Eloquent builder.
+ $pager = $this->query->paginate($perPage, $columns);
+
+ $this->hydratePivotRelation($pager->getItems());
+
+ return $pager;
+ }
+
+ /**
+ * Hydrate the pivot table relationship on the models.
+ *
+ * @param array $models
+ * @return void
+ */
+ protected function hydratePivotRelation(array $models)
+ {
+ // To hydrate the pivot relationship, we will just gather the pivot attributes
+ // and create a new Pivot model, which is basically a dynamic model that we
+ // will set the attributes, table, and connections on so it they be used.
+ foreach ($models as $model)
+ {
+ $pivot = $this->newExistingPivot($this->cleanPivotAttributes($model));
+
+ $model->setRelation('pivot', $pivot);
+ }
+ }
+
+ /**
+ * Get the pivot attributes from a model.
+ *
+ * @param \Illuminate\Database\Eloquent\Model $model
+ * @return array
+ */
+ protected function cleanPivotAttributes(Model $model)
+ {
+ $values = array();
+
+ foreach ($model->getAttributes() as $key => $value)
+ {
+ // To get the pivots attributes we will just take any of the attributes which
+ // begin with "pivot_" and add those to this arrays, as well as unsetting
+ // them from the parent's models since they exist in a different table.
+ if (strpos($key, 'pivot_') === 0)
+ {
+ $values[substr($key, 6)] = $value;
+
+ unset($model->$key);
+ }
+ }
+
+ return $values;
+ }
+
+ /**
+ * Set the base constraints on the relation query.
+ *
+ * @return void
+ */
+ public function addConstraints()
+ {
+ $this->setJoin();
+
+ if (static::$constraints) $this->setWhere();
+ }
+
+ /**
+ * Add the constraints for a relationship count query.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Builder $parent
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ public function getRelationCountQuery(Builder $query, Builder $parent)
+ {
+ if ($parent->getQuery()->from == $query->getQuery()->from)
+ {
+ return $this->getRelationCountQueryForSelfJoin($query, $parent);
+ }
+
+ $this->setJoin($query);
+
+ return parent::getRelationCountQuery($query, $parent);
+ }
+
+ /**
+ * Add the constraints for a relationship count query on the same table.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Builder $parent
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ public function getRelationCountQueryForSelfJoin(Builder $query, Builder $parent)
+ {
+ $query->select(new Expression('count(*)'));
+
+ $tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix();
+
+ $query->from($this->table.' as '.$tablePrefix.$hash = $this->getRelationCountHash());
+
+ $key = $this->wrap($this->getQualifiedParentKeyName());
+
+ return $query->where($hash.'.'.$this->foreignKey, '=', new Expression($key));
+ }
+
+ /**
+ * Get a relationship join table hash.
+ *
+ * @return string
+ */
+ public function getRelationCountHash()
+ {
+ return 'self_'.md5(microtime(true));
+ }
+
+ /**
+ * Set the select clause for the relation query.
+ *
+ * @param array $columns
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ */
+ protected function getSelectColumns(array $columns = array('*'))
+ {
+ if ($columns == array('*'))
+ {
+ $columns = array($this->related->getTable().'.*');
+ }
+
+ return array_merge($columns, $this->getAliasedPivotColumns());
+ }
+
+ /**
+ * Get the pivot columns for the relation.
+ *
+ * @return array
+ */
+ protected function getAliasedPivotColumns()
+ {
+ $defaults = array($this->foreignKey, $this->otherKey);
+
+ // We need to alias all of the pivot columns with the "pivot_" prefix so we
+ // can easily extract them out of the models and put them into the pivot
+ // relationships when they are retrieved and hydrated into the models.
+ $columns = array();
+
+ foreach (array_merge($defaults, $this->pivotColumns) as $column)
+ {
+ $columns[] = $this->table.'.'.$column.' as pivot_'.$column;
+ }
+
+ return array_unique($columns);
+ }
+
+ /**
+ * Determine whether the given column is defined as a pivot column.
+ *
+ * @param string $column
+ * @return bool
+ */
+ protected function hasPivotColumn($column)
+ {
+ return in_array($column, $this->pivotColumns);
+ }
+
+ /**
+ * Set the join clause for the relation query.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder|null
+ * @return $this
+ */
+ protected function setJoin($query = null)
+ {
+ $query = $query ?: $this->query;
+
+ // We need to join to the intermediate table on the related model's primary
+ // key column with the intermediate table's foreign key for the related
+ // model instance. Then we can set the "where" for the parent models.
+ $baseTable = $this->related->getTable();
+
+ $key = $baseTable.'.'.$this->related->getKeyName();
+
+ $query->join($this->table, $key, '=', $this->getOtherKey());
+
+ return $this;
+ }
+
+ /**
+ * Set the where clause for the relation query.
+ *
+ * @return $this
+ */
+ protected function setWhere()
+ {
+ $foreign = $this->getForeignKey();
+
+ $this->query->where($foreign, '=', $this->parent->getKey());
+
+ return $this;
+ }
+
+ /**
+ * Set the constraints for an eager load of the relation.
+ *
+ * @param array $models
+ * @return void
+ */
+ public function addEagerConstraints(array $models)
+ {
+ $this->query->whereIn($this->getForeignKey(), $this->getKeys($models));
+ }
+
+ /**
+ * Initialize the relation on a set of models.
+ *
+ * @param array $models
+ * @param string $relation
+ * @return array
+ */
+ public function initRelation(array $models, $relation)
+ {
+ foreach ($models as $model)
+ {
+ $model->setRelation($relation, $this->related->newCollection());
+ }
+
+ return $models;
+ }
+
+ /**
+ * Match the eagerly loaded results to their parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ public function match(array $models, Collection $results, $relation)
+ {
+ $dictionary = $this->buildDictionary($results);
+
+ // Once we have an array dictionary of child objects we can easily match the
+ // children back to their parent using the dictionary and the keys on the
+ // the parent models. Then we will return the hydrated models back out.
+ foreach ($models as $model)
+ {
+ if (isset($dictionary[$key = $model->getKey()]))
+ {
+ $collection = $this->related->newCollection($dictionary[$key]);
+
+ $model->setRelation($relation, $collection);
+ }
+ }
+
+ return $models;
+ }
+
+ /**
+ * Build model dictionary keyed by the relation's foreign key.
+ *
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @return array
+ */
+ protected function buildDictionary(Collection $results)
+ {
+ $foreign = $this->foreignKey;
+
+ // 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();
+
+ foreach ($results as $result)
+ {
+ $dictionary[$result->pivot->$foreign][] = $result;
+ }
+
+ return $dictionary;
+ }
+
+ /**
+ * Touch all of the related models for the relationship.
+ *
+ * E.g.: Touch all roles associated with this user.
+ *
+ * @return void
+ */
+ public function touch()
+ {
+ $key = $this->getRelated()->getKeyName();
+
+ $columns = $this->getRelatedFreshUpdate();
+
+ // If we actually have IDs for the relation, we will run the query to update all
+ // the related model's timestamps, to make sure these all reflect the changes
+ // to the parent models. This will help us keep any caching synced up here.
+ $ids = $this->getRelatedIds();
+
+ if (count($ids) > 0)
+ {
+ $this->getRelated()->newQuery()->whereIn($key, $ids)->update($columns);
+ }
+ }
+
+ /**
+ * Get all of the IDs for the related models.
+ *
+ * @return array
+ */
+ public function getRelatedIds()
+ {
+ $related = $this->getRelated();
+
+ $fullKey = $related->getQualifiedKeyName();
+
+ return $this->getQuery()->select($fullKey)->lists($related->getKeyName());
+ }
+
+ /**
+ * Save a new model and attach it to the parent model.
+ *
+ * @param \Illuminate\Database\Eloquent\Model $model
+ * @param array $joining
+ * @param bool $touch
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function save(Model $model, array $joining = array(), $touch = true)
+ {
+ $model->save(array('touch' => false));
+
+ $this->attach($model->getKey(), $joining, $touch);
+
+ return $model;
+ }
+
+ /**
+ * Save an array of new models and attach them to the parent model.
+ *
+ * @param array $models
+ * @param array $joinings
+ * @return array
+ */
+ public function saveMany(array $models, array $joinings = array())
+ {
+ foreach ($models as $key => $model)
+ {
+ $this->save($model, (array) array_get($joinings, $key), false);
+ }
+
+ $this->touchIfTouching();
+
+ return $models;
+ }
+
+ /**
+ * Create a new instance of the related model.
+ *
+ * @param array $attributes
+ * @param array $joining
+ * @param bool $touch
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function create(array $attributes, array $joining = array(), $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));
+
+ $this->attach($instance->getKey(), $joining, $touch);
+
+ return $instance;
+ }
+
+ /**
+ * Create an array of new instances of the related models.
+ *
+ * @param array $records
+ * @param array $joinings
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function createMany(array $records, array $joinings = array())
+ {
+ $instances = array();
+
+ foreach ($records as $key => $record)
+ {
+ $instances[] = $this->create($record, (array) array_get($joinings, $key), false);
+ }
+
+ $this->touchIfTouching();
+
+ return $instances;
+ }
+
+ /**
+ * Sync the intermediate tables with a list of IDs or collection of models.
+ *
+ * @param array $ids
+ * @param bool $detaching
+ * @return array
+ */
+ public function sync($ids, $detaching = true)
+ {
+ $changes = array(
+ 'attached' => array(), 'detached' => array(), 'updated' => array()
+ );
+
+ 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->newPivotQuery()->lists($this->otherKey);
+
+ $records = $this->formatSyncList($ids);
+
+ $detach = array_diff($current, array_keys($records));
+
+ // Next, we will take the differences of the currents and given IDs and detach
+ // all of the entities that exist in the "current" array but are not in the
+ // the array of the IDs given to the method which will complete the sync.
+ if ($detaching && count($detach) > 0)
+ {
+ $this->detach($detach);
+
+ $changes['detached'] = (array) array_map(function($v) { return (int) $v; }, $detach);
+ }
+
+ // Now we are finally ready to attach the new records. Note that we'll disable
+ // touching until after the entire operation is complete so we don't fire a
+ // ton of touch operations until we are totally done syncing the records.
+ $changes = array_merge(
+ $changes, $this->attachNew($records, $current, false)
+ );
+
+ if (count($changes['attached']) || count($changes['updated']))
+ {
+ $this->touchIfTouching();
+ }
+
+ return $changes;
+ }
+
+ /**
+ * Format the sync list so that it is keyed by ID.
+ *
+ * @param array $records
+ * @return array
+ */
+ protected function formatSyncList(array $records)
+ {
+ $results = array();
+
+ foreach ($records as $id => $attributes)
+ {
+ if ( ! is_array($attributes))
+ {
+ list($id, $attributes) = array($attributes, array());
+ }
+
+ $results[$id] = $attributes;
+ }
+
+ return $results;
+ }
+
+ /**
+ * Attach all of the IDs that aren't in the current array.
+ *
+ * @param array $records
+ * @param array $current
+ * @param bool $touch
+ * @return array
+ */
+ protected function attachNew(array $records, array $current, $touch = true)
+ {
+ $changes = array('attached' => array(), 'updated' => array());
+
+ foreach ($records as $id => $attributes)
+ {
+ // If the ID is not in the list of existing pivot IDs, we will insert a new pivot
+ // record, otherwise, we will just update this existing record on this joining
+ // table, so that the developers will easily update these records pain free.
+ if ( ! in_array($id, $current))
+ {
+ $this->attach($id, $attributes, $touch);
+
+ $changes['attached'][] = (int) $id;
+ }
+
+ // Now we'll try to update an existing pivot record with the attributes that were
+ // given to the method. If the model is actually updated we will add it to the
+ // list of updated pivot records so we return them back out to the consumer.
+ elseif (count($attributes) > 0 &&
+ $this->updateExistingPivot($id, $attributes, $touch))
+ {
+ $changes['updated'][] = (int) $id;
+ }
+ }
+
+ return $changes;
+ }
+
+ /**
+ * Update an existing pivot record on the table.
+ *
+ * @param mixed $id
+ * @param array $attributes
+ * @param bool $touch
+ * @return void
+ */
+ public function updateExistingPivot($id, array $attributes, $touch = true)
+ {
+ if (in_array($this->updatedAt(), $this->pivotColumns))
+ {
+ $attributes = $this->setTimestampsOnAttach($attributes, true);
+ }
+
+ $updated = $this->newPivotStatementForId($id)->update($attributes);
+
+ if ($touch) $this->touchIfTouching();
+
+ return $updated;
+ }
+
+ /**
+ * Attach a model to the parent.
+ *
+ * @param mixed $id
+ * @param array $attributes
+ * @param bool $touch
+ * @return void
+ */
+ public function attach($id, array $attributes = array(), $touch = true)
+ {
+ if ($id instanceof Model) $id = $id->getKey();
+
+ $query = $this->newPivotStatement();
+
+ $query->insert($this->createAttachRecords((array) $id, $attributes));
+
+ if ($touch) $this->touchIfTouching();
+ }
+
+ /**
+ * Create an array of records to insert into the pivot table.
+ *
+ * @param array $ids
+ * @param array $attributes
+ * @return array
+ */
+ protected function createAttachRecords($ids, array $attributes)
+ {
+ $records = array();
+
+ $timed = ($this->hasPivotColumn($this->createdAt()) || $this->hasPivotColumn($this->updatedAt()));
+
+ // To create the attachment records, we will simply spin through the IDs given
+ // and create a new record to insert for each ID. Each ID may actually be a
+ // key in the array, with extra attributes to be placed in other columns.
+ foreach ($ids as $key => $value)
+ {
+ $records[] = $this->attacher($key, $value, $attributes, $timed);
+ }
+
+ return $records;
+ }
+
+ /**
+ * Create a full attachment record payload.
+ *
+ * @param int $key
+ * @param mixed $value
+ * @param array $attributes
+ * @param bool $timed
+ * @return array
+ */
+ protected function attacher($key, $value, $attributes, $timed)
+ {
+ list($id, $extra) = $this->getAttachId($key, $value, $attributes);
+
+ // To create the attachment records, we will simply spin through the IDs given
+ // and create a new record to insert for each ID. Each ID may actually be a
+ // key in the array, with extra attributes to be placed in other columns.
+ $record = $this->createAttachRecord($id, $timed);
+
+ return array_merge($record, $extra);
+ }
+
+ /**
+ * Get the attach record ID and extra attributes.
+ *
+ * @param mixed $key
+ * @param mixed $value
+ * @param array $attributes
+ * @return array
+ */
+ protected function getAttachId($key, $value, array $attributes)
+ {
+ if (is_array($value))
+ {
+ return array($key, array_merge($value, $attributes));
+ }
+
+ return array($value, $attributes);
+ }
+
+ /**
+ * Create a new pivot attachment record.
+ *
+ * @param int $id
+ * @param bool $timed
+ * @return array
+ */
+ protected function createAttachRecord($id, $timed)
+ {
+ $record[$this->foreignKey] = $this->parent->getKey();
+
+ $record[$this->otherKey] = $id;
+
+ // If the record needs to have creation and update timestamps, we will make
+ // them by calling the parent model's "freshTimestamp" method which will
+ // provide us with a fresh timestamp in this model's preferred format.
+ if ($timed)
+ {
+ $record = $this->setTimestampsOnAttach($record);
+ }
+
+ return $record;
+ }
+
+ /**
+ * Set the creation and update timestamps on an attach record.
+ *
+ * @param array $record
+ * @param bool $exists
+ * @return array
+ */
+ protected function setTimestampsOnAttach(array $record, $exists = false)
+ {
+ $fresh = $this->parent->freshTimestamp();
+
+ if ( ! $exists && $this->hasPivotColumn($this->createdAt()))
+ {
+ $record[$this->createdAt()] = $fresh;
+ }
+
+ if ($this->hasPivotColumn($this->updatedAt()))
+ {
+ $record[$this->updatedAt()] = $fresh;
+ }
+
+ return $record;
+ }
+
+ /**
+ * Detach models from the relationship.
+ *
+ * @param int|array $ids
+ * @param bool $touch
+ * @return int
+ */
+ public function detach($ids = array(), $touch = true)
+ {
+ if ($ids instanceof Model) $ids = (array) $ids->getKey();
+
+ $query = $this->newPivotQuery();
+
+ // If associated IDs were passed to the method we will only delete those
+ // associations, otherwise all of the association ties will be broken.
+ // We'll return the numbers of affected rows when we do the deletes.
+ $ids = (array) $ids;
+
+ if (count($ids) > 0)
+ {
+ $query->whereIn($this->otherKey, (array) $ids);
+ }
+
+ if ($touch) $this->touchIfTouching();
+
+ // Once we have all of the conditions set on the statement, we are ready
+ // to run the delete on the pivot table. Then, if the touch parameter
+ // is true, we will go ahead and touch all related models to sync.
+ $results = $query->delete();
+
+ return $results;
+ }
+
+ /**
+ * If we're touching the parent model, touch.
+ *
+ * @return void
+ */
+ public function touchIfTouching()
+ {
+ if ($this->touchingParent()) $this->getParent()->touch();
+
+ if ($this->getParent()->touches($this->relationName)) $this->touch();
+ }
+
+ /**
+ * Determine if we should touch the parent on sync.
+ *
+ * @return bool
+ */
+ protected function touchingParent()
+ {
+ return $this->getRelated()->touches($this->guessInverseRelation());
+ }
+
+ /**
+ * Attempt to guess the name of the inverse of the relation.
+ *
+ * @return string
+ */
+ protected function guessInverseRelation()
+ {
+ return camel_case(str_plural(class_basename($this->getParent())));
+ }
+
+ /**
+ * Create a new query builder for the pivot table.
+ *
+ * @return \Illuminate\Database\Query\Builder
+ */
+ protected function newPivotQuery()
+ {
+ $query = $this->newPivotStatement();
+
+ foreach ($this->pivotWheres as $whereArgs)
+ {
+ call_user_func_array([$query, 'where'], $whereArgs);
+ }
+
+ return $query->where($this->foreignKey, $this->parent->getKey());
+ }
+
+ /**
+ * Get a new plain query builder for the pivot table.
+ *
+ * @return \Illuminate\Database\Query\Builder
+ */
+ public function newPivotStatement()
+ {
+ return $this->query->getQuery()->newQuery()->from($this->table);
+ }
+
+ /**
+ * Get a new pivot statement for a given "other" ID.
+ *
+ * @param mixed $id
+ * @return \Illuminate\Database\Query\Builder
+ */
+ public function newPivotStatementForId($id)
+ {
+ return $this->newPivotQuery()->where($this->otherKey, $id);
+ }
+
+ /**
+ * Create a new pivot model instance.
+ *
+ * @param array $attributes
+ * @param bool $exists
+ * @return \Illuminate\Database\Eloquent\Relations\Pivot
+ */
+ public function newPivot(array $attributes = array(), $exists = false)
+ {
+ $pivot = $this->related->newPivot($this->parent, $attributes, $this->table, $exists);
+
+ return $pivot->setPivotKeys($this->foreignKey, $this->otherKey);
+ }
+
+ /**
+ * Create a new existing pivot model instance.
+ *
+ * @param array $attributes
+ * @return \Illuminate\Database\Eloquent\Relations\Pivot
+ */
+ public function newExistingPivot(array $attributes = array())
+ {
+ return $this->newPivot($attributes, true);
+ }
+
+ /**
+ * Set the columns on the pivot table to retrieve.
+ *
+ * @param mixed $columns
+ * @return $this
+ */
+ public function withPivot($columns)
+ {
+ $columns = is_array($columns) ? $columns : func_get_args();
+
+ $this->pivotColumns = array_merge($this->pivotColumns, $columns);
+
+ return $this;
+ }
+
+ /**
+ * Specify that the pivot table has creation and update timestamps.
+ *
+ * @param mixed $createdAt
+ * @param mixed $updatedAt
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ */
+ public function withTimestamps($createdAt = null, $updatedAt = null)
+ {
+ return $this->withPivot($createdAt ?: $this->createdAt(), $updatedAt ?: $this->updatedAt());
+ }
+
+ /**
+ * Get the related model's updated at column name.
+ *
+ * @return string
+ */
+ public function getRelatedFreshUpdate()
+ {
+ return array($this->related->getUpdatedAtColumn() => $this->related->freshTimestamp());
+ }
+
+ /**
+ * Get the key for comparing against the parent key in "has" query.
+ *
+ * @return string
+ */
+ public function getHasCompareKey()
+ {
+ return $this->getForeignKey();
+ }
+
+ /**
+ * Get the fully qualified foreign key for the relation.
+ *
+ * @return string
+ */
+ public function getForeignKey()
+ {
+ return $this->table.'.'.$this->foreignKey;
+ }
+
+ /**
+ * Get the fully qualified "other key" for the relation.
+ *
+ * @return string
+ */
+ public function getOtherKey()
+ {
+ return $this->table.'.'.$this->otherKey;
+ }
+
+ /**
+ * Get the intermediate table for the relationship.
+ *
+ * @return string
+ */
+ public function getTable()
+ {
+ return $this->table;
+ }
+
+ /**
+ * Get the relationship name for the relationship.
+ *
+ * @return string
+ */
+ public function getRelationName()
+ {
+ return $this->relationName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasMany.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasMany.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasMany.php
new file mode 100755
index 0000000..159a658
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasMany.php
@@ -0,0 +1,47 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Collection;
+
+class HasMany extends HasOneOrMany {
+
+ /**
+ * Get the results of the relationship.
+ *
+ * @return mixed
+ */
+ public function getResults()
+ {
+ return $this->query->get();
+ }
+
+ /**
+ * Initialize the relation on a set of models.
+ *
+ * @param array $models
+ * @param string $relation
+ * @return array
+ */
+ public function initRelation(array $models, $relation)
+ {
+ foreach ($models as $model)
+ {
+ $model->setRelation($relation, $this->related->newCollection());
+ }
+
+ return $models;
+ }
+
+ /**
+ * Match the eagerly loaded results to their parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ public function match(array $models, Collection $results, $relation)
+ {
+ return $this->matchMany($models, $results, $relation);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
new file mode 100644
index 0000000..d0e33a7
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
@@ -0,0 +1,263 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Query\Expression;
+use Illuminate\Database\Eloquent\Collection;
+
+class HasManyThrough extends Relation {
+
+ /**
+ * The distance parent model instance.
+ *
+ * @var \Illuminate\Database\Eloquent\Model
+ */
+ protected $farParent;
+
+ /**
+ * The near key on the relationship.
+ *
+ * @var string
+ */
+ protected $firstKey;
+
+ /**
+ * The far key on the relationship.
+ *
+ * @var string
+ */
+ protected $secondKey;
+
+ /**
+ * Create a new has many relationship instance.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Model $farParent
+ * @param \Illuminate\Database\Eloquent\Model $parent
+ * @param string $firstKey
+ * @param string $secondKey
+ * @return void
+ */
+ public function __construct(Builder $query, Model $farParent, Model $parent, $firstKey, $secondKey)
+ {
+ $this->firstKey = $firstKey;
+ $this->secondKey = $secondKey;
+ $this->farParent = $farParent;
+
+ parent::__construct($query, $parent);
+ }
+
+ /**
+ * Set the base constraints on the relation query.
+ *
+ * @return void
+ */
+ public function addConstraints()
+ {
+ $parentTable = $this->parent->getTable();
+
+ $this->setJoin();
+
+ if (static::$constraints)
+ {
+ $this->query->where($parentTable.'.'.$this->firstKey, '=', $this->farParent->getKey());
+ }
+ }
+
+ /**
+ * Add the constraints for a relationship count query.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Builder $parent
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ public function getRelationCountQuery(Builder $query, Builder $parent)
+ {
+ $parentTable = $this->parent->getTable();
+
+ $this->setJoin($query);
+
+ $query->select(new Expression('count(*)'));
+
+ $key = $this->wrap($parentTable.'.'.$this->firstKey);
+
+ return $query->where($this->getHasCompareKey(), '=', new Expression($key));
+ }
+
+ /**
+ * Set the join clause on the query.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder|null $query
+ * @return void
+ */
+ protected function setJoin(Builder $query = null)
+ {
+ $query = $query ?: $this->query;
+
+ $foreignKey = $this->related->getTable().'.'.$this->secondKey;
+
+ $query->join($this->parent->getTable(), $this->getQualifiedParentKeyName(), '=', $foreignKey);
+ }
+
+ /**
+ * Set the constraints for an eager load of the relation.
+ *
+ * @param array $models
+ * @return void
+ */
+ public function addEagerConstraints(array $models)
+ {
+ $table = $this->parent->getTable();
+
+ $this->query->whereIn($table.'.'.$this->firstKey, $this->getKeys($models));
+ }
+
+ /**
+ * Initialize the relation on a set of models.
+ *
+ * @param array $models
+ * @param string $relation
+ * @return array
+ */
+ public function initRelation(array $models, $relation)
+ {
+ foreach ($models as $model)
+ {
+ $model->setRelation($relation, $this->related->newCollection());
+ }
+
+ return $models;
+ }
+
+ /**
+ * Match the eagerly loaded results to their parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ public function match(array $models, Collection $results, $relation)
+ {
+ $dictionary = $this->buildDictionary($results);
+
+ // Once we have the dictionary we can simply spin through the parent models to
+ // link them up with their children using the keyed dictionary to make the
+ // matching very convenient and easy work. Then we'll just return them.
+ foreach ($models as $model)
+ {
+ $key = $model->getKey();
+
+ if (isset($dictionary[$key]))
+ {
+ $value = $this->related->newCollection($dictionary[$key]);
+
+ $model->setRelation($relation, $value);
+ }
+ }
+
+ return $models;
+ }
+
+ /**
+ * Build model dictionary keyed by the relation's foreign key.
+ *
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @return array
+ */
+ protected function buildDictionary(Collection $results)
+ {
+ $dictionary = array();
+
+ $foreign = $this->firstKey;
+
+ // First we will create a dictionary of models keyed by the foreign key of the
+ // relationship as this will allow us to quickly access all of the related
+ // models without having to do nested looping which will be quite slow.
+ foreach ($results as $result)
+ {
+ $dictionary[$result->{$foreign}][] = $result;
+ }
+
+ return $dictionary;
+ }
+
+ /**
+ * Get the results of the relationship.
+ *
+ * @return mixed
+ */
+ public function getResults()
+ {
+ return $this->get();
+ }
+
+ /**
+ * Execute the query as a "select" statement.
+ *
+ * @param array $columns
+ * @return \Illuminate\Database\Eloquent\Collection
+ */
+ public function get($columns = array('*'))
+ {
+ // First we'll add the proper select columns onto the query so it is run with
+ // the proper columns. Then, we will get the results and hydrate out pivot
+ // models with the result of those columns as a separate model relation.
+ $select = $this->getSelectColumns($columns);
+
+ $models = $this->query->addSelect($select)->getModels();
+
+ // If we actually found models we will also eager load any relationships that
+ // have been specified as needing to be eager loaded. This will solve the
+ // n + 1 query problem for the developer and also increase performance.
+ if (count($models) > 0)
+ {
+ $models = $this->query->eagerLoadRelations($models);
+ }
+
+ return $this->related->newCollection($models);
+ }
+
+ /**
+ * Set the select clause for the relation query.
+ *
+ * @param array $columns
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ */
+ protected function getSelectColumns(array $columns = array('*'))
+ {
+ if ($columns == array('*'))
+ {
+ $columns = array($this->related->getTable().'.*');
+ }
+
+ return array_merge($columns, array($this->parent->getTable().'.'.$this->firstKey));
+ }
+
+ /**
+ * Get a paginator for the "select" statement.
+ *
+ * @param int $perPage
+ * @param array $columns
+ * @return \Illuminate\Pagination\Paginator
+ */
+ public function paginate($perPage = null, $columns = array('*'))
+ {
+ $this->query->addSelect($this->getSelectColumns($columns));
+
+ $pager = $this->query->paginate($perPage, $columns);
+
+ return $pager;
+ }
+
+ /**
+ * Get the key for comparing against the parent key in "has" query.
+ *
+ * @return string
+ */
+ public function getHasCompareKey()
+ {
+ return $this->farParent->getQualifiedKeyName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOne.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOne.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOne.php
new file mode 100755
index 0000000..fd0f9a0
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOne.php
@@ -0,0 +1,47 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Collection;
+
+class HasOne extends HasOneOrMany {
+
+ /**
+ * Get the results of the relationship.
+ *
+ * @return mixed
+ */
+ public function getResults()
+ {
+ return $this->query->first();
+ }
+
+ /**
+ * Initialize the relation on a set of models.
+ *
+ * @param array $models
+ * @param string $relation
+ * @return array
+ */
+ public function initRelation(array $models, $relation)
+ {
+ foreach ($models as $model)
+ {
+ $model->setRelation($relation, null);
+ }
+
+ return $models;
+ }
+
+ /**
+ * Match the eagerly loaded results to their parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ public function match(array $models, Collection $results, $relation)
+ {
+ return $this->matchOne($models, $results, $relation);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
new file mode 100755
index 0000000..83bc7ee
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
@@ -0,0 +1,291 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
+
+abstract class HasOneOrMany extends Relation {
+
+ /**
+ * The foreign key of the parent model.
+ *
+ * @var string
+ */
+ protected $foreignKey;
+
+ /**
+ * The local key of the parent model.
+ *
+ * @var string
+ */
+ protected $localKey;
+
+ /**
+ * Create a new has many relationship instance.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Model $parent
+ * @param string $foreignKey
+ * @param string $localKey
+ * @return void
+ */
+ public function __construct(Builder $query, Model $parent, $foreignKey, $localKey)
+ {
+ $this->localKey = $localKey;
+ $this->foreignKey = $foreignKey;
+
+ parent::__construct($query, $parent);
+ }
+
+ /**
+ * Set the base constraints on the relation query.
+ *
+ * @return void
+ */
+ public function addConstraints()
+ {
+ if (static::$constraints)
+ {
+ $this->query->where($this->foreignKey, '=', $this->getParentKey());
+ }
+ }
+
+ /**
+ * Set the constraints for an eager load of the relation.
+ *
+ * @param array $models
+ * @return void
+ */
+ public function addEagerConstraints(array $models)
+ {
+ $this->query->whereIn($this->foreignKey, $this->getKeys($models, $this->localKey));
+ }
+
+ /**
+ * Match the eagerly loaded results to their single parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ public function matchOne(array $models, Collection $results, $relation)
+ {
+ return $this->matchOneOrMany($models, $results, $relation, 'one');
+ }
+
+ /**
+ * Match the eagerly loaded results to their many parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ public function matchMany(array $models, Collection $results, $relation)
+ {
+ return $this->matchOneOrMany($models, $results, $relation, 'many');
+ }
+
+ /**
+ * Match the eagerly loaded results to their many parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @param string $type
+ * @return array
+ */
+ protected function matchOneOrMany(array $models, Collection $results, $relation, $type)
+ {
+ $dictionary = $this->buildDictionary($results);
+
+ // Once we have the dictionary we can simply spin through the parent models to
+ // link them up with their children using the keyed dictionary to make the
+ // matching very convenient and easy work. Then we'll just return them.
+ foreach ($models as $model)
+ {
+ $key = $model->getAttribute($this->localKey);
+
+ if (isset($dictionary[$key]))
+ {
+ $value = $this->getRelationValue($dictionary, $key, $type);
+
+ $model->setRelation($relation, $value);
+ }
+ }
+
+ return $models;
+ }
+
+ /**
+ * Get the value of a relationship by one or many type.
+ *
+ * @param array $dictionary
+ * @param string $key
+ * @param string $type
+ * @return mixed
+ */
+ protected function getRelationValue(array $dictionary, $key, $type)
+ {
+ $value = $dictionary[$key];
+
+ return $type == 'one' ? reset($value) : $this->related->newCollection($value);
+ }
+
+ /**
+ * Build model dictionary keyed by the relation's foreign key.
+ *
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @return array
+ */
+ protected function buildDictionary(Collection $results)
+ {
+ $dictionary = array();
+
+ $foreign = $this->getPlainForeignKey();
+
+ // First we will create a dictionary of models keyed by the foreign key of the
+ // relationship as this will allow us to quickly access all of the related
+ // models without having to do nested looping which will be quite slow.
+ foreach ($results as $result)
+ {
+ $dictionary[$result->{$foreign}][] = $result;
+ }
+
+ return $dictionary;
+ }
+
+ /**
+ * Attach a model instance to the parent model.
+ *
+ * @param \Illuminate\Database\Eloquent\Model $model
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function save(Model $model)
+ {
+ $model->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
+
+ return $model->save() ? $model : false;
+ }
+
+ /**
+ * Attach an array of models to the parent instance.
+ *
+ * @param array $models
+ * @return array
+ */
+ public function saveMany(array $models)
+ {
+ array_walk($models, array($this, 'save'));
+
+ return $models;
+ }
+
+ /**
+ * Create a new instance of the related model.
+ *
+ * @param array $attributes
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function create(array $attributes)
+ {
+ // Here we will set the raw attributes to avoid hitting the "fill" method so
+ // that we do not have to worry about a mass accessor rules blocking sets
+ // on the models. Otherwise, some of these attributes will not get set.
+ $instance = $this->related->newInstance($attributes);
+
+ $instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
+
+ $instance->save();
+
+ return $instance;
+ }
+
+ /**
+ * Create an array of new instances of the related model.
+ *
+ * @param array $records
+ * @return array
+ */
+ public function createMany(array $records)
+ {
+ $instances = array();
+
+ foreach ($records as $record)
+ {
+ $instances[] = $this->create($record);
+ }
+
+ return $instances;
+ }
+
+ /**
+ * Perform an update on all the related models.
+ *
+ * @param array $attributes
+ * @return int
+ */
+ public function update(array $attributes)
+ {
+ if ($this->related->usesTimestamps())
+ {
+ $attributes[$this->relatedUpdatedAt()] = $this->related->freshTimestamp();
+ }
+
+ return $this->query->update($attributes);
+ }
+
+ /**
+ * Get the key for comparing against the parent key in "has" query.
+ *
+ * @return string
+ */
+ public function getHasCompareKey()
+ {
+ return $this->getForeignKey();
+ }
+
+ /**
+ * Get the foreign key for the relationship.
+ *
+ * @return string
+ */
+ public function getForeignKey()
+ {
+ return $this->foreignKey;
+ }
+
+ /**
+ * Get the plain foreign key.
+ *
+ * @return string
+ */
+ public function getPlainForeignKey()
+ {
+ $segments = explode('.', $this->getForeignKey());
+
+ return $segments[count($segments) - 1];
+ }
+
+ /**
+ * Get the key value of the parent's local key.
+ *
+ * @return mixed
+ */
+ public function getParentKey()
+ {
+ return $this->parent->getAttribute($this->localKey);
+ }
+
+ /**
+ * Get the fully qualified parent key name.
+ *
+ * @return string
+ */
+ public function getQualifiedParentKeyName()
+ {
+ return $this->parent->getTable().'.'.$this->localKey;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphMany.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphMany.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphMany.php
new file mode 100755
index 0000000..1abdf37
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphMany.php
@@ -0,0 +1,47 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Collection;
+
+class MorphMany extends MorphOneOrMany {
+
+ /**
+ * Get the results of the relationship.
+ *
+ * @return mixed
+ */
+ public function getResults()
+ {
+ return $this->query->get();
+ }
+
+ /**
+ * Initialize the relation on a set of models.
+ *
+ * @param array $models
+ * @param string $relation
+ * @return array
+ */
+ public function initRelation(array $models, $relation)
+ {
+ foreach ($models as $model)
+ {
+ $model->setRelation($relation, $this->related->newCollection());
+ }
+
+ return $models;
+ }
+
+ /**
+ * Match the eagerly loaded results to their parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ public function match(array $models, Collection $results, $relation)
+ {
+ return $this->matchMany($models, $results, $relation);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOne.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOne.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOne.php
new file mode 100755
index 0000000..fdebc24
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOne.php
@@ -0,0 +1,47 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Collection;
+
+class MorphOne extends MorphOneOrMany {
+
+ /**
+ * Get the results of the relationship.
+ *
+ * @return mixed
+ */
+ public function getResults()
+ {
+ return $this->query->first();
+ }
+
+ /**
+ * Initialize the relation on a set of models.
+ *
+ * @param array $models
+ * @param string $relation
+ * @return array
+ */
+ public function initRelation(array $models, $relation)
+ {
+ foreach ($models as $model)
+ {
+ $model->setRelation($relation, null);
+ }
+
+ return $models;
+ }
+
+ /**
+ * Match the eagerly loaded results to their parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ public function match(array $models, Collection $results, $relation)
+ {
+ return $this->matchOne($models, $results, $relation);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php
new file mode 100755
index 0000000..4a20351
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php
@@ -0,0 +1,159 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Builder;
+
+abstract class MorphOneOrMany extends HasOneOrMany {
+
+ /**
+ * The foreign key type for the relationship.
+ *
+ * @var string
+ */
+ protected $morphType;
+
+ /**
+ * The class name of the parent model.
+ *
+ * @var string
+ */
+ protected $morphClass;
+
+ /**
+ * Create a new has many relationship instance.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Model $parent
+ * @param string $type
+ * @param string $id
+ * @param string $localKey
+ * @return void
+ */
+ public function __construct(Builder $query, Model $parent, $type, $id, $localKey)
+ {
+ $this->morphType = $type;
+
+ $this->morphClass = $parent->getMorphClass();
+
+ parent::__construct($query, $parent, $id, $localKey);
+ }
+
+ /**
+ * Set the base constraints on the relation query.
+ *
+ * @return void
+ */
+ public function addConstraints()
+ {
+ if (static::$constraints)
+ {
+ parent::addConstraints();
+
+ $this->query->where($this->morphType, $this->morphClass);
+ }
+ }
+
+ /**
+ * Get the relationship count query.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Builder $parent
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ public function getRelationCountQuery(Builder $query, Builder $parent)
+ {
+ $query = parent::getRelationCountQuery($query, $parent);
+
+ return $query->where($this->morphType, $this->morphClass);
+ }
+
+ /**
+ * Set the constraints for an eager load of the relation.
+ *
+ * @param array $models
+ * @return void
+ */
+ public function addEagerConstraints(array $models)
+ {
+ parent::addEagerConstraints($models);
+
+ $this->query->where($this->morphType, $this->morphClass);
+ }
+
+ /**
+ * Attach a model instance to the parent model.
+ *
+ * @param \Illuminate\Database\Eloquent\Model $model
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function save(Model $model)
+ {
+ $model->setAttribute($this->getPlainMorphType(), $this->morphClass);
+
+ return parent::save($model);
+ }
+
+ /**
+ * Create a new instance of the related model.
+ *
+ * @param array $attributes
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function create(array $attributes)
+ {
+ $instance = $this->related->newInstance($attributes);
+
+ // When saving a polymorphic relationship, we need to set not only the foreign
+ // key, but also the foreign key type, which is typically the class name of
+ // the parent model. This makes the polymorphic item unique in the table.
+ $this->setForeignAttributesForCreate($instance);
+
+ $instance->save();
+
+ return $instance;
+ }
+
+ /**
+ * Set the foreign ID and type for creating a related model.
+ *
+ * @param \Illuminate\Database\Eloquent\Model $model
+ * @return void
+ */
+ protected function setForeignAttributesForCreate(Model $model)
+ {
+ $model->{$this->getPlainForeignKey()} = $this->getParentKey();
+
+ $model->{last(explode('.', $this->morphType))} = $this->morphClass;
+ }
+
+ /**
+ * Get the foreign key "type" name.
+ *
+ * @return string
+ */
+ public function getMorphType()
+ {
+ return $this->morphType;
+ }
+
+ /**
+ * Get the plain morph type name without the table.
+ *
+ * @return string
+ */
+ public function getPlainMorphType()
+ {
+ return last(explode('.', $this->morphType));
+ }
+
+ /**
+ * Get the class name of the parent model.
+ *
+ * @return string
+ */
+ public function getMorphClass()
+ {
+ return $this->morphClass;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphPivot.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphPivot.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphPivot.php
new file mode 100644
index 0000000..d6c773f
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphPivot.php
@@ -0,0 +1,79 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Builder;
+
+class MorphPivot extends Pivot {
+
+ /**
+ * The type of the polymorphic relation.
+ *
+ * Explicitly define this so it's not included in saved attributes.
+ *
+ * @var string
+ */
+ protected $morphType;
+
+ /**
+ * The value of the polymorphic relation.
+ *
+ * Explicitly define this so it's not included in saved attributes.
+ *
+ * @var string
+ */
+ protected $morphClass;
+
+ /**
+ * Set the keys for a save update query.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ protected function setKeysForSaveQuery(Builder $query)
+ {
+ $query->where($this->morphType, $this->morphClass);
+
+ return parent::setKeysForSaveQuery($query);
+ }
+
+ /**
+ * Delete the pivot model record from the database.
+ *
+ * @return int
+ */
+ public function delete()
+ {
+ $query = $this->getDeleteQuery();
+
+ $query->where($this->morphType, $this->morphClass);
+
+ return $query->delete();
+ }
+
+ /**
+ * Set the morph type for the pivot.
+ *
+ * @param string $morphType
+ * @return $this
+ */
+ public function setMorphType($morphType)
+ {
+ $this->morphType = $morphType;
+
+ return $this;
+ }
+
+ /**
+ * Set the morph class for the pivot.
+ *
+ * @param string $morphClass
+ * @return \Illuminate\Database\Eloquent\Relations\MorphPivot
+ */
+ public function setMorphClass($morphClass)
+ {
+ $this->morphClass = $morphClass;
+
+ return $this;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php
new file mode 100644
index 0000000..cd9948f
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php
@@ -0,0 +1,246 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Collection as BaseCollection;
+
+class MorphTo extends BelongsTo {
+
+ /**
+ * The type of the polymorphic relation.
+ *
+ * @var string
+ */
+ protected $morphType;
+
+ /**
+ * The models whose relations are being eager loaded.
+ *
+ * @var \Illuminate\Database\Eloquent\Collection
+ */
+ protected $models;
+
+ /**
+ * All of the models keyed by ID.
+ *
+ * @var array
+ */
+ protected $dictionary = array();
+
+ /*
+ * Indicates if soft-deleted model instances should be fetched.
+ *
+ * @var bool
+ */
+ protected $withTrashed = false;
+
+ /**
+ * Create a new belongs to relationship instance.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Model $parent
+ * @param string $foreignKey
+ * @param string $otherKey
+ * @param string $type
+ * @param string $relation
+ * @return void
+ */
+ public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $type, $relation)
+ {
+ $this->morphType = $type;
+
+ parent::__construct($query, $parent, $foreignKey, $otherKey, $relation);
+ }
+
+ /**
+ * Set the constraints for an eager load of the relation.
+ *
+ * @param array $models
+ * @return void
+ */
+ public function addEagerConstraints(array $models)
+ {
+ $this->buildDictionary($this->models = Collection::make($models));
+ }
+
+ /**
+ * Build a dictionary with the models.
+ *
+ * @param \Illuminate\Database\Eloquent\Collection $models
+ * @return void
+ */
+ protected function buildDictionary(Collection $models)
+ {
+ foreach ($models as $model)
+ {
+ if ($model->{$this->morphType})
+ {
+ $this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}][] = $model;
+ }
+ }
+ }
+
+ /**
+ * Match the eagerly loaded results to their parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ public function match(array $models, Collection $results, $relation)
+ {
+ return $models;
+ }
+
+ /**
+ * Associate the model instance to the given parent.
+ *
+ * @param \Illuminate\Database\Eloquent\Model $model
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function associate(Model $model)
+ {
+ $this->parent->setAttribute($this->foreignKey, $model->getKey());
+
+ $this->parent->setAttribute($this->morphType, $model->getMorphClass());
+
+ return $this->parent->setRelation($this->relation, $model);
+ }
+
+ /**
+ * Get the results of the relationship.
+ *
+ * Called via eager load method of Eloquent query builder.
+ *
+ * @return mixed
+ */
+ public function getEager()
+ {
+ foreach (array_keys($this->dictionary) as $type)
+ {
+ $this->matchToMorphParents($type, $this->getResultsByType($type));
+ }
+
+ return $this->models;
+ }
+
+ /**
+ * Match the results for a given type to their parents.
+ *
+ * @param string $type
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @return void
+ */
+ protected function matchToMorphParents($type, Collection $results)
+ {
+ foreach ($results as $result)
+ {
+ if (isset($this->dictionary[$type][$result->getKey()]))
+ {
+ foreach ($this->dictionary[$type][$result->getKey()] as $model)
+ {
+ $model->setRelation($this->relation, $result);
+ }
+ }
+ }
+ }
+
+ /**
+ * Get all of the relation results for a type.
+ *
+ * @param string $type
+ * @return \Illuminate\Database\Eloquent\Collection
+ */
+ protected function getResultsByType($type)
+ {
+ $instance = $this->createModelByType($type);
+
+ $key = $instance->getKeyName();
+
+ $query = $instance->newQuery();
+
+ $query = $this->useWithTrashed($query);
+
+ return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get();
+ }
+
+ /**
+ * Gather all of the foreign keys for a given type.
+ *
+ * @param string $type
+ * @return array
+ */
+ protected function gatherKeysByType($type)
+ {
+ $foreign = $this->foreignKey;
+
+ return BaseCollection::make($this->dictionary[$type])->map(function($models) use ($foreign)
+ {
+ return head($models)->{$foreign};
+
+ })->unique();
+ }
+
+ /**
+ * Create a new model instance by type.
+ *
+ * @param string $type
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function createModelByType($type)
+ {
+ return new $type;
+ }
+
+ /**
+ * Get the foreign key "type" name.
+ *
+ * @return string
+ */
+ public function getMorphType()
+ {
+ return $this->morphType;
+ }
+
+ /**
+ * Get the dictionary used by the relationship.
+ *
+ * @return array
+ */
+ public function getDictionary()
+ {
+ return $this->dictionary;
+ }
+
+ /**
+ * Fetch soft-deleted model instances with query
+ *
+ * @return $this
+ */
+ public function withTrashed()
+ {
+ $this->withTrashed = true;
+
+ $this->query = $this->useWithTrashed($this->query);
+
+ return $this;
+ }
+
+ /**
+ * Return trashed models with query if told so
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ protected function useWithTrashed(Builder $query)
+ {
+ if ($this->withTrashed && $query->getMacro('withTrashed') !== null)
+ {
+ return $query->withTrashed();
+ }
+ return $query;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
new file mode 100644
index 0000000..2d8d6ac
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
@@ -0,0 +1,158 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Builder;
+
+class MorphToMany extends BelongsToMany {
+
+ /**
+ * The type of the polymorphic relation.
+ *
+ * @var string
+ */
+ protected $morphType;
+
+ /**
+ * The class name of the morph type constraint.
+ *
+ * @var string
+ */
+ protected $morphClass;
+
+ /**
+ * Indicates if we are connecting the inverse of the relation.
+ *
+ * This primarily affects the morphClass constraint.
+ *
+ * @var bool
+ */
+ protected $inverse;
+
+ /**
+ * Create a new has many relationship instance.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Model $parent
+ * @param string $name
+ * @param string $table
+ * @param string $foreignKey
+ * @param string $otherKey
+ * @param string $relationName
+ * @param bool $inverse
+ * @return void
+ */
+ public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false)
+ {
+ $this->inverse = $inverse;
+ $this->morphType = $name.'_type';
+ $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass();
+
+ parent::__construct($query, $parent, $table, $foreignKey, $otherKey, $relationName);
+ }
+
+ /**
+ * Set the where clause for the relation query.
+ *
+ * @return $this
+ */
+ protected function setWhere()
+ {
+ parent::setWhere();
+
+ $this->query->where($this->table.'.'.$this->morphType, $this->morphClass);
+
+ return $this;
+ }
+
+ /**
+ * Add the constraints for a relationship count query.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Builder $parent
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ public function getRelationCountQuery(Builder $query, Builder $parent)
+ {
+ $query = parent::getRelationCountQuery($query, $parent);
+
+ return $query->where($this->table.'.'.$this->morphType, $this->morphClass);
+ }
+
+ /**
+ * Set the constraints for an eager load of the relation.
+ *
+ * @param array $models
+ * @return void
+ */
+ public function addEagerConstraints(array $models)
+ {
+ parent::addEagerConstraints($models);
+
+ $this->query->where($this->table.'.'.$this->morphType, $this->morphClass);
+ }
+
+ /**
+ * Create a new pivot attachment record.
+ *
+ * @param int $id
+ * @param bool $timed
+ * @return array
+ */
+ protected function createAttachRecord($id, $timed)
+ {
+ $record = parent::createAttachRecord($id, $timed);
+
+ return array_add($record, $this->morphType, $this->morphClass);
+ }
+
+ /**
+ * Create a new query builder for the pivot table.
+ *
+ * @return \Illuminate\Database\Query\Builder
+ */
+ protected function newPivotQuery()
+ {
+ $query = parent::newPivotQuery();
+
+ return $query->where($this->morphType, $this->morphClass);
+ }
+
+ /**
+ * Create a new pivot model instance.
+ *
+ * @param array $attributes
+ * @param bool $exists
+ * @return \Illuminate\Database\Eloquent\Relations\Pivot
+ */
+ public function newPivot(array $attributes = array(), $exists = false)
+ {
+ $pivot = new MorphPivot($this->parent, $attributes, $this->table, $exists);
+
+ $pivot->setPivotKeys($this->foreignKey, $this->otherKey)
+ ->setMorphType($this->morphType)
+ ->setMorphClass($this->morphClass);
+
+ return $pivot;
+ }
+
+ /**
+ * Get the foreign key "type" name.
+ *
+ * @return string
+ */
+ public function getMorphType()
+ {
+ return $this->morphType;
+ }
+
+ /**
+ * Get the class name of the parent model.
+ *
+ * @return string
+ */
+ public function getMorphClass()
+ {
+ return $this->morphClass;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Pivot.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Pivot.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Pivot.php
new file mode 100755
index 0000000..365477e
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Pivot.php
@@ -0,0 +1,171 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Builder;
+
+class Pivot extends Model {
+
+ /**
+ * The parent model of the relationship.
+ *
+ * @var \Illuminate\Database\Eloquent\Model
+ */
+ protected $parent;
+
+ /**
+ * The name of the foreign key column.
+ *
+ * @var string
+ */
+ protected $foreignKey;
+
+ /**
+ * The name of the "other key" column.
+ *
+ * @var string
+ */
+ protected $otherKey;
+
+ /**
+ * The attributes that aren't mass assignable.
+ *
+ * @var array
+ */
+ protected $guarded = array();
+
+ /**
+ * Create a new pivot model instance.
+ *
+ * @param \Illuminate\Database\Eloquent\Model $parent
+ * @param array $attributes
+ * @param string $table
+ * @param bool $exists
+ * @return void
+ */
+ public function __construct(Model $parent, $attributes, $table, $exists = false)
+ {
+ parent::__construct();
+
+ // The pivot model is a "dynamic" model since we will set the tables dynamically
+ // for the instance. This allows it work for any intermediate tables for the
+ // many to many relationship that are defined by this developer's classes.
+ $this->setRawAttributes($attributes, true);
+
+ $this->setTable($table);
+
+ $this->setConnection($parent->getConnectionName());
+
+ // We store off the parent instance so we will access the timestamp column names
+ // for the model, since the pivot model timestamps aren't easily configurable
+ // from the developer's point of view. We can use the parents to get these.
+ $this->parent = $parent;
+
+ $this->exists = $exists;
+
+ $this->timestamps = $this->hasTimestampAttributes();
+ }
+
+ /**
+ * Set the keys for a save update query.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ protected function setKeysForSaveQuery(Builder $query)
+ {
+ $query->where($this->foreignKey, $this->getAttribute($this->foreignKey));
+
+ return $query->where($this->otherKey, $this->getAttribute($this->otherKey));
+ }
+
+ /**
+ * Delete the pivot model record from the database.
+ *
+ * @return int
+ */
+ public function delete()
+ {
+ return $this->getDeleteQuery()->delete();
+ }
+
+ /**
+ * Get the query builder for a delete operation on the pivot.
+ *
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ protected function getDeleteQuery()
+ {
+ $foreign = $this->getAttribute($this->foreignKey);
+
+ $query = $this->newQuery()->where($this->foreignKey, $foreign);
+
+ return $query->where($this->otherKey, $this->getAttribute($this->otherKey));
+ }
+
+ /**
+ * Get the foreign key column name.
+ *
+ * @return string
+ */
+ public function getForeignKey()
+ {
+ return $this->foreignKey;
+ }
+
+ /**
+ * Get the "other key" column name.
+ *
+ * @return string
+ */
+ public function getOtherKey()
+ {
+ return $this->otherKey;
+ }
+
+ /**
+ * Set the key names for the pivot model instance.
+ *
+ * @param string $foreignKey
+ * @param string $otherKey
+ * @return $this
+ */
+ public function setPivotKeys($foreignKey, $otherKey)
+ {
+ $this->foreignKey = $foreignKey;
+
+ $this->otherKey = $otherKey;
+
+ return $this;
+ }
+
+ /**
+ * Determine if the pivot model has timestamp attributes.
+ *
+ * @return bool
+ */
+ public function hasTimestampAttributes()
+ {
+ return array_key_exists($this->getCreatedAtColumn(), $this->attributes);
+ }
+
+ /**
+ * Get the name of the "created at" column.
+ *
+ * @return string
+ */
+ public function getCreatedAtColumn()
+ {
+ return $this->parent->getCreatedAtColumn();
+ }
+
+ /**
+ * Get the name of the "updated at" column.
+ *
+ * @return string
+ */
+ public function getUpdatedAtColumn()
+ {
+ return $this->parent->getUpdatedAtColumn();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Relation.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Relation.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Relation.php
new file mode 100755
index 0000000..24125bb
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Relation.php
@@ -0,0 +1,288 @@
+<?php namespace Illuminate\Database\Eloquent\Relations;
+
+use Closure;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Query\Expression;
+use Illuminate\Database\Eloquent\Collection;
+
+abstract class Relation {
+
+ /**
+ * The Eloquent query builder instance.
+ *
+ * @var \Illuminate\Database\Eloquent\Builder
+ */
+ protected $query;
+
+ /**
+ * The parent model instance.
+ *
+ * @var \Illuminate\Database\Eloquent\Model
+ */
+ protected $parent;
+
+ /**
+ * The related model instance.
+ *
+ * @var \Illuminate\Database\Eloquent\Model
+ */
+ protected $related;
+
+ /**
+ * Indicates if the relation is adding constraints.
+ *
+ * @var bool
+ */
+ protected static $constraints = true;
+
+ /**
+ * Create a new relation instance.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Model $parent
+ * @return void
+ */
+ public function __construct(Builder $query, Model $parent)
+ {
+ $this->query = $query;
+ $this->parent = $parent;
+ $this->related = $query->getModel();
+
+ $this->addConstraints();
+ }
+
+ /**
+ * Set the base constraints on the relation query.
+ *
+ * @return void
+ */
+ abstract public function addConstraints();
+
+ /**
+ * Set the constraints for an eager load of the relation.
+ *
+ * @param array $models
+ * @return void
+ */
+ abstract public function addEagerConstraints(array $models);
+
+ /**
+ * Initialize the relation on a set of models.
+ *
+ * @param array $models
+ * @param string $relation
+ * @return array
+ */
+ abstract public function initRelation(array $models, $relation);
+
+ /**
+ * Match the eagerly loaded results to their parents.
+ *
+ * @param array $models
+ * @param \Illuminate\Database\Eloquent\Collection $results
+ * @param string $relation
+ * @return array
+ */
+ abstract public function match(array $models, Collection $results, $relation);
+
+ /**
+ * Get the results of the relationship.
+ *
+ * @return mixed
+ */
+ abstract public function getResults();
+
+ /**
+ * Get the relationship for eager loading.
+ *
+ * @return \Illuminate\Database\Eloquent\Collection
+ */
+ public function getEager()
+ {
+ return $this->get();
+ }
+
+ /**
+ * Touch all of the related models for the relationship.
+ *
+ * @return void
+ */
+ public function touch()
+ {
+ $column = $this->getRelated()->getUpdatedAtColumn();
+
+ $this->rawUpdate(array($column => $this->getRelated()->freshTimestampString()));
+ }
+
+ /**
+ * Run a raw update against the base query.
+ *
+ * @param array $attributes
+ * @return int
+ */
+ public function rawUpdate(array $attributes = array())
+ {
+ return $this->query->update($attributes);
+ }
+
+ /**
+ * Add the constraints for a relationship count query.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $query
+ * @param \Illuminate\Database\Eloquent\Builder $parent
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ public function getRelationCountQuery(Builder $query, Builder $parent)
+ {
+ $query->select(new Expression('count(*)'));
+
+ $key = $this->wrap($this->getQualifiedParentKeyName());
+
+ return $query->where($this->getHasCompareKey(), '=', new Expression($key));
+ }
+
+ /**
+ * Run a callback with constraints disabled on the relation.
+ *
+ * @param \Closure $callback
+ * @return mixed
+ */
+ public static function noConstraints(Closure $callback)
+ {
+ static::$constraints = false;
+
+ // When resetting the relation where clause, we want to shift the first element
+ // off of the bindings, leaving only the constraints that the developers put
+ // as "extra" on the relationships, and not original relation constraints.
+ $results = call_user_func($callback);
+
+ static::$constraints = true;
+
+ return $results;
+ }
+
+ /**
+ * Get all of the primary keys for an array of models.
+ *
+ * @param array $models
+ * @param string $key
+ * @return array
+ */
+ protected function getKeys(array $models, $key = null)
+ {
+ return array_unique(array_values(array_map(function($value) use ($key)
+ {
+ return $key ? $value->getAttribute($key) : $value->getKey();
+
+ }, $models)));
+ }
+
+ /**
+ * Get the underlying query for the relation.
+ *
+ * @return \Illuminate\Database\Eloquent\Builder
+ */
+ public function getQuery()
+ {
+ return $this->query;
+ }
+
+ /**
+ * Get the base query builder driving the Eloquent builder.
+ *
+ * @return \Illuminate\Database\Query\Builder
+ */
+ public function getBaseQuery()
+ {
+ return $this->query->getQuery();
+ }
+
+ /**
+ * Get the parent model of the relation.
+ *
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function getParent()
+ {
+ return $this->parent;
+ }
+
+ /**
+ * Get the fully qualified parent key name.
+ *
+ * @return string
+ */
+ public function getQualifiedParentKeyName()
+ {
+ return $this->parent->getQualifiedKeyName();
+ }
+
+ /**
+ * Get the related model of the relation.
+ *
+ * @return \Illuminate\Database\Eloquent\Model
+ */
+ public function getRelated()
+ {
+ return $this->related;
+ }
+
+ /**
+ * Get the name of the "created at" column.
+ *
+ * @return string
+ */
+ public function createdAt()
+ {
+ return $this->parent->getCreatedAtColumn();
+ }
+
+ /**
+ * Get the name of the "updated at" column.
+ *
+ * @return string
+ */
+ public function updatedAt()
+ {
+ return $this->parent->getUpdatedAtColumn();
+ }
+
+ /**
+ * Get the name of the related model's "updated at" column.
+ *
+ * @return string
+ */
+ public function relatedUpdatedAt()
+ {
+ return $this->related->getUpdatedAtColumn();
+ }
+
+ /**
+ * Wrap the given value with the parent query's grammar.
+ *
+ * @param string $value
+ * @return string
+ */
+ public function wrap($value)
+ {
+ return $this->parent->newQueryWithoutScopes()->getQuery()->getGrammar()->wrap($value);
+ }
+
+ /**
+ * Handle dynamic method calls to the relationship.
+ *
+ * @param string $method
+ * @param array $parameters
+ * @return mixed
+ */
+ public function __call($method, $parameters)
+ {
+ $result = call_user_func_array(array($this->query, $method), $parameters);
+
+ if ($result === $this->query) return $this;
+
+ return $result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/ScopeInterface.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/ScopeInterface.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/ScopeInterface.php
new file mode 100644
index 0000000..b0a93a9
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/ScopeInterface.php
@@ -0,0 +1,21 @@
+<?php namespace Illuminate\Database\Eloquent;
+
+interface ScopeInterface {
+
+ /**
+ * Apply the scope to a given Eloquent query builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return void
+ */
+ public function apply(Builder $builder);
+
+ /**
+ * Remove the scope from the given Eloquent query builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return void
+ */
+ public function remove(Builder $builder);
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletingScope.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletingScope.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletingScope.php
new file mode 100644
index 0000000..61c5d5c
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletingScope.php
@@ -0,0 +1,170 @@
+<?php namespace Illuminate\Database\Eloquent;
+
+class SoftDeletingScope implements ScopeInterface {
+
+ /**
+ * All of the extensions to be added to the builder.
+ *
+ * @var array
+ */
+ protected $extensions = ['ForceDelete', 'Restore', 'WithTrashed', 'OnlyTrashed'];
+
+ /**
+ * Apply the scope to a given Eloquent query builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return void
+ */
+ public function apply(Builder $builder)
+ {
+ $model = $builder->getModel();
+
+ $builder->whereNull($model->getQualifiedDeletedAtColumn());
+
+ $this->extend($builder);
+ }
+
+ /**
+ * Remove the scope from the given Eloquent query builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return void
+ */
+ public function remove(Builder $builder)
+ {
+ $column = $builder->getModel()->getQualifiedDeletedAtColumn();
+
+ $query = $builder->getQuery();
+
+ foreach ((array) $query->wheres as $key => $where)
+ {
+ // If the where clause is a soft delete date constraint, we will remove it from
+ // the query and reset the keys on the wheres. This allows this developer to
+ // include deleted model in a relationship result set that is lazy loaded.
+ if ($this->isSoftDeleteConstraint($where, $column))
+ {
+ unset($query->wheres[$key]);
+
+ $query->wheres = array_values($query->wheres);
+ }
+ }
+ }
+
+ /**
+ * Extend the query builder with the needed functions.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return void
+ */
+ public function extend(Builder $builder)
+ {
+ foreach ($this->extensions as $extension)
+ {
+ $this->{"add{$extension}"}($builder);
+ }
+
+ $builder->onDelete(function(Builder $builder)
+ {
+ $column = $this->getDeletedAtColumn($builder);
+
+ return $builder->update(array(
+ $column => $builder->getModel()->freshTimestampString()
+ ));
+ });
+ }
+
+ /**
+ * Get the "deleted at" column for the builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return string
+ */
+ protected function getDeletedAtColumn(Builder $builder)
+ {
+ if (count($builder->getQuery()->joins) > 0)
+ {
+ return $builder->getModel()->getQualifiedDeletedAtColumn();
+ }
+ else
+ {
+ return $builder->getModel()->getDeletedAtColumn();
+ }
+ }
+
+ /**
+ * Add the force delete extension to the builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return void
+ */
+ protected function addForceDelete(Builder $builder)
+ {
+ $builder->macro('forceDelete', function(Builder $builder)
+ {
+ return $builder->getQuery()->delete();
+ });
+ }
+
+ /**
+ * Add the restore extension to the builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return void
+ */
+ protected function addRestore(Builder $builder)
+ {
+ $builder->macro('restore', function(Builder $builder)
+ {
+ $builder->withTrashed();
+
+ return $builder->update(array($builder->getModel()->getDeletedAtColumn() => null));
+ });
+ }
+
+ /**
+ * Add the with-trashed extension to the builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return void
+ */
+ protected function addWithTrashed(Builder $builder)
+ {
+ $builder->macro('withTrashed', function(Builder $builder)
+ {
+ $this->remove($builder);
+
+ return $builder;
+ });
+ }
+
+ /**
+ * Add the only-trashed extension to the builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @return void
+ */
+ protected function addOnlyTrashed(Builder $builder)
+ {
+ $builder->macro('onlyTrashed', function(Builder $builder)
+ {
+ $this->remove($builder);
+
+ $builder->getQuery()->whereNotNull($builder->getModel()->getQualifiedDeletedAtColumn());
+
+ return $builder;
+ });
+ }
+
+ /**
+ * Determine if the given where clause is a soft delete constraint.
+ *
+ * @param array $where
+ * @param string $column
+ * @return bool
+ */
+ protected function isSoftDeleteConstraint(array $where, $column)
+ {
+ return $where['type'] == 'Null' && $where['column'] == $column;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/01413d65/vendor/laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletingTrait.php
----------------------------------------------------------------------
diff --git a/vendor/laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletingTrait.php b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletingTrait.php
new file mode 100644
index 0000000..617c019
--- /dev/null
+++ b/vendor/laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletingTrait.php
@@ -0,0 +1,170 @@
+<?php namespace Illuminate\Database\Eloquent;
+
+trait SoftDeletingTrait {
+
+ /**
+ * Indicates if the model is currently force deleting.
+ *
+ * @var bool
+ */
+ protected $forceDeleting = false;
+
+ /**
+ * Boot the soft deleting trait for a model.
+ *
+ * @return void
+ */
+ public static function bootSoftDeletingTrait()
+ {
+ static::addGlobalScope(new SoftDeletingScope);
+ }
+
+ /**
+ * Force a hard delete on a soft deleted model.
+ *
+ * @return void
+ */
+ public function forceDelete()
+ {
+ $this->forceDeleting = true;
+
+ $this->delete();
+
+ $this->forceDeleting = false;
+ }
+
+ /**
+ * Perform the actual delete query on this model instance.
+ *
+ * @return void
+ */
+ protected function performDeleteOnModel()
+ {
+ if ($this->forceDeleting)
+ {
+ return $this->withTrashed()->where($this->getKeyName(), $this->getKey())->forceDelete();
+ }
+
+ return $this->runSoftDelete();
+ }
+
+ /**
+ * Perform the actual delete query on this model instance.
+ *
+ * @return void
+ */
+ protected function runSoftDelete()
+ {
+ $query = $this->newQuery()->where($this->getKeyName(), $this->getKey());
+
+ $this->{$this->getDeletedAtColumn()} = $time = $this->freshTimestamp();
+
+ $query->update(array($this->getDeletedAtColumn() => $this->fromDateTime($time)));
+ }
+
+ /**
+ * Restore a soft-deleted model instance.
+ *
+ * @return bool|null
+ */
+ public function restore()
+ {
+ // If the restoring event does not return false, we will proceed with this
+ // restore operation. Otherwise, we bail out so the developer will stop
+ // the restore totally. We will clear the deleted timestamp and save.
+ if ($this->fireModelEvent('restoring') === false)
+ {
+ return false;
+ }
+
+ $this->{$this->getDeletedAtColumn()} = null;
+
+ // Once we have saved the model, we will fire the "restored" event so this
+ // developer will do anything they need to after a restore operation is
+ // totally finished. Then we will return the result of the save call.
+ $this->exists = true;
+
+ $result = $this->save();
+
+ $this->fireModelEvent('restored', false);
+
+ return $result;
+ }
+
+ /**
+ * Determine if the model instance has been soft-deleted.
+ *
+ * @return bool
+ */
+ public function trashed()
+ {
+ return ! is_null($this->{$this->getDeletedAtColumn()});
+ }
+
+ /**
+ * Get a new query builder that includes soft deletes.
+ *
+ * @return \Illuminate\Database\Eloquent\Builder|static
+ */
+ public static function withTrashed()
+ {
+ return (new static)->newQueryWithoutScope(new SoftDeletingScope);
+ }
+
+ /**
+ * Get a new query builder that only includes soft deletes.
+ *
+ * @return \Illuminate\Database\Eloquent\Builder|static
+ */
+ public static function onlyTrashed()
+ {
+ $instance = new static;
+
+ $column = $instance->getQualifiedDeletedAtColumn();
+
+ return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column);
+ }
+
+ /**
+ * Register a restoring model event with the dispatcher.
+ *
+ * @param \Closure|string $callback
+ * @return void
+ */
+ public static function restoring($callback)
+ {
+ static::registerModelEvent('restoring', $callback);
+ }
+
+ /**
+ * Register a restored model event with the dispatcher.
+ *
+ * @param \Closure|string $callback
+ * @return void
+ */
+ public static function restored($callback)
+ {
+ static::registerModelEvent('restored', $callback);
+ }
+
+ /**
+ * Get the name of the "deleted at" column.
+ *
+ * @return string
+ */
+ public function getDeletedAtColumn()
+ {
+ return defined('static::DELETED_AT') ? static::DELETED_AT : 'deleted_at';
+ }
+
+ /**
+ * Get the fully qualified "deleted at" column.
+ *
+ * @return string
+ */
+ public function getQualifiedDeletedAtColumn()
+ {
+ return $this->getTable().'.'.$this->getDeletedAtColumn();
+ }
+
+}