the whole shebang
This commit is contained in:
259
vendor/laravel/framework/src/Illuminate/Database/Capsule/Manager.php
vendored
Normal file
259
vendor/laravel/framework/src/Illuminate/Database/Capsule/Manager.php
vendored
Normal file
@@ -0,0 +1,259 @@
|
||||
<?php namespace Illuminate\Database\Capsule;
|
||||
|
||||
use PDO;
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
use Illuminate\Cache\CacheManager;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Connectors\ConnectionFactory;
|
||||
|
||||
class Manager {
|
||||
|
||||
/**
|
||||
* The current globally used instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Capsule\Manager
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* Create a new database capsule manager.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $container = null)
|
||||
{
|
||||
$this->setupContainer($container);
|
||||
|
||||
// Once we have the container setup, we will setup the default configuration
|
||||
// options in the container "config" binding. This will make the database
|
||||
// manager behave correctly since all the correct binding are in place.
|
||||
$this->setupDefaultConfiguration();
|
||||
|
||||
$this->setupManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the IoC container instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
protected function setupContainer($container)
|
||||
{
|
||||
$this->container = $container ?: new Container;
|
||||
|
||||
$this->container->instance('config', new Fluent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the default database configuration options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setupDefaultConfiguration()
|
||||
{
|
||||
$this->container['config']['database.fetch'] = PDO::FETCH_ASSOC;
|
||||
|
||||
$this->container['config']['database.default'] = 'default';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the database manager instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setupManager()
|
||||
{
|
||||
$factory = new ConnectionFactory($this->container);
|
||||
|
||||
$this->manager = new DatabaseManager($this->container, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a connection instance from the global manager.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public static function connection($connection = null)
|
||||
{
|
||||
return static::$instance->getConnection($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a fluent query builder instance.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $connection
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
public static function table($table, $connection = null)
|
||||
{
|
||||
return static::$instance->connection($connection)->table($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a schema builder instance.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return \Illuminate\Database\Schema\Builder
|
||||
*/
|
||||
public static function schema($connection = null)
|
||||
{
|
||||
return static::$instance->connection($connection)->getSchemaBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a registered connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function getConnection($name = null)
|
||||
{
|
||||
return $this->manager->connection($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a connection with the manager.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function addConnection(array $config, $name = 'default')
|
||||
{
|
||||
$connections = $this->container['config']['database.connections'];
|
||||
|
||||
$connections[$name] = $config;
|
||||
|
||||
$this->container['config']['database.connections'] = $connections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap Eloquent so it is ready for usage.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function bootEloquent()
|
||||
{
|
||||
Eloquent::setConnectionResolver($this->manager);
|
||||
|
||||
// If we have an event dispatcher instance, we will go ahead and register it
|
||||
// with the Eloquent ORM, allowing for model callbacks while creating and
|
||||
// updating "model" instances; however, if it not necessary to operate.
|
||||
if ($dispatcher = $this->getEventDispatcher())
|
||||
{
|
||||
Eloquent::setEventDispatcher($dispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fetch mode for the database connections.
|
||||
*
|
||||
* @param int $fetchMode
|
||||
* @return \Illuminate\Database\Capsule\Manager
|
||||
*/
|
||||
public function setFetchMode($fetchMode)
|
||||
{
|
||||
$this->container['config']['database.fetch'] = $fetchMode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this capsule instance available globally.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAsGlobal()
|
||||
{
|
||||
static::$instance = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current event dispatcher instance.
|
||||
*
|
||||
* @return \Illuminate\Events\Dispatcher
|
||||
*/
|
||||
public function getEventDispatcher()
|
||||
{
|
||||
if ($this->container->bound('events'))
|
||||
{
|
||||
return $this->container['events'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event dispatcher instance to be used by connections.
|
||||
*
|
||||
* @param \Illuminate\Events\Dispatcher $dispatcher
|
||||
* @return void
|
||||
*/
|
||||
public function setEventDispatcher(Dispatcher $dispatcher)
|
||||
{
|
||||
$this->container->instance('events', $dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current cache manager instance.
|
||||
*
|
||||
* @return \Illuminate\Cache\Manager
|
||||
*/
|
||||
public function getCacheManager()
|
||||
{
|
||||
if ($this->container->bound('cache'))
|
||||
{
|
||||
return $this->container['cache'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache manager to bse used by connections.
|
||||
*
|
||||
* @param \Illuminate\Cache\CacheManager $cache
|
||||
* @return void
|
||||
*/
|
||||
public function setCacheManager(CacheManager $cache)
|
||||
{
|
||||
$this->container->instance('cache', $cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the IoC container instance.
|
||||
*
|
||||
* @return \Illuminate\Container\Container
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IoC container instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function setContainer(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically pass methods to the default connection.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
return call_user_func_array(array(static::connection(), $method), $parameters);
|
||||
}
|
||||
|
||||
}
|
946
vendor/laravel/framework/src/Illuminate/Database/Connection.php
vendored
Executable file
946
vendor/laravel/framework/src/Illuminate/Database/Connection.php
vendored
Executable file
@@ -0,0 +1,946 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use PDO;
|
||||
use Closure;
|
||||
use DateTime;
|
||||
use Illuminate\Cache\CacheManager;
|
||||
use Illuminate\Database\Query\Processors\Processor;
|
||||
|
||||
class Connection implements ConnectionInterface {
|
||||
|
||||
/**
|
||||
* The active PDO connection.
|
||||
*
|
||||
* @var PDO
|
||||
*/
|
||||
protected $pdo;
|
||||
|
||||
/**
|
||||
* The query grammar implementation.
|
||||
*
|
||||
* @var \Illuminate\Database\Query\Grammars\Grammar
|
||||
*/
|
||||
protected $queryGrammar;
|
||||
|
||||
/**
|
||||
* The schema grammar implementation.
|
||||
*
|
||||
* @var \Illuminate\Database\Schema\Grammars\Grammar
|
||||
*/
|
||||
protected $schemaGrammar;
|
||||
|
||||
/**
|
||||
* The query post processor implementation.
|
||||
*
|
||||
* @var \Illuminate\Database\Query\Processors\Processor
|
||||
*/
|
||||
protected $postProcessor;
|
||||
|
||||
/**
|
||||
* The event dispatcher instance.
|
||||
*
|
||||
* @var \Illuminate\Events\Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* The paginator environment instance.
|
||||
*
|
||||
* @var \Illuminate\Pagination\Paginator
|
||||
*/
|
||||
protected $paginator;
|
||||
|
||||
/**
|
||||
* The cache manager instance.
|
||||
*
|
||||
* @var \Illuminate\Cache\CacheManger
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* The default fetch mode of the connection.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $fetchMode = PDO::FETCH_ASSOC;
|
||||
|
||||
/**
|
||||
* The number of active transasctions.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $transactions = 0;
|
||||
|
||||
/**
|
||||
* All of the queries run against the connection.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $queryLog = array();
|
||||
|
||||
/**
|
||||
* Indicates whether queries are being logged.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $loggingQueries = true;
|
||||
|
||||
/**
|
||||
* Indicates if the connection is in a "dry run".
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $pretending = false;
|
||||
|
||||
/**
|
||||
* The name of the connected database.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* The table prefix for the connection.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tablePrefix = '';
|
||||
|
||||
/**
|
||||
* The database connection configuration options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
|
||||
/**
|
||||
* Create a new database connection instance.
|
||||
*
|
||||
* @param PDO $pdo
|
||||
* @param string $database
|
||||
* @param string $tablePrefix
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(PDO $pdo, $database = '', $tablePrefix = '', array $config = array())
|
||||
{
|
||||
$this->pdo = $pdo;
|
||||
|
||||
// First we will setup the default properties. We keep track of the DB
|
||||
// name we are connected to since it is needed when some reflective
|
||||
// type commands are run such as checking whether a table exists.
|
||||
$this->database = $database;
|
||||
|
||||
$this->tablePrefix = $tablePrefix;
|
||||
|
||||
$this->config = $config;
|
||||
|
||||
// We need to initialize a query grammar and the query post processors
|
||||
// which are both very important parts of the database abstractions
|
||||
// so we initialize these to their default values while starting.
|
||||
$this->useDefaultQueryGrammar();
|
||||
|
||||
$this->useDefaultPostProcessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query grammar to the default implementation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function useDefaultQueryGrammar()
|
||||
{
|
||||
$this->queryGrammar = $this->getDefaultQueryGrammar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default query grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return new Query\Grammars\Grammar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the schema grammar to the default implementation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function useDefaultSchemaGrammar()
|
||||
{
|
||||
$this->schemaGrammar = $this->getDefaultSchemaGrammar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default schema grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar() {}
|
||||
|
||||
/**
|
||||
* Set the query post processor to the default implementation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function useDefaultPostProcessor()
|
||||
{
|
||||
$this->postProcessor = $this->getDefaultPostProcessor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default post processor instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Processors\Processor
|
||||
*/
|
||||
protected function getDefaultPostProcessor()
|
||||
{
|
||||
return new Query\Processors\Processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a schema builder instance for the connection.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Builder
|
||||
*/
|
||||
public function getSchemaBuilder()
|
||||
{
|
||||
if (is_null($this->schemaGrammar)) { $this->useDefaultSchemaGrammar(); }
|
||||
|
||||
return new Schema\Builder($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a fluent query against a database table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
public function table($table)
|
||||
{
|
||||
$processor = $this->getPostProcessor();
|
||||
|
||||
$query = new Query\Builder($this, $this->getQueryGrammar(), $processor);
|
||||
|
||||
return $query->from($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new raw query expression.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return \Illuminate\Database\Query\Expression
|
||||
*/
|
||||
public function raw($value)
|
||||
{
|
||||
return new Query\Expression($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a select statement and return a single result.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return mixed
|
||||
*/
|
||||
public function selectOne($query, $bindings = array())
|
||||
{
|
||||
$records = $this->select($query, $bindings);
|
||||
|
||||
return count($records) > 0 ? reset($records) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a select statement against the database.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return array
|
||||
*/
|
||||
public function select($query, $bindings = array())
|
||||
{
|
||||
return $this->run($query, $bindings, function($me, $query, $bindings)
|
||||
{
|
||||
if ($me->pretending()) return array();
|
||||
|
||||
// For select statements, we'll simply execute the query and return an array
|
||||
// of the database result set. Each element in the array will be a single
|
||||
// row from the database table, and will either be an array or objects.
|
||||
$statement = $me->getPdo()->prepare($query);
|
||||
|
||||
$statement->execute($me->prepareBindings($bindings));
|
||||
|
||||
return $statement->fetchAll($me->getFetchMode());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an insert statement against the database.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return bool
|
||||
*/
|
||||
public function insert($query, $bindings = array())
|
||||
{
|
||||
return $this->statement($query, $bindings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an update statement against the database.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return int
|
||||
*/
|
||||
public function update($query, $bindings = array())
|
||||
{
|
||||
return $this->affectingStatement($query, $bindings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a delete statement against the database.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return int
|
||||
*/
|
||||
public function delete($query, $bindings = array())
|
||||
{
|
||||
return $this->affectingStatement($query, $bindings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an SQL statement and return the boolean result.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return bool
|
||||
*/
|
||||
public function statement($query, $bindings = array())
|
||||
{
|
||||
return $this->run($query, $bindings, function($me, $query, $bindings)
|
||||
{
|
||||
if ($me->pretending()) return true;
|
||||
|
||||
$bindings = $me->prepareBindings($bindings);
|
||||
|
||||
return $me->getPdo()->prepare($query)->execute($bindings);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an SQL statement and get the number of rows affected.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return int
|
||||
*/
|
||||
public function affectingStatement($query, $bindings = array())
|
||||
{
|
||||
return $this->run($query, $bindings, function($me, $query, $bindings)
|
||||
{
|
||||
if ($me->pretending()) return 0;
|
||||
|
||||
// For update or delete statements, we want to get the number of rows affected
|
||||
// by the statement and return that back to the developer. We'll first need
|
||||
// to execute the statement and then we'll use PDO to fetch the affected.
|
||||
$statement = $me->getPdo()->prepare($query);
|
||||
|
||||
$statement->execute($me->prepareBindings($bindings));
|
||||
|
||||
return $statement->rowCount();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a raw, unprepared query against the PDO connection.
|
||||
*
|
||||
* @param string $query
|
||||
* @return bool
|
||||
*/
|
||||
public function unprepared($query)
|
||||
{
|
||||
return $this->run($query, array(), function($me, $query, $bindings)
|
||||
{
|
||||
if ($me->pretending()) return true;
|
||||
|
||||
return (bool) $me->getPdo()->exec($query);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the query bindings for execution.
|
||||
*
|
||||
* @param array $bindings
|
||||
* @return array
|
||||
*/
|
||||
public function prepareBindings(array $bindings)
|
||||
{
|
||||
$grammar = $this->getQueryGrammar();
|
||||
|
||||
foreach ($bindings as $key => $value)
|
||||
{
|
||||
// We need to transform all instances of the DateTime class into an actual
|
||||
// date string. Each query grammar maintains its own date string format
|
||||
// so we'll just ask the grammar for the format to get from the date.
|
||||
if ($value instanceof DateTime)
|
||||
{
|
||||
$bindings[$key] = $value->format($grammar->getDateFormat());
|
||||
}
|
||||
elseif ($value === false)
|
||||
{
|
||||
$bindings[$key] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $bindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a Closure within a transaction.
|
||||
*
|
||||
* @param Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function transaction(Closure $callback)
|
||||
{
|
||||
$this->beginTransaction();
|
||||
|
||||
// We'll simply execute the given callback within a try / catch block
|
||||
// and if we catch any exception we can rollback the transaction
|
||||
// so that none of the changes are persisted to the database.
|
||||
try
|
||||
{
|
||||
$result = $callback($this);
|
||||
|
||||
$this->commit();
|
||||
}
|
||||
|
||||
// If we catch an exception, we will roll back so nothing gets messed
|
||||
// up in the database. Then we'll re-throw the exception so it can
|
||||
// be handled how the developer sees fit for their applications.
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->rollBack();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a new database transaction.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function beginTransaction()
|
||||
{
|
||||
++$this->transactions;
|
||||
|
||||
if ($this->transactions == 1)
|
||||
{
|
||||
$this->pdo->beginTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the active database transaction.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
if ($this->transactions == 1) $this->pdo->commit();
|
||||
|
||||
--$this->transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback the active database transaction.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rollBack()
|
||||
{
|
||||
if ($this->transactions == 1)
|
||||
{
|
||||
$this->transactions = 0;
|
||||
|
||||
$this->pdo->rollBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
--$this->transactions;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the given callback in "dry run" mode.
|
||||
*
|
||||
* @param Closure $callback
|
||||
* @return array
|
||||
*/
|
||||
public function pretend(Closure $callback)
|
||||
{
|
||||
$this->pretending = true;
|
||||
|
||||
$this->queryLog = array();
|
||||
|
||||
// Basically to make the database connection "pretend", we will just return
|
||||
// the default values for all the query methods, then we will return an
|
||||
// array of queries that were "executed" within the Closure callback.
|
||||
$callback($this);
|
||||
|
||||
$this->pretending = false;
|
||||
|
||||
return $this->queryLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a SQL statement and log its execution context.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @param Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
protected function run($query, $bindings, Closure $callback)
|
||||
{
|
||||
$start = microtime(true);
|
||||
|
||||
// To execute the statement, we'll simply call the callback, which will actually
|
||||
// run the SQL against the PDO connection. Then we can calculate the time it
|
||||
// took to execute and log the query SQL, bindings and time in our memory.
|
||||
try
|
||||
{
|
||||
$result = $callback($this, $query, $bindings);
|
||||
}
|
||||
|
||||
// If an exception occurs when attempting to run a query, we'll format the error
|
||||
// message to include the bindings with SQL, which will make this exception a
|
||||
// lot more helpful to the developer instead of just the database's errors.
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->handleQueryException($e, $query, $bindings);
|
||||
}
|
||||
|
||||
// Once we have run the query we will calculate the time that it took to run and
|
||||
// then log the query, bindings, and execution time so we will report them on
|
||||
// the event that the developer needs them. We'll log time in milliseconds.
|
||||
$time = $this->getElapsedTime($start);
|
||||
|
||||
$this->logQuery($query, $bindings, $time);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an exception that occurred during a query.
|
||||
*
|
||||
* @param Exception $e
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return void
|
||||
*/
|
||||
protected function handleQueryException(\Exception $e, $query, $bindings)
|
||||
{
|
||||
$bindings = var_export($bindings, true);
|
||||
|
||||
$message = $e->getMessage()." (SQL: {$query}) (Bindings: {$bindings})";
|
||||
|
||||
throw new \Exception($message, 0, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a query in the connection's query log.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @param $time
|
||||
* @return void
|
||||
*/
|
||||
public function logQuery($query, $bindings, $time = null)
|
||||
{
|
||||
if (isset($this->events))
|
||||
{
|
||||
$this->events->fire('illuminate.query', array($query, $bindings, $time, $this->getName()));
|
||||
}
|
||||
|
||||
if ( ! $this->loggingQueries) return;
|
||||
|
||||
$this->queryLog[] = compact('query', 'bindings', 'time');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a database query listener with the connection.
|
||||
*
|
||||
* @param Closure $callback
|
||||
* @return void
|
||||
*/
|
||||
public function listen(Closure $callback)
|
||||
{
|
||||
if (isset($this->events))
|
||||
{
|
||||
$this->events->listen('illuminate.query', $callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the elapsed time since a given starting point.
|
||||
*
|
||||
* @param int $start
|
||||
* @return float
|
||||
*/
|
||||
protected function getElapsedTime($start)
|
||||
{
|
||||
return round((microtime(true) - $start) * 1000, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Doctrine Schema Column instance.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function getDoctrineColumn($table, $column)
|
||||
{
|
||||
$schema = $this->getDoctrineSchemaManager();
|
||||
|
||||
return $schema->listTableDetails($table)->getColumn($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL schema manager for the connection.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Schema\AbstractSchemaManager
|
||||
*/
|
||||
public function getDoctrineSchemaManager()
|
||||
{
|
||||
return $this->getDoctrineDriver()->getSchemaManager($this->getDoctrineConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL database connection instance.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Connection
|
||||
*/
|
||||
public function getDoctrineConnection()
|
||||
{
|
||||
$driver = $this->getDoctrineDriver();
|
||||
|
||||
$data = array('pdo' => $this->pdo, 'dbname' => $this->getConfig('database'));
|
||||
|
||||
return new \Doctrine\DBAL\Connection($data, $driver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently used PDO connection.
|
||||
*
|
||||
* @return PDO
|
||||
*/
|
||||
public function getPdo()
|
||||
{
|
||||
return $this->pdo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database connection name.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getConfig('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an option from the configuration options.
|
||||
*
|
||||
* @param string $option
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig($option)
|
||||
{
|
||||
return array_get($this->config, $option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PDO driver name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDriverName()
|
||||
{
|
||||
return $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query grammar used by the connection.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\Grammar
|
||||
*/
|
||||
public function getQueryGrammar()
|
||||
{
|
||||
return $this->queryGrammar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query grammar used by the connection.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Grammars\Grammar
|
||||
* @return void
|
||||
*/
|
||||
public function setQueryGrammar(Query\Grammars\Grammar $grammar)
|
||||
{
|
||||
$this->queryGrammar = $grammar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the schema grammar used by the connection.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\Grammar
|
||||
*/
|
||||
public function getSchemaGrammar()
|
||||
{
|
||||
return $this->schemaGrammar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the schema grammar used by the connection.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Grammars\Grammar
|
||||
* @return void
|
||||
*/
|
||||
public function setSchemaGrammar(Schema\Grammars\Grammar $grammar)
|
||||
{
|
||||
$this->schemaGrammar = $grammar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query post processor used by the connection.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Processors\Processor
|
||||
*/
|
||||
public function getPostProcessor()
|
||||
{
|
||||
return $this->postProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query post processor used by the connection.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Processors\Processor
|
||||
* @return void
|
||||
*/
|
||||
public function setPostProcessor(Processor $processor)
|
||||
{
|
||||
$this->postProcessor = $processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event dispatcher used by the connection.
|
||||
*
|
||||
* @return \Illuminate\Events\Dispatcher
|
||||
*/
|
||||
public function getEventDispatcher()
|
||||
{
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event dispatcher instance on the connection.
|
||||
*
|
||||
* @param \Illuminate\Events\Dispatcher
|
||||
* @return void
|
||||
*/
|
||||
public function setEventDispatcher(\Illuminate\Events\Dispatcher $events)
|
||||
{
|
||||
$this->events = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the paginator environment instance.
|
||||
*
|
||||
* @return \Illuminate\Pagination\Environment
|
||||
*/
|
||||
public function getPaginator()
|
||||
{
|
||||
if ($this->paginator instanceof Closure)
|
||||
{
|
||||
$this->paginator = call_user_func($this->paginator);
|
||||
}
|
||||
|
||||
return $this->paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the pagination environment instance.
|
||||
*
|
||||
* @param \Illuminate\Pagination\Environment|\Closure $paginator
|
||||
* @return void
|
||||
*/
|
||||
public function setPaginator($paginator)
|
||||
{
|
||||
$this->paginator = $paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache manager instance.
|
||||
*
|
||||
* @return \Illuminate\Cache\CacheManager
|
||||
*/
|
||||
public function getCacheManager()
|
||||
{
|
||||
if ($this->cache instanceof Closure)
|
||||
{
|
||||
$this->cache = call_user_func($this->cache);
|
||||
}
|
||||
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache manager instance on the connection.
|
||||
*
|
||||
* @param \Illuminate\Cache\CacheManager|\Closure $cache
|
||||
* @return void
|
||||
*/
|
||||
public function setCacheManager($cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the connection in a "dry run".
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pretending()
|
||||
{
|
||||
return $this->pretending === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default fetch mode for the connection.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getFetchMode()
|
||||
{
|
||||
return $this->fetchMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default fetch mode for the connection.
|
||||
*
|
||||
* @param int $fetchMode
|
||||
* @return int
|
||||
*/
|
||||
public function setFetchMode($fetchMode)
|
||||
{
|
||||
$this->fetchMode = $fetchMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connection query log.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryLog()
|
||||
{
|
||||
return $this->queryLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the query log.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flushQueryLog()
|
||||
{
|
||||
$this->queryLog = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the query log on the connection.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enableQueryLog()
|
||||
{
|
||||
$this->loggingQueries = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the query log on the connection.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disableQueryLog()
|
||||
{
|
||||
$this->loggingQueries = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the connected database.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDatabaseName()
|
||||
{
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the connected database.
|
||||
*
|
||||
* @param string $database
|
||||
* @return string
|
||||
*/
|
||||
public function setDatabaseName($database)
|
||||
{
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the table prefix for the connection.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTablePrefix()
|
||||
{
|
||||
return $this->tablePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the table prefix in use by the connection.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function setTablePrefix($prefix)
|
||||
{
|
||||
$this->tablePrefix = $prefix;
|
||||
|
||||
$this->getQueryGrammar()->setTablePrefix($prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the table prefix and return the grammar.
|
||||
*
|
||||
* @param \Illuminate\Database\Grammar $grammar
|
||||
* @return \Illuminate\Database\Grammar
|
||||
*/
|
||||
public function withTablePrefix(Grammar $grammar)
|
||||
{
|
||||
$grammar->setTablePrefix($this->tablePrefix);
|
||||
|
||||
return $grammar;
|
||||
}
|
||||
|
||||
}
|
67
vendor/laravel/framework/src/Illuminate/Database/ConnectionInterface.php
vendored
Executable file
67
vendor/laravel/framework/src/Illuminate/Database/ConnectionInterface.php
vendored
Executable file
@@ -0,0 +1,67 @@
|
||||
<?php namespace Illuminate\Database; use Closure;
|
||||
|
||||
interface ConnectionInterface {
|
||||
|
||||
/**
|
||||
* Run a select statement and return a single result.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return mixed
|
||||
*/
|
||||
public function selectOne($query, $bindings = array());
|
||||
|
||||
/**
|
||||
* Run a select statement against the database.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return array
|
||||
*/
|
||||
public function select($query, $bindings = array());
|
||||
|
||||
/**
|
||||
* Run an insert statement against the database.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return bool
|
||||
*/
|
||||
public function insert($query, $bindings = array());
|
||||
|
||||
/**
|
||||
* Run an update statement against the database.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return int
|
||||
*/
|
||||
public function update($query, $bindings = array());
|
||||
|
||||
/**
|
||||
* Run a delete statement against the database.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return int
|
||||
*/
|
||||
public function delete($query, $bindings = array());
|
||||
|
||||
/**
|
||||
* Execute an SQL statement and return the boolean result.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return bool
|
||||
*/
|
||||
public function statement($query, $bindings = array());
|
||||
|
||||
/**
|
||||
* Execute a Closure within a transaction.
|
||||
*
|
||||
* @param Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function transaction(Closure $callback);
|
||||
|
||||
}
|
90
vendor/laravel/framework/src/Illuminate/Database/ConnectionResolver.php
vendored
Executable file
90
vendor/laravel/framework/src/Illuminate/Database/ConnectionResolver.php
vendored
Executable file
@@ -0,0 +1,90 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
class ConnectionResolver implements ConnectionResolverInterface {
|
||||
|
||||
/**
|
||||
* All of the registered connections.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $connections = array();
|
||||
|
||||
/**
|
||||
* The default connection name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $default;
|
||||
|
||||
/**
|
||||
* Create a new connection resolver instance.
|
||||
*
|
||||
* @param array $connections
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $connections = array())
|
||||
{
|
||||
foreach ($connections as $name => $connection)
|
||||
{
|
||||
$this->addConnection($name, $connection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a database connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function connection($name = null)
|
||||
{
|
||||
if (is_null($name)) $name = $this->getDefaultConnection();
|
||||
|
||||
return $this->connections[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a connection to the resolver.
|
||||
*
|
||||
* @param string $name
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return void
|
||||
*/
|
||||
public function addConnection($name, Connection $connection)
|
||||
{
|
||||
$this->connections[$name] = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a connection has been registered.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasConnection($name)
|
||||
{
|
||||
return isset($this->connections[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default connection name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultConnection()
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default connection name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultConnection($name)
|
||||
{
|
||||
$this->default = $name;
|
||||
}
|
||||
|
||||
}
|
28
vendor/laravel/framework/src/Illuminate/Database/ConnectionResolverInterface.php
vendored
Executable file
28
vendor/laravel/framework/src/Illuminate/Database/ConnectionResolverInterface.php
vendored
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
interface ConnectionResolverInterface {
|
||||
|
||||
/**
|
||||
* Get a database connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function connection($name = null);
|
||||
|
||||
/**
|
||||
* Get the default connection name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultConnection();
|
||||
|
||||
/**
|
||||
* Set the default connection name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultConnection($name);
|
||||
|
||||
}
|
124
vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php
vendored
Executable file
124
vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php
vendored
Executable file
@@ -0,0 +1,124 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
use PDO;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\MySqlConnection;
|
||||
use Illuminate\Database\SQLiteConnection;
|
||||
use Illuminate\Database\PostgresConnection;
|
||||
use Illuminate\Database\SqlServerConnection;
|
||||
|
||||
class ConnectionFactory {
|
||||
|
||||
/**
|
||||
* The IoC container instance.
|
||||
*
|
||||
* @var \Illuminate\Container\Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Create a new connection factory instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a PDO connection based on the configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $name
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function make(array $config, $name = null)
|
||||
{
|
||||
$config = $this->parseConfig($config, $name);
|
||||
|
||||
$pdo = $this->createConnector($config)->connect($config);
|
||||
|
||||
return $this->createConnection($config['driver'], $pdo, $config['database'], $config['prefix'], $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and prepare the database configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function parseConfig(array $config, $name)
|
||||
{
|
||||
return array_add(array_add($config, 'prefix', ''), 'name', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a connector instance based on the configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Database\Connectors\ConnectorInterface
|
||||
*/
|
||||
public function createConnector(array $config)
|
||||
{
|
||||
if ( ! isset($config['driver']))
|
||||
{
|
||||
throw new \InvalidArgumentException("A driver must be specified.");
|
||||
}
|
||||
|
||||
switch ($config['driver'])
|
||||
{
|
||||
case 'mysql':
|
||||
return new MySqlConnector;
|
||||
|
||||
case 'pgsql':
|
||||
return new PostgresConnector;
|
||||
|
||||
case 'sqlite':
|
||||
return new SQLiteConnector;
|
||||
|
||||
case 'sqlsrv':
|
||||
return new SqlServerConnector;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("Unsupported driver [{$config['driver']}]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new connection instance.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param PDO $connection
|
||||
* @param string $database
|
||||
* @param string $prefix
|
||||
* @param array $config
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
protected function createConnection($driver, PDO $connection, $database, $prefix = '', $config = null)
|
||||
{
|
||||
if ($this->container->bound($key = "db.connection.{$driver}"))
|
||||
{
|
||||
return $this->container->make($key, array($connection, $database, $prefix, $config));
|
||||
}
|
||||
|
||||
switch ($driver)
|
||||
{
|
||||
case 'mysql':
|
||||
return new MySqlConnection($connection, $database, $prefix, $config);
|
||||
|
||||
case 'pgsql':
|
||||
return new PostgresConnection($connection, $database, $prefix, $config);
|
||||
|
||||
case 'sqlite':
|
||||
return new SQLiteConnection($connection, $database, $prefix, $config);
|
||||
|
||||
case 'sqlsrv':
|
||||
return new SqlServerConnection($connection, $database, $prefix, $config);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("Unsupported driver [$driver]");
|
||||
}
|
||||
|
||||
}
|
71
vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
vendored
Executable file
71
vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
vendored
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
use PDO;
|
||||
|
||||
class Connector {
|
||||
|
||||
/**
|
||||
* The default PDO connection options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
PDO::ATTR_CASE => PDO::CASE_NATURAL,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
|
||||
PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the PDO options based on the configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(array $config)
|
||||
{
|
||||
$options = array_get($config, 'options', array());
|
||||
|
||||
return array_diff_key($this->options, $options) + $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PDO connection.
|
||||
*
|
||||
* @param string $dsn
|
||||
* @param array $config
|
||||
* @param array $options
|
||||
* @return PDO
|
||||
*/
|
||||
public function createConnection($dsn, array $config, array $options)
|
||||
{
|
||||
$username = array_get($config, 'username');
|
||||
|
||||
$password = array_get($config, 'password');
|
||||
|
||||
return new PDO($dsn, $username, $password, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default PDO connection options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default PDO connection options.
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultOptions(array $options)
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
}
|
13
vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectorInterface.php
vendored
Executable file
13
vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectorInterface.php
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
interface ConnectorInterface {
|
||||
|
||||
/**
|
||||
* Establish a database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return PDO
|
||||
*/
|
||||
public function connect(array $config);
|
||||
|
||||
}
|
67
vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php
vendored
Executable file
67
vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php
vendored
Executable file
@@ -0,0 +1,67 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
class MySqlConnector extends Connector implements ConnectorInterface {
|
||||
|
||||
/**
|
||||
* Establish a database connection.
|
||||
*
|
||||
* @param array $options
|
||||
* @return PDO
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
$dsn = $this->getDsn($config);
|
||||
|
||||
// We need to grab the PDO options that should be used while making the brand
|
||||
// new connection instance. The PDO options control various aspects of the
|
||||
// connection's behavior, and some might be specified by the developers.
|
||||
$options = $this->getOptions($config);
|
||||
|
||||
$connection = $this->createConnection($dsn, $config, $options);
|
||||
|
||||
$collation = $config['collation'];
|
||||
|
||||
$charset = $config['charset'];
|
||||
|
||||
// Next we will set the "names" and "collation" on the clients connections so
|
||||
// a correct character set will be used by this client. The collation also
|
||||
// is set on the server but needs to be set here on this client objects.
|
||||
$names = "set names '$charset' collate '$collation'";
|
||||
|
||||
$connection->prepare($names)->execute();
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a DSN string from a configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getDsn(array $config)
|
||||
{
|
||||
// First we will create the basic DSN setup as well as the port if it is in
|
||||
// in the configuration options. This will give us the basic DSN we will
|
||||
// need to establish the PDO connections and return them back for use.
|
||||
extract($config);
|
||||
|
||||
$dsn = "mysql:host={$host};dbname={$database}";
|
||||
|
||||
if (isset($config['port']))
|
||||
{
|
||||
$dsn .= ";port={$port}";
|
||||
}
|
||||
|
||||
// Sometimes the developer may specify the specific UNIX socket that should
|
||||
// be used. If that is the case we will add that option to the string we
|
||||
// have created so that it gets utilized while the connection is made.
|
||||
if (isset($config['unix_socket']))
|
||||
{
|
||||
$dsn .= ";unix_socket={$config['unix_socket']}";
|
||||
}
|
||||
|
||||
return $dsn;
|
||||
}
|
||||
|
||||
}
|
82
vendor/laravel/framework/src/Illuminate/Database/Connectors/PostgresConnector.php
vendored
Executable file
82
vendor/laravel/framework/src/Illuminate/Database/Connectors/PostgresConnector.php
vendored
Executable file
@@ -0,0 +1,82 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
use PDO;
|
||||
|
||||
class PostgresConnector extends Connector implements ConnectorInterface {
|
||||
|
||||
/**
|
||||
* The default PDO connection options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
PDO::ATTR_CASE => PDO::CASE_NATURAL,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
|
||||
PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Establish a database connection.
|
||||
*
|
||||
* @param array $options
|
||||
* @return PDO
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
// First we'll create the basic DSN and connection instance connecting to the
|
||||
// using the configuration option specified by the developer. We will also
|
||||
// set the default character set on the connections to UTF-8 by default.
|
||||
$dsn = $this->getDsn($config);
|
||||
|
||||
$options = $this->getOptions($config);
|
||||
|
||||
$connection = $this->createConnection($dsn, $config, $options);
|
||||
|
||||
$charset = $config['charset'];
|
||||
|
||||
$connection->prepare("set names '$charset'")->execute();
|
||||
|
||||
// Unlike MySQL, Postgres allows the concept of "schema" and a default schema
|
||||
// may have been specified on the connections. If that is the case we will
|
||||
// set the default schema search paths to the specified database schema.
|
||||
if (isset($config['schema']))
|
||||
{
|
||||
$schema = $config['schema'];
|
||||
|
||||
$connection->prepare("set search_path to {$schema}")->execute();
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a DSN string from a configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getDsn(array $config)
|
||||
{
|
||||
// First we will create the basic DSN setup as well as the port if it is in
|
||||
// in the configuration options. This will give us the basic DSN we will
|
||||
// need to establish the PDO connections and return them back for use.
|
||||
extract($config);
|
||||
|
||||
$host = isset($host) ? "host={$host};" : '';
|
||||
|
||||
$dsn = "pgsql:{$host}dbname={$database}";
|
||||
|
||||
// If a port was specified, we will add it to this Postgres DSN connections
|
||||
// format. Once we have done that we are ready to return this connection
|
||||
// string back out for usage, as this has been fully constructed here.
|
||||
if (isset($config['port']))
|
||||
{
|
||||
$dsn .= ";port={$port}";
|
||||
}
|
||||
|
||||
return $dsn;
|
||||
}
|
||||
|
||||
}
|
36
vendor/laravel/framework/src/Illuminate/Database/Connectors/SQLiteConnector.php
vendored
Executable file
36
vendor/laravel/framework/src/Illuminate/Database/Connectors/SQLiteConnector.php
vendored
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
class SQLiteConnector extends Connector implements ConnectorInterface {
|
||||
|
||||
/**
|
||||
* Establish a database connection.
|
||||
*
|
||||
* @param array $options
|
||||
* @return PDO
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
$options = $this->getOptions($config);
|
||||
|
||||
// SQLite supports "in-memory" databases that only last as long as the owning
|
||||
// connection does. These are useful for tests or for short lifetime store
|
||||
// querying. In-memory databases may only have a single open connection.
|
||||
if ($config['database'] == ':memory:')
|
||||
{
|
||||
return $this->createConnection('sqlite::memory:', $config, $options);
|
||||
}
|
||||
|
||||
$path = realpath($config['database']);
|
||||
|
||||
// Here we'll verify that the SQLite database exists before we gooing further
|
||||
// as the developer probably wants to know if the database exists and this
|
||||
// SQLite driver will not throw any exception if it does not by default.
|
||||
if ($path === false)
|
||||
{
|
||||
throw new \InvalidArgumentException("Database does not exist.");
|
||||
}
|
||||
|
||||
return $this->createConnection("sqlite:{$path}", $config, $options);
|
||||
}
|
||||
|
||||
}
|
67
vendor/laravel/framework/src/Illuminate/Database/Connectors/SqlServerConnector.php
vendored
Executable file
67
vendor/laravel/framework/src/Illuminate/Database/Connectors/SqlServerConnector.php
vendored
Executable file
@@ -0,0 +1,67 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
use PDO;
|
||||
|
||||
class SqlServerConnector extends Connector implements ConnectorInterface {
|
||||
|
||||
/**
|
||||
* The PDO connection options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
PDO::ATTR_CASE => PDO::CASE_NATURAL,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
|
||||
PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Establish a database connection.
|
||||
*
|
||||
* @param array $options
|
||||
* @return PDO
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
$options = $this->getOptions($config);
|
||||
|
||||
return $this->createConnection($this->getDsn($config), $config, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a DSN string from a configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getDsn(array $config)
|
||||
{
|
||||
extract($config);
|
||||
|
||||
// First we will create the basic DSN setup as well as the port if it is in
|
||||
// in the configuration options. This will give us the basic DSN we will
|
||||
// need to establish the PDO connections and return them back for use.
|
||||
$port = isset($config['port']) ? ','.$port : '';
|
||||
|
||||
if (in_array('dblib', $this->getAvailableDrivers()))
|
||||
{
|
||||
return "dblib:host={$host}{$port};dbname={$database}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "sqlsrv:Server={$host}{$port};Database={$database}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the available PDO drivers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAvailableDrivers()
|
||||
{
|
||||
return PDO::getAvailableDrivers();
|
||||
}
|
||||
|
||||
}
|
49
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/BaseCommand.php
vendored
Executable file
49
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/BaseCommand.php
vendored
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class BaseCommand extends Command {
|
||||
|
||||
/**
|
||||
* Get the path to the migration directory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getMigrationPath()
|
||||
{
|
||||
$path = $this->input->getOption('path');
|
||||
|
||||
// First, we will check to see if a path option has been defined. If it has
|
||||
// we will use the path relative to the root of this installation folder
|
||||
// so that migrations may be run for any path within the applications.
|
||||
if ( ! is_null($path))
|
||||
{
|
||||
return $this->laravel['path.base'].'/'.$path;
|
||||
}
|
||||
|
||||
$package = $this->input->getOption('package');
|
||||
|
||||
// If the package is in the list of migration paths we received we will put
|
||||
// the migrations in that path. Otherwise, we will assume the package is
|
||||
// is in the package directories and will place them in that location.
|
||||
if ( ! is_null($package))
|
||||
{
|
||||
return $this->packagePath.'/'.$package.'/src/migrations';
|
||||
}
|
||||
|
||||
$bench = $this->input->getOption('bench');
|
||||
|
||||
// Finally we will check for the workbench option, which is a shortcut into
|
||||
// specifying the full path for a "workbench" project. Workbenches allow
|
||||
// developers to develop packages along side a "standard" app install.
|
||||
if ( ! is_null($bench))
|
||||
{
|
||||
$path = "/workbench/{$bench}/src/migrations";
|
||||
|
||||
return $this->laravel['path.base'].$path;
|
||||
}
|
||||
|
||||
return $this->laravel['path'].'/database/migrations';
|
||||
}
|
||||
|
||||
}
|
69
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/InstallCommand.php
vendored
Executable file
69
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/InstallCommand.php
vendored
Executable file
@@ -0,0 +1,69 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Illuminate\Database\Migrations\MigrationRepositoryInterface;
|
||||
|
||||
class InstallCommand extends Command {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:install';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create the migration repository';
|
||||
|
||||
/**
|
||||
* The repository instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Console\Migrations\MigrationRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Create a new migration install command instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Console\Migrations\MigrationRepositoryInterface $repository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MigrationRepositoryInterface $repository)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$this->repository->setSource($this->input->getOption('database'));
|
||||
|
||||
$this->repository->createRepository();
|
||||
|
||||
$this->info("Migration table created successfully.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
126
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MakeCommand.php
vendored
Executable file
126
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MakeCommand.php
vendored
Executable file
@@ -0,0 +1,126 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Illuminate\Database\Migrations\MigrationCreator;
|
||||
|
||||
class MakeCommand extends BaseCommand {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:make';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new migration file';
|
||||
|
||||
/**
|
||||
* The migration creator instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Migrations\MigrationCreator
|
||||
*/
|
||||
protected $creator;
|
||||
|
||||
/**
|
||||
* The path to the packages directory (vendor).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $packagePath;
|
||||
|
||||
/**
|
||||
* Create a new migration install command instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Migrations\MigrationCreator $creator
|
||||
* @param string $packagePath
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MigrationCreator $creator, $packagePath)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->creator = $creator;
|
||||
$this->packagePath = $packagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
// It's possible for the developer to specify the tables to modify in this
|
||||
// schema operation. The developer may also specify if this table needs
|
||||
// to be freshly created so we can create the appropriate migrations.
|
||||
$name = $this->input->getArgument('name');
|
||||
|
||||
$table = $this->input->getOption('table');
|
||||
|
||||
$create = $this->input->getOption('create');
|
||||
|
||||
// Now we are ready to write the migration out to disk. Once we've written
|
||||
// the migration out, we will dump-autoload for the entire framework to
|
||||
// make sure that the migrations are registered by the class loaders.
|
||||
$this->writeMigration($name, $table, $create);
|
||||
|
||||
$this->call('dump-autoload');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the migration file to disk.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param bool $create
|
||||
* @return string
|
||||
*/
|
||||
protected function writeMigration($name, $table, $create)
|
||||
{
|
||||
$path = $this->getMigrationPath();
|
||||
|
||||
$file = pathinfo($this->creator->create($name, $path, $table, $create), PATHINFO_FILENAME);
|
||||
|
||||
$this->line("<info>Created Migration:</info> $file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return array(
|
||||
array('name', InputArgument::REQUIRED, 'The name of the migration'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('bench', null, InputOption::VALUE_OPTIONAL, 'The workbench the migration belongs to.', null),
|
||||
|
||||
array('create', null, InputOption::VALUE_NONE, 'The table needs to be created.'),
|
||||
|
||||
array('package', null, InputOption::VALUE_OPTIONAL, 'The package the migration belongs to.', null),
|
||||
|
||||
array('path', null, InputOption::VALUE_OPTIONAL, 'Where to store the migration.', null),
|
||||
|
||||
array('table', null, InputOption::VALUE_OPTIONAL, 'The table to migrate.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
125
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php
vendored
Executable file
125
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php
vendored
Executable file
@@ -0,0 +1,125 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class MigrateCommand extends BaseCommand {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Run the database migrations';
|
||||
|
||||
/**
|
||||
* The migrator instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Migrations\Migrator
|
||||
*/
|
||||
protected $migrator;
|
||||
|
||||
/**
|
||||
* The path to the packages directory (vendor).
|
||||
*/
|
||||
protected $packagePath;
|
||||
|
||||
/**
|
||||
* Create a new migration command instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Migrations\Migrator $migrator
|
||||
* @param string $packagePath
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Migrator $migrator, $packagePath)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->migrator = $migrator;
|
||||
$this->packagePath = $packagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$this->prepareDatabase();
|
||||
|
||||
// The pretend option can be used for "simulating" the migration and grabbing
|
||||
// the SQL queries that would fire if the migration were to be run against
|
||||
// a database for real, which is helpful for double checking migrations.
|
||||
$pretend = $this->input->getOption('pretend');
|
||||
|
||||
$path = $this->getMigrationPath();
|
||||
|
||||
$this->migrator->run($path, $pretend);
|
||||
|
||||
// Once the migrator has run we will grab the note output and send it out to
|
||||
// the console screen, since the migrator itself functions without having
|
||||
// any instances of the OutputInterface contract passed into the class.
|
||||
foreach ($this->migrator->getNotes() as $note)
|
||||
{
|
||||
$this->output->writeln($note);
|
||||
}
|
||||
|
||||
// Finally, if the "seed" option has been given, we will re-run the database
|
||||
// seed task to re-populate the database, which is convenient when adding
|
||||
// a migration and a seed at the same time, as it is only this command.
|
||||
if ($this->input->getOption('seed'))
|
||||
{
|
||||
$this->call('db:seed');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the migration database for running.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareDatabase()
|
||||
{
|
||||
$this->migrator->setConnection($this->input->getOption('database'));
|
||||
|
||||
if ( ! $this->migrator->repositoryExists())
|
||||
{
|
||||
$options = array('--database' => $this->input->getOption('database'));
|
||||
|
||||
$this->call('migrate:install', $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('bench', null, InputOption::VALUE_OPTIONAL, 'The name of the workbench to migrate.', null),
|
||||
|
||||
array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
|
||||
|
||||
array('path', null, InputOption::VALUE_OPTIONAL, 'The path to migration files.', null),
|
||||
|
||||
array('package', null, InputOption::VALUE_OPTIONAL, 'The package to migrate.', null),
|
||||
|
||||
array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'),
|
||||
|
||||
array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
58
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/RefreshCommand.php
vendored
Executable file
58
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/RefreshCommand.php
vendored
Executable file
@@ -0,0 +1,58 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class RefreshCommand extends Command {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:refresh';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Reset and re-run all migrations';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$database = $this->input->getOption('database');
|
||||
|
||||
$this->call('migrate:reset', array('--database' => $database));
|
||||
|
||||
// The refresh command is essentially just a brief aggregate of a few other of
|
||||
// the migration commands and just provides a convenient wrapper to execute
|
||||
// them in succession. We'll also see if we need to res-eed the database.
|
||||
$this->call('migrate', array('--database' => $database));
|
||||
|
||||
if ($this->input->getOption('seed'))
|
||||
{
|
||||
$this->call('db:seed', array('--database' => $database));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
|
||||
|
||||
array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
84
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/ResetCommand.php
vendored
Executable file
84
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/ResetCommand.php
vendored
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ResetCommand extends Command {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:reset';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Rollback all database migrations';
|
||||
|
||||
/**
|
||||
* The migrator instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Migrations\Migrator
|
||||
*/
|
||||
protected $migrator;
|
||||
|
||||
/**
|
||||
* Create a new migration rollback command instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Migrations\Migrator $migrator
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Migrator $migrator)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->migrator = $migrator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$this->migrator->setConnection($this->input->getOption('database'));
|
||||
|
||||
$pretend = $this->input->getOption('pretend');
|
||||
|
||||
while (true)
|
||||
{
|
||||
$count = $this->migrator->rollback($pretend);
|
||||
|
||||
// Once the migrator has run we will grab the note output and send it out to
|
||||
// the console screen, since the migrator itself functions without having
|
||||
// any instances of the OutputInterface contract passed into the class.
|
||||
foreach ($this->migrator->getNotes() as $note)
|
||||
{
|
||||
$this->output->writeln($note);
|
||||
}
|
||||
|
||||
if ($count == 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
|
||||
|
||||
array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
79
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/RollbackCommand.php
vendored
Executable file
79
vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/RollbackCommand.php
vendored
Executable file
@@ -0,0 +1,79 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class RollbackCommand extends Command {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:rollback';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Rollback the last database migration';
|
||||
|
||||
/**
|
||||
* The migrator instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Migrations\Migrator
|
||||
*/
|
||||
protected $migrator;
|
||||
|
||||
/**
|
||||
* Create a new migration rollback command instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Migrations\Migrator $migrator
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Migrator $migrator)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->migrator = $migrator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$this->migrator->setConnection($this->input->getOption('database'));
|
||||
|
||||
$pretend = $this->input->getOption('pretend');
|
||||
|
||||
$this->migrator->rollback($pretend);
|
||||
|
||||
// Once the migrator has run we will grab the note output and send it out to
|
||||
// the console screen, since the migrator itself functions without having
|
||||
// any instances of the OutputInterface contract passed into the class.
|
||||
foreach ($this->migrator->getNotes() as $note)
|
||||
{
|
||||
$this->output->writeln($note);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
|
||||
|
||||
array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
96
vendor/laravel/framework/src/Illuminate/Database/Console/SeedCommand.php
vendored
Executable file
96
vendor/laravel/framework/src/Illuminate/Database/Console/SeedCommand.php
vendored
Executable file
@@ -0,0 +1,96 @@
|
||||
<?php namespace Illuminate\Database\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Illuminate\Database\ConnectionResolverInterface as Resolver;
|
||||
|
||||
class SeedCommand extends Command {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'db:seed';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Seed the database with records';
|
||||
|
||||
/**
|
||||
* The connection resolver instance.
|
||||
*
|
||||
* @var \Illuminate\Database\ConnectionResolverInterface
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
/**
|
||||
* Create a new database seed command instance.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionResolverInterface $resolver
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Resolver $resolver)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$this->resolver->setDefaultConnection($this->getDatabase());
|
||||
|
||||
$this->getSeeder()->run();
|
||||
|
||||
$this->info('Database seeded!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a seeder instance from the container.
|
||||
*
|
||||
* @return \Illuminate\Database\Seeder
|
||||
*/
|
||||
protected function getSeeder()
|
||||
{
|
||||
$class = $this->laravel->make($this->input->getOption('class'));
|
||||
|
||||
return $class->setContainer($this->laravel)->setCommand($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the database connection to use.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDatabase()
|
||||
{
|
||||
$database = $this->input->getOption('database');
|
||||
|
||||
return $database ?: $this->laravel['config']['database.default'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder', 'DatabaseSeeder'),
|
||||
|
||||
array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
222
vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php
vendored
Executable file
222
vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php
vendored
Executable file
@@ -0,0 +1,222 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Support\Manager;
|
||||
use Illuminate\Database\Connectors\ConnectionFactory;
|
||||
|
||||
class DatabaseManager implements ConnectionResolverInterface {
|
||||
|
||||
/**
|
||||
* The application instance.
|
||||
*
|
||||
* @var \Illuminate\Foundation\Application
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* The database connection factory instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Connectors\ConnectionFactory
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
/**
|
||||
* The active connection instances.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $connections = array();
|
||||
|
||||
/**
|
||||
* The custom connection resolvers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $extensions = array();
|
||||
|
||||
/**
|
||||
* Create a new database manager instance.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @param \Illuminate\Database\Connectors\ConnectionFactory $factory
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($app, ConnectionFactory $factory)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->factory = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a database connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function connection($name = null)
|
||||
{
|
||||
$name = $name ?: $this->getDefaultConnection();
|
||||
|
||||
// If we haven't created this connection, we'll create it based on the config
|
||||
// provided in the application. Once we've created the connections we will
|
||||
// set the "fetch mode" for PDO which determines the query return types.
|
||||
if ( ! isset($this->connections[$name]))
|
||||
{
|
||||
$connection = $this->makeConnection($name);
|
||||
|
||||
$this->connections[$name] = $this->prepare($connection);
|
||||
}
|
||||
|
||||
return $this->connections[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnect to the given database.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function reconnect($name = null)
|
||||
{
|
||||
$name = $name ?: $this->getDefaultConnection();
|
||||
|
||||
unset($this->connections[$name]);
|
||||
|
||||
return $this->connection($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the database connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
protected function makeConnection($name)
|
||||
{
|
||||
$config = $this->getConfig($name);
|
||||
|
||||
// First we will check by the connection name to see if an extension has been
|
||||
// registered specifically for that connection. If it has we will call the
|
||||
// Closure and pass it the config allowing it to resolve the connection.
|
||||
if (isset($this->extensions[$name]))
|
||||
{
|
||||
return call_user_func($this->extensions[$name], $config);
|
||||
}
|
||||
|
||||
$driver = $config['driver'];
|
||||
|
||||
// Next we will check to see if an extension has been registered for a driver
|
||||
// and will call the Closure if so, which allows us to have a more generic
|
||||
// resolver for the drivers themselves which applies to all connections.
|
||||
if (isset($this->extensions[$driver]))
|
||||
{
|
||||
return call_user_func($this->extensions[$driver], $config);
|
||||
}
|
||||
|
||||
return $this->factory->make($config, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the database connection instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
protected function prepare(Connection $connection)
|
||||
{
|
||||
$connection->setFetchMode($this->app['config']['database.fetch']);
|
||||
|
||||
if ($this->app->bound('events'))
|
||||
{
|
||||
$connection->setEventDispatcher($this->app['events']);
|
||||
}
|
||||
|
||||
// The database connection can also utilize a cache manager instance when cache
|
||||
// functionality is used on queries, which provides an expressive interface
|
||||
// to caching both fluent queries and Eloquent queries that are executed.
|
||||
$app = $this->app;
|
||||
|
||||
$connection->setCacheManager(function() use ($app)
|
||||
{
|
||||
return $app['cache'];
|
||||
});
|
||||
|
||||
// We will setup a Closure to resolve the paginator instance on the connection
|
||||
// since the Paginator isn't sued on every request and needs quite a few of
|
||||
// our dependencies. It'll be more efficient to lazily resolve instances.
|
||||
$connection->setPaginator(function() use ($app)
|
||||
{
|
||||
return $app['paginator'];
|
||||
});
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration for a connection.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function getConfig($name)
|
||||
{
|
||||
$name = $name ?: $this->getDefaultConnection();
|
||||
|
||||
// To get the database connection configuration, we will just pull each of the
|
||||
// connection configurations and get the configurations for the given name.
|
||||
// If the configuration doesn't exist, we'll throw an exception and bail.
|
||||
$connections = $this->app['config']['database.connections'];
|
||||
|
||||
if (is_null($config = array_get($connections, $name)))
|
||||
{
|
||||
throw new \InvalidArgumentException("Database [$name] not configured.");
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default connection name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultConnection()
|
||||
{
|
||||
return $this->app['config']['database.default'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default connection name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultConnection($name)
|
||||
{
|
||||
$this->app['config']['database.default'] = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an extension connection resolver.
|
||||
*
|
||||
* @param string $name
|
||||
* @param callable $resolver
|
||||
* @return void
|
||||
*/
|
||||
public function extend($name, $resolver)
|
||||
{
|
||||
$this->extensions[$name] = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically pass methods to the default connection.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return call_user_func_array(array($this->connection(), $method), $parameters);
|
||||
}
|
||||
|
||||
}
|
45
vendor/laravel/framework/src/Illuminate/Database/DatabaseServiceProvider.php
vendored
Executable file
45
vendor/laravel/framework/src/Illuminate/Database/DatabaseServiceProvider.php
vendored
Executable file
@@ -0,0 +1,45 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Database\Connectors\ConnectionFactory;
|
||||
|
||||
class DatabaseServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Model::setConnectionResolver($this->app['db']);
|
||||
|
||||
Model::setEventDispatcher($this->app['events']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// The connection factory is used to create the actual connection instances on
|
||||
// the database. We will inject the factory into the manager so that it may
|
||||
// make the connections while they are actually needed and not of before.
|
||||
$this->app['db.factory'] = $this->app->share(function($app)
|
||||
{
|
||||
return new ConnectionFactory($app);
|
||||
});
|
||||
|
||||
// The database manager is used to resolve various connections, since multiple
|
||||
// connections might be managed. It also implements the connection resolver
|
||||
// interface which may be used by other components requiring connections.
|
||||
$this->app['db'] = $this->app->share(function($app)
|
||||
{
|
||||
return new DatabaseManager($app, $app['db.factory']);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
737
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php
vendored
Executable file
737
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php
vendored
Executable file
@@ -0,0 +1,737 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
use Closure;
|
||||
use DateTime;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
|
||||
class Builder {
|
||||
|
||||
/**
|
||||
* The base query builder instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected $query;
|
||||
|
||||
/**
|
||||
* The model being queried.
|
||||
*
|
||||
* @var \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* The relationships that should be eager loaded.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $eagerLoad = array();
|
||||
|
||||
/**
|
||||
* The methods that should be returned from query builder.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $passthru = array(
|
||||
'toSql', 'lists', 'insert', 'insertGetId', 'pluck',
|
||||
'count', 'min', 'max', 'avg', 'sum', 'exists',
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new Eloquent query builder instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(QueryBuilder $query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a model by its primary key.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Model|static|null
|
||||
*/
|
||||
public function find($id, $columns = array('*'))
|
||||
{
|
||||
$this->query->where($this->model->getKeyName(), '=', $id);
|
||||
|
||||
return $this->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a model by its primary key or throw an exception.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Model|static
|
||||
*/
|
||||
public function findOrFail($id, $columns = array('*'))
|
||||
{
|
||||
if ( ! is_null($model = $this->find($id, $columns))) return $model;
|
||||
|
||||
throw new ModelNotFoundException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query and get the first result.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Model|static|null
|
||||
*/
|
||||
public function first($columns = array('*'))
|
||||
{
|
||||
return $this->take(1)->get($columns)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query and get the first result or throw an exception.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Model|static
|
||||
*/
|
||||
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|static[]
|
||||
*/
|
||||
public function get($columns = array('*'))
|
||||
{
|
||||
$models = $this->getModels($columns);
|
||||
|
||||
// If we actually found models we will also eager load any relationships that
|
||||
// have been specified as needing to be eager loaded, which will solve the
|
||||
// n+1 query issue for the developers to avoid running a lot of queries.
|
||||
if (count($models) > 0)
|
||||
{
|
||||
$models = $this->eagerLoadRelations($models);
|
||||
}
|
||||
|
||||
return $this->model->newCollection($models);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluck a single column from the database.
|
||||
*
|
||||
* @param string $column
|
||||
* @return mixed
|
||||
*/
|
||||
public function pluck($column)
|
||||
{
|
||||
$result = $this->first(array($column));
|
||||
|
||||
if ($result) return $result->{$column};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array with the values of a given column.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
public function lists($column, $key = null)
|
||||
{
|
||||
$results = $this->query->lists($column, $key);
|
||||
|
||||
// If the model has a mutator for the requested column, we will spin through
|
||||
// the results and mutate the values so that the mutated version of these
|
||||
// columns are returned as you would expect from these Eloquent models.
|
||||
if ($this->model->hasGetMutator($column))
|
||||
{
|
||||
foreach ($results as $key => &$value)
|
||||
{
|
||||
$fill = array($column => $value);
|
||||
|
||||
$value = $this->model->newFromBuilder($fill)->$column;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a paginator for the "select" statement.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Pagination\Paginator
|
||||
*/
|
||||
public function paginate($perPage = null, $columns = array('*'))
|
||||
{
|
||||
$perPage = $perPage ?: $this->model->getPerPage();
|
||||
|
||||
$paginator = $this->query->getConnection()->getPaginator();
|
||||
|
||||
if (isset($this->query->groups))
|
||||
{
|
||||
return $this->groupedPaginate($paginator, $perPage, $columns);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->ungroupedPaginate($paginator, $perPage, $columns);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a paginator for a grouped statement.
|
||||
*
|
||||
* @param \Illuminate\Pagination\Environment $paginator
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Pagination\Paginator
|
||||
*/
|
||||
protected function groupedPaginate($paginator, $perPage, $columns)
|
||||
{
|
||||
$results = $this->get($columns)->all();
|
||||
|
||||
return $this->query->buildRawPaginator($paginator, $results, $perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a paginator for an ungrouped statement.
|
||||
*
|
||||
* @param \Illuminate\Pagination\Environment $paginator
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Pagination\Paginator
|
||||
*/
|
||||
protected function ungroupedPaginate($paginator, $perPage, $columns)
|
||||
{
|
||||
$total = $this->query->getPaginationCount();
|
||||
|
||||
// Once we have the paginator we need to set the limit and offset values for
|
||||
// the query so we can get the properly paginated items. Once we have an
|
||||
// array of items we can create the paginator instances for the items.
|
||||
$page = $paginator->getCurrentPage();
|
||||
|
||||
$this->query->forPage($page, $perPage);
|
||||
|
||||
return $paginator->make($this->get($columns)->all(), $total, $perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a record in the database.
|
||||
*
|
||||
* @param array $values
|
||||
* @return int
|
||||
*/
|
||||
public function update(array $values)
|
||||
{
|
||||
return $this->query->update($this->addUpdatedAtColumn($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment a column's value by a given amount.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $amount
|
||||
* @param array $extra
|
||||
* @return int
|
||||
*/
|
||||
public function increment($column, $amount = 1, array $extra = array())
|
||||
{
|
||||
$extra = $this->addUpdatedAtColumn($extra);
|
||||
|
||||
return $this->query->increment($column, $amount, $extra);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement a column's value by a given amount.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $amount
|
||||
* @param array $extra
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($column, $amount = 1, array $extra = array())
|
||||
{
|
||||
$extra = $this->addUpdatedAtColumn($extra);
|
||||
|
||||
return $this->query->decrement($column, $amount, $extra);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the "updated at" column to an array of values.
|
||||
*
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
protected function addUpdatedAtColumn(array $values)
|
||||
{
|
||||
if ( ! $this->model->usesTimestamps()) return $values;
|
||||
|
||||
$column = $this->model->getUpdatedAtColumn();
|
||||
|
||||
return array_add($values, $column, $this->model->freshTimestampString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a record from the database.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if ($this->model->isSoftDeleting())
|
||||
{
|
||||
return $this->softDelete();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->query->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Soft delete the record in the database.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function softDelete()
|
||||
{
|
||||
$column = $this->model->getDeletedAtColumn();
|
||||
|
||||
return $this->update(array($column => $this->model->freshTimestampString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a delete on a set of soft deleted models.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function forceDelete()
|
||||
{
|
||||
return $this->query->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the soft-deleted model instances.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
if ($this->model->isSoftDeleting())
|
||||
{
|
||||
$column = $this->model->getDeletedAtColumn();
|
||||
|
||||
return $this->update(array($column => null));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the soft deleted models in the results.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function withTrashed()
|
||||
{
|
||||
$column = $this->model->getQualifiedDeletedAtColumn();
|
||||
|
||||
foreach ($this->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($this->query->wheres[$key]);
|
||||
|
||||
$this->query->wheres = array_values($this->query->wheres);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the result set to only included soft deletes.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function onlyTrashed()
|
||||
{
|
||||
$this->withTrashed();
|
||||
|
||||
$this->query->whereNotNull($this->model->getQualifiedDeletedAtColumn());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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['column'] == $column and $where['type'] == 'Null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hydrated models without eager loading.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return array|static[]
|
||||
*/
|
||||
public function getModels($columns = array('*'))
|
||||
{
|
||||
// First, we will simply get the raw results from the query builders which we
|
||||
// can use to populate an array with Eloquent models. We will pass columns
|
||||
// that should be selected as well, which are typically just everything.
|
||||
$results = $this->query->get($columns);
|
||||
|
||||
$connection = $this->model->getConnectionName();
|
||||
|
||||
$models = array();
|
||||
|
||||
// Once we have the results, we can spin through them and instantiate a fresh
|
||||
// model instance for each records we retrieved from the database. We will
|
||||
// also set the proper connection name for the model after we create it.
|
||||
foreach ($results as $result)
|
||||
{
|
||||
$models[] = $model = $this->model->newFromBuilder($result);
|
||||
|
||||
$model->setConnection($connection);
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eager load the relationships for the models.
|
||||
*
|
||||
* @param array $models
|
||||
* @return array
|
||||
*/
|
||||
public function eagerLoadRelations(array $models)
|
||||
{
|
||||
foreach ($this->eagerLoad as $name => $constraints)
|
||||
{
|
||||
// For nested eager loads we'll skip loading them here and they will be set as an
|
||||
// eager load on the query to retrieve the relation so that they will be eager
|
||||
// loaded on that query, because that is where they get hydrated as models.
|
||||
if (strpos($name, '.') === false)
|
||||
{
|
||||
$models = $this->loadRelation($models, $name, $constraints);
|
||||
}
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eagerly load the relationship on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $name
|
||||
* @param \Closure $constraints
|
||||
* @return array
|
||||
*/
|
||||
protected function loadRelation(array $models, $name, Closure $constraints)
|
||||
{
|
||||
// First we will "back up" the existing where conditions on the query so we can
|
||||
// add our eager constraints. Then we will merge the wheres that were on the
|
||||
// query back to it in order that any where conditions might be specified.
|
||||
$relation = $this->getRelation($name);
|
||||
|
||||
$relation->addEagerConstraints($models);
|
||||
|
||||
call_user_func($constraints, $relation);
|
||||
|
||||
$models = $relation->initRelation($models, $name);
|
||||
|
||||
// Once we have the results, we just match those back up to their parent models
|
||||
// using the relationship instance. Then we just return the finished arrays
|
||||
// of models which have been eagerly hydrated and are readied for return.
|
||||
$results = $relation->get();
|
||||
|
||||
return $relation->match($models, $results, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relation instance for the given relation name.
|
||||
*
|
||||
* @param string $relation
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function getRelation($relation)
|
||||
{
|
||||
$me = $this;
|
||||
|
||||
// We want to run a relationship query without any constrains so that we will
|
||||
// not have to remove these where clauses manually which gets really hacky
|
||||
// and is error prone while we remove the developer's own where clauses.
|
||||
$query = Relation::noConstraints(function() use ($me, $relation)
|
||||
{
|
||||
return $me->getModel()->$relation();
|
||||
});
|
||||
|
||||
$nested = $this->nestedRelations($relation);
|
||||
|
||||
// If there are nested relationships set on the query, we will put those onto
|
||||
// the query instances so that they can be handled after this relationship
|
||||
// is loaded. In this way they will all trickle down as they are loaded.
|
||||
if (count($nested) > 0)
|
||||
{
|
||||
$query->getQuery()->with($nested);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the deeply nested relations for a given top-level relation.
|
||||
*
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
protected function nestedRelations($relation)
|
||||
{
|
||||
$nested = array();
|
||||
|
||||
// We are basically looking for any relationships that are nested deeper than
|
||||
// the given top-level relationship. We will just check for any relations
|
||||
// that start with the given top relations and adds them to our arrays.
|
||||
foreach ($this->eagerLoad as $name => $constraints)
|
||||
{
|
||||
if ($this->isNested($name, $relation))
|
||||
{
|
||||
$nested[substr($name, strlen($relation.'.'))] = $constraints;
|
||||
}
|
||||
}
|
||||
|
||||
return $nested;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the relationship is nested.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $relation
|
||||
* @return bool
|
||||
*/
|
||||
protected function isNested($name, $relation)
|
||||
{
|
||||
$dots = str_contains($name, '.');
|
||||
|
||||
return $dots and starts_with($name, $relation) and $name != $relation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a relationship count condition to the query.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function has($relation, $operator = '>=', $count = 1, $boolean = 'and')
|
||||
{
|
||||
$instance = $this->model->$relation();
|
||||
|
||||
$query = $instance->getRelationCountQuery($instance->getRelated()->newQuery());
|
||||
|
||||
$this->query->mergeBindings($query->getQuery());
|
||||
|
||||
return $this->where(new Expression('('.$query->toSql().')'), $operator, $count, $boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a relationship count condition to the query with an "or".
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function orHas($relation, $operator = '>=', $count = 1)
|
||||
{
|
||||
return $this->has($relation, $operator, $count, 'or');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the relationships that should be eager loaded.
|
||||
*
|
||||
* @param dynamic $relations
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function with($relations)
|
||||
{
|
||||
if (is_string($relations)) $relations = func_get_args();
|
||||
|
||||
$eagers = $this->parseRelations($relations);
|
||||
|
||||
$this->eagerLoad = array_merge($this->eagerLoad, $eagers);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a list of relations into individuals.
|
||||
*
|
||||
* @param array $relations
|
||||
* @return array
|
||||
*/
|
||||
protected function parseRelations(array $relations)
|
||||
{
|
||||
$results = array();
|
||||
|
||||
foreach ($relations as $name => $constraints)
|
||||
{
|
||||
// If the "relation" value is actually a numeric key, we can assume that no
|
||||
// constraints have been specified for the eager load and we'll just put
|
||||
// an empty Closure with the loader so that we can treat all the same.
|
||||
if (is_numeric($name))
|
||||
{
|
||||
$f = function() {};
|
||||
|
||||
list($name, $constraints) = array($constraints, $f);
|
||||
}
|
||||
|
||||
// We need to separate out any nested includes. Which allows the developers
|
||||
// to load deep relationships using "dots" without stating each level of
|
||||
// the relationship with its own key in the array of eager load names.
|
||||
$results = $this->parseNested($name, $results);
|
||||
|
||||
$results[$name] = $constraints;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the nested relationships in a relation.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
protected function parseNested($name, $results)
|
||||
{
|
||||
$progress = array();
|
||||
|
||||
// If the relation has already been set on the result array, we will not set it
|
||||
// again, since that would override any constraints that were already placed
|
||||
// on the relationships. We will only set the ones that are not specified.
|
||||
foreach (explode('.', $name) as $segment)
|
||||
{
|
||||
$progress[] = $segment;
|
||||
|
||||
if ( ! isset($results[$last = implode('.', $progress)]))
|
||||
{
|
||||
$results[$last] = function() {};
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying query builder instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder|static
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the underlying query builder instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return void
|
||||
*/
|
||||
public function setQuery($query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relationships being eagerly loaded.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEagerLoads()
|
||||
{
|
||||
return $this->eagerLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the relationships being eagerly loaded.
|
||||
*
|
||||
* @param array $eagerLoad
|
||||
* @return void
|
||||
*/
|
||||
public function setEagerLoads(array $eagerLoad)
|
||||
{
|
||||
$this->eagerLoad = $eagerLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model instance being queried.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a model instance for the model being queried.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function setModel(Model $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
|
||||
$this->query->from($model->getTable());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically handle calls into the query instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (method_exists($this->model, $scope = 'scope'.ucfirst($method)))
|
||||
{
|
||||
array_unshift($parameters, $this);
|
||||
|
||||
call_user_func_array(array($this->model, $scope), $parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = call_user_func_array(array($this->query, $method), $parameters);
|
||||
}
|
||||
|
||||
return in_array($method, $this->passthru) ? $result : $this;
|
||||
}
|
||||
|
||||
}
|
84
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php
vendored
Executable file
84
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php
vendored
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
use Illuminate\Support\Collection as BaseCollection;
|
||||
|
||||
class Collection extends BaseCollection {
|
||||
|
||||
/**
|
||||
* Find a model in the collection by key.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $default
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function find($key, $default = null)
|
||||
{
|
||||
return array_first($this->items, function($key, $model) use ($key)
|
||||
{
|
||||
return $model->getKey() == $key;
|
||||
|
||||
}, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a set of relationships onto the collection.
|
||||
*
|
||||
* @param dynamic string
|
||||
* @return void
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
if (count($this->items) > 0)
|
||||
{
|
||||
$query = $this->first()->newQuery()->with(func_get_args());
|
||||
|
||||
$this->items = $query->eagerLoadRelations($this->items);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to the collection.
|
||||
*
|
||||
* @param mixed $item
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function add($item)
|
||||
{
|
||||
$this->items[] = $item;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a key exists in the collection.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return bool
|
||||
*/
|
||||
public function contains($key)
|
||||
{
|
||||
return ! is_null($this->find($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a nested element of the collection.
|
||||
*
|
||||
* @param string $key
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function fetch($key)
|
||||
{
|
||||
return new static(array_fetch($this->toArray(), $key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of primary keys
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function modelKeys()
|
||||
{
|
||||
return array_map(function($m) { return $m->getKey(); }, $this->items);
|
||||
}
|
||||
|
||||
}
|
3
vendor/laravel/framework/src/Illuminate/Database/Eloquent/MassAssignmentException.php
vendored
Executable file
3
vendor/laravel/framework/src/Illuminate/Database/Eloquent/MassAssignmentException.php
vendored
Executable file
@@ -0,0 +1,3 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
class MassAssignmentException extends \RuntimeException {}
|
2572
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
vendored
Executable file
2572
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
vendored
Executable file
File diff suppressed because it is too large
Load Diff
3
vendor/laravel/framework/src/Illuminate/Database/Eloquent/ModelNotFoundException.php
vendored
Executable file
3
vendor/laravel/framework/src/Illuminate/Database/Eloquent/ModelNotFoundException.php
vendored
Executable file
@@ -0,0 +1,3 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
class ModelNotFoundException extends \RuntimeException {}
|
221
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php
vendored
Executable file
221
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php
vendored
Executable file
@@ -0,0 +1,221 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use LogicException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class BelongsTo extends Relation {
|
||||
|
||||
/**
|
||||
* The foreign key of the parent model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $foreignKey;
|
||||
|
||||
/**
|
||||
* The name of the relationship.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $relation;
|
||||
|
||||
/**
|
||||
* Create a new has many relationship instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $relation
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $foreignKey, $relation)
|
||||
{
|
||||
$this->relation = $relation;
|
||||
$this->foreignKey = $foreignKey;
|
||||
|
||||
parent::__construct($query, $parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
return $this->query->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
if (static::$constraints)
|
||||
{
|
||||
// For belongs to relationships, which are essentially the inverse of has one
|
||||
// or has many relationships, we need to actually query on the primary key
|
||||
// of the related models matching on the foreign key that's on a parent.
|
||||
$key = $this->related->getKeyName();
|
||||
|
||||
$table = $this->related->getTable();
|
||||
|
||||
$this->query->where($table.'.'.$key, '=', $this->parent->{$this->foreignKey});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query)
|
||||
{
|
||||
throw new LogicException('Has method invalid on "belongsTo" relations.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
// We'll grab the primary key name of the related models since it could be set to
|
||||
// a non-standard name and not "id". We will then construct the constraint for
|
||||
// our eagerly loading query so it returns the proper models from execution.
|
||||
$key = $this->related->getKeyName();
|
||||
|
||||
$key = $this->related->getTable().'.'.$key;
|
||||
|
||||
$this->query->whereIn($key, $this->getEagerModelKeys($models));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather the keys from an array of related models.
|
||||
*
|
||||
* @param array $models
|
||||
* @return array
|
||||
*/
|
||||
protected function getEagerModelKeys(array $models)
|
||||
{
|
||||
$keys = array();
|
||||
|
||||
// First we need to gather all of the keys from the parent models so we know what
|
||||
// to query for via the eager loading query. We will add them to an array then
|
||||
// execute a "where in" statement to gather up all of those related records.
|
||||
foreach ($models as $model)
|
||||
{
|
||||
if ( ! is_null($value = $model->{$this->foreignKey}))
|
||||
{
|
||||
$keys[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no keys that were not null we will just return an array with 0 in
|
||||
// it so the query doesn't fail, but will not return any results, which should
|
||||
// be what this developer is expecting in a case where this happens to them.
|
||||
if (count($keys) == 0)
|
||||
{
|
||||
return array(0);
|
||||
}
|
||||
|
||||
return array_values(array_unique($keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @return void
|
||||
*/
|
||||
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)
|
||||
{
|
||||
$foreign = $this->foreignKey;
|
||||
|
||||
// First we will get to build a dictionary of the child models by their primary
|
||||
// key of the relationship, then we can easily match the children back onto
|
||||
// the parents using that dictionary and the primary key of the children.
|
||||
$dictionary = array();
|
||||
|
||||
foreach ($results as $result)
|
||||
{
|
||||
$dictionary[$result->getKey()] = $result;
|
||||
}
|
||||
|
||||
// Once we have the dictionary constructed, we can loop through all the parents
|
||||
// and match back onto their children using these keys of the dictionary and
|
||||
// the primary key of the children to map them onto the correct instances.
|
||||
foreach ($models as $model)
|
||||
{
|
||||
if (isset($dictionary[$model->$foreign]))
|
||||
{
|
||||
$model->setRelation($relation, $dictionary[$model->$foreign]);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
return $this->parent->setRelation($this->relation, $model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the parent model on the relationship.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(array $attributes)
|
||||
{
|
||||
$instance = $this->getResults();
|
||||
|
||||
return $instance->fill($attributes)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreign key of the relationship.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getForeignKey()
|
||||
{
|
||||
return $this->foreignKey;
|
||||
}
|
||||
|
||||
}
|
900
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
vendored
Executable file
900
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
vendored
Executable file
@@ -0,0 +1,900 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use DateTime;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
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();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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();
|
||||
|
||||
$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
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query)
|
||||
{
|
||||
$this->setJoin($query);
|
||||
|
||||
return parent::getRelationCountQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the select clause for the relation query.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the join clause for the relation query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder|null
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
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 \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
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 void
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param array $ids
|
||||
* @param bool $detaching
|
||||
* @return void
|
||||
*/
|
||||
public function sync(array $ids, $detaching = true)
|
||||
{
|
||||
// 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 and count($detach) > 0)
|
||||
{
|
||||
$this->detach($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.
|
||||
$this->attachNew($records, $current, false);
|
||||
|
||||
$this->touchIfTouching();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_numeric($attributes))
|
||||
{
|
||||
list($id, $attributes) = array((int) $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 void
|
||||
*/
|
||||
protected function attachNew(array $records, array $current, $touch = true)
|
||||
{
|
||||
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);
|
||||
}
|
||||
elseif (count($attributes) > 0)
|
||||
{
|
||||
$this->updateExistingPivot($id, $attributes, $touch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pivot record on the table.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $attributes
|
||||
* @param bool $touch
|
||||
* @return void
|
||||
*/
|
||||
protected function updateExistingPivot($id, array $attributes, $touch)
|
||||
{
|
||||
if (in_array($this->updatedAt(), $this->pivotColumns))
|
||||
{
|
||||
$attributes = $this->setTimestampsOnAttach($attributes, true);
|
||||
}
|
||||
|
||||
$this->newPivotStatementForId($id)->update($attributes);
|
||||
|
||||
if ($touch) $this->touchIfTouching();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return void
|
||||
*/
|
||||
protected function createAttachRecords($ids, array $attributes)
|
||||
{
|
||||
$records = array();
|
||||
|
||||
$timed = in_array($this->createdAt(), $this->pivotColumns);
|
||||
|
||||
// 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));
|
||||
}
|
||||
else
|
||||
{
|
||||
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 timstamps 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) $record[$this->createdAt()] = $fresh;
|
||||
|
||||
$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, $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 strtolower(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();
|
||||
|
||||
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
|
||||
*/
|
||||
protected function newPivotStatementForId($id)
|
||||
{
|
||||
$pivot = $this->newPivotStatement();
|
||||
|
||||
$key = $this->parent->getKey();
|
||||
|
||||
return $pivot->where($this->foreignKey, $key)->where($this->otherKey, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new pivot model instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param bool $exists
|
||||
* @return \Illuminate\Database\Eloquent\Relation\Pivot
|
||||
*/
|
||||
public function newPivot(array $attributes = array(), $exists = false)
|
||||
{
|
||||
$pivot = new Pivot($this->parent, $attributes, $this->table, $exists);
|
||||
|
||||
$pivot->setPivotKeys($this->foreignKey, $this->otherKey);
|
||||
|
||||
return $pivot;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function withTimestamps()
|
||||
{
|
||||
return $this->withPivot($this->createdAt(), $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 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;
|
||||
}
|
||||
|
||||
}
|
47
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasMany.php
vendored
Executable file
47
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasMany.php
vendored
Executable file
@@ -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 void
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
47
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOne.php
vendored
Executable file
47
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOne.php
vendored
Executable file
@@ -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 void
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
259
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
vendored
Executable file
259
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
vendored
Executable file
@@ -0,0 +1,259 @@
|
||||
<?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;
|
||||
|
||||
abstract class HasOneOrMany extends Relation {
|
||||
|
||||
/**
|
||||
* The foreign key of the parent model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $foreignKey;
|
||||
|
||||
/**
|
||||
* Create a new has many relationship instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $foreignKey)
|
||||
{
|
||||
$this->foreignKey = $foreignKey;
|
||||
|
||||
parent::__construct($query, $parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
if (static::$constraints)
|
||||
{
|
||||
$key = $this->parent->getKey();
|
||||
|
||||
$this->query->where($this->foreignKey, '=', $key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->getKey();
|
||||
|
||||
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->parent->getKey());
|
||||
|
||||
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)
|
||||
{
|
||||
$foreign = array(
|
||||
$this->getPlainForeignKey() => $this->parent->getKey()
|
||||
);
|
||||
|
||||
// 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();
|
||||
|
||||
$instance->setRawAttributes(array_merge($attributes, $foreign));
|
||||
|
||||
$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 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];
|
||||
}
|
||||
|
||||
}
|
47
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphMany.php
vendored
Executable file
47
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphMany.php
vendored
Executable file
@@ -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 void
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
47
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOne.php
vendored
Executable file
47
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOne.php
vendored
Executable file
@@ -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 void
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
160
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php
vendored
Executable file
160
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php
vendored
Executable file
@@ -0,0 +1,160 @@
|
||||
<?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
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $type, $id)
|
||||
{
|
||||
$this->morphType = $type;
|
||||
|
||||
$this->morphClass = get_class($parent);
|
||||
|
||||
parent::__construct($query, $parent, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query)
|
||||
{
|
||||
$query = parent::getRelationCountQuery($query);
|
||||
|
||||
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)
|
||||
{
|
||||
$foreign = $this->getForeignAttributesForCreate();
|
||||
|
||||
// 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.
|
||||
$attributes = array_merge($attributes, $foreign);
|
||||
|
||||
$instance = $this->related->newInstance($attributes);
|
||||
|
||||
$instance->save();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreign ID and type for creating a related model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getForeignAttributesForCreate()
|
||||
{
|
||||
$foreign = array($this->getPlainForeignKey() => $this->parent->getKey());
|
||||
|
||||
$foreign[last(explode('.', $this->morphType))] = $this->morphClass;
|
||||
|
||||
return $foreign;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
158
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Pivot.php
vendored
Executable file
158
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Pivot.php
vendored
Executable file
@@ -0,0 +1,158 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
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);
|
||||
|
||||
$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($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()
|
||||
{
|
||||
$foreign = $this->getAttribute($this->foreignKey);
|
||||
|
||||
$query = $this->newQuery()->where($this->foreignKey, $foreign);
|
||||
|
||||
return $query->where($this->otherKey, $this->getAttribute($this->otherKey))->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 void
|
||||
*/
|
||||
public function setPivotKeys($foreignKey, $otherKey)
|
||||
{
|
||||
$this->foreignKey = $foreignKey;
|
||||
|
||||
$this->otherKey = $otherKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
278
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Relation.php
vendored
Executable file
278
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Relation.php
vendored
Executable file
@@ -0,0 +1,278 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use Closure;
|
||||
use DateTime;
|
||||
use Carbon\Carbon;
|
||||
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 void
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* Touch all of the related models for the relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$column = $this->getRelated()->getUpdatedAtColumn();
|
||||
|
||||
$this->rawUpdate(array($column => $this->getRelated()->freshTimestamp()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore all of the soft deleted related models.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return $this->query->withTrashed()->restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query)
|
||||
{
|
||||
$query->select(new Expression('count(*)'));
|
||||
|
||||
$key = $this->wrap($this->parent->getQualifiedKeyName());
|
||||
|
||||
return $query->where($this->getForeignKey(), '=', new Expression($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a callback with constrains 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
|
||||
* @return array
|
||||
*/
|
||||
protected function getKeys(array $models)
|
||||
{
|
||||
return array_values(array_map(function($value)
|
||||
{
|
||||
return $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 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->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;
|
||||
}
|
||||
|
||||
}
|
177
vendor/laravel/framework/src/Illuminate/Database/Grammar.php
vendored
Executable file
177
vendor/laravel/framework/src/Illuminate/Database/Grammar.php
vendored
Executable file
@@ -0,0 +1,177 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
abstract class Grammar {
|
||||
|
||||
/**
|
||||
* The grammar table prefix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tablePrefix = '';
|
||||
|
||||
/**
|
||||
* Wrap an array of values.
|
||||
*
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function wrapArray(array $values)
|
||||
{
|
||||
return array_map(array($this, 'wrap'), $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a table in keyword identifiers.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function wrapTable($table)
|
||||
{
|
||||
if ($this->isExpression($table)) return $this->getValue($table);
|
||||
|
||||
return $this->wrap($this->tablePrefix.$table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a value in keyword identifiers.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function wrap($value)
|
||||
{
|
||||
if ($this->isExpression($value)) return $this->getValue($value);
|
||||
|
||||
// If the value being wrapped has a column alias we will need to separate out
|
||||
// the pieces so we can wrap each of the segments of the expression on it
|
||||
// own, and then joins them both back together with the "as" connector.
|
||||
if (strpos(strtolower($value), ' as ') !== false)
|
||||
{
|
||||
$segments = explode(' ', $value);
|
||||
|
||||
return $this->wrap($segments[0]).' as '.$this->wrap($segments[2]);
|
||||
}
|
||||
|
||||
$wrapped = array();
|
||||
|
||||
$segments = explode('.', $value);
|
||||
|
||||
// If the value is not an aliased table expression, we'll just wrap it like
|
||||
// normal, so if there is more than one segment, we will wrap the first
|
||||
// segments as if it was a table and the rest as just regular values.
|
||||
foreach ($segments as $key => $segment)
|
||||
{
|
||||
if ($key == 0 and count($segments) > 1)
|
||||
{
|
||||
$wrapped[] = $this->wrapTable($segment);
|
||||
}
|
||||
else
|
||||
{
|
||||
$wrapped[] = $this->wrapValue($segment);
|
||||
}
|
||||
}
|
||||
|
||||
return implode('.', $wrapped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a single string in keyword identifiers.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function wrapValue($value)
|
||||
{
|
||||
return $value !== '*' ? sprintf($this->wrapper, $value) : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an array of column names into a delimited string.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return string
|
||||
*/
|
||||
public function columnize(array $columns)
|
||||
{
|
||||
return implode(', ', array_map(array($this, 'wrap'), $columns));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create query parameter place-holders for an array.
|
||||
*
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function parameterize(array $values)
|
||||
{
|
||||
return implode(', ', array_map(array($this, 'parameter'), $values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the appropriate query parameter place-holder for a value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
public function parameter($value)
|
||||
{
|
||||
return $this->isExpression($value) ? $this->getValue($value) : '?';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a raw expression.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Expression $expression
|
||||
* @return string
|
||||
*/
|
||||
public function getValue($expression)
|
||||
{
|
||||
return $expression->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given value is a raw expression.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpression($value)
|
||||
{
|
||||
return $value instanceof Query\Expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the format for database stored dates.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateFormat()
|
||||
{
|
||||
return 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the grammar's table prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTablePrefix()
|
||||
{
|
||||
return $this->tablePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the grammar's table prefix.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return \Illuminate\Database\Grammar
|
||||
*/
|
||||
public function setTablePrefix($prefix)
|
||||
{
|
||||
$this->tablePrefix = $prefix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
207
vendor/laravel/framework/src/Illuminate/Database/MigrationServiceProvider.php
vendored
Executable file
207
vendor/laravel/framework/src/Illuminate/Database/MigrationServiceProvider.php
vendored
Executable file
@@ -0,0 +1,207 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Illuminate\Database\Migrations\MigrationCreator;
|
||||
use Illuminate\Database\Console\Migrations\MakeCommand;
|
||||
use Illuminate\Database\Console\Migrations\ResetCommand;
|
||||
use Illuminate\Database\Console\Migrations\RefreshCommand;
|
||||
use Illuminate\Database\Console\Migrations\InstallCommand;
|
||||
use Illuminate\Database\Console\Migrations\MigrateCommand;
|
||||
use Illuminate\Database\Console\Migrations\RollbackCommand;
|
||||
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
|
||||
|
||||
class MigrationServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerRepository();
|
||||
|
||||
// Once we have registered the migrator instance we will go ahead and register
|
||||
// all of the migration related commands that are used by the "Artisan" CLI
|
||||
// so that they may be easily accessed for registering with the consoles.
|
||||
$this->registerMigrator();
|
||||
|
||||
$this->registerCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the migration repository service.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerRepository()
|
||||
{
|
||||
$this->app['migration.repository'] = $this->app->share(function($app)
|
||||
{
|
||||
$table = $app['config']['database.migrations'];
|
||||
|
||||
return new DatabaseMigrationRepository($app['db'], $table);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the migrator service.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerMigrator()
|
||||
{
|
||||
// The migrator is responsible for actually running and rollback the migration
|
||||
// files in the application. We'll pass in our database connection resolver
|
||||
// so the migrator can resolve any of these connections when it needs to.
|
||||
$this->app['migrator'] = $this->app->share(function($app)
|
||||
{
|
||||
$repository = $app['migration.repository'];
|
||||
|
||||
return new Migrator($repository, $app['db'], $app['files']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the migration commands.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerCommands()
|
||||
{
|
||||
$commands = array('Migrate', 'Rollback', 'Reset', 'Refresh', 'Install', 'Make');
|
||||
|
||||
// We'll simply spin through the list of commands that are migration related
|
||||
// and register each one of them with an application container. They will
|
||||
// be resolved in the Artisan start file and registered on the console.
|
||||
foreach ($commands as $command)
|
||||
{
|
||||
$this->{'register'.$command.'Command'}();
|
||||
}
|
||||
|
||||
// Once the commands are registered in the application IoC container we will
|
||||
// register them with the Artisan start event so that these are available
|
||||
// when the Artisan application actually starts up and is getting used.
|
||||
$this->commands(
|
||||
'command.migrate', 'command.migrate.make',
|
||||
'command.migrate.install', 'command.migrate.rollback',
|
||||
'command.migrate.reset', 'command.migrate.refresh'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "migrate" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerMigrateCommand()
|
||||
{
|
||||
$this->app['command.migrate'] = $this->app->share(function($app)
|
||||
{
|
||||
$packagePath = $app['path.base'].'/vendor';
|
||||
|
||||
return new MigrateCommand($app['migrator'], $packagePath);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "rollback" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerRollbackCommand()
|
||||
{
|
||||
$this->app['command.migrate.rollback'] = $this->app->share(function($app)
|
||||
{
|
||||
return new RollbackCommand($app['migrator']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "reset" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerResetCommand()
|
||||
{
|
||||
$this->app['command.migrate.reset'] = $this->app->share(function($app)
|
||||
{
|
||||
return new ResetCommand($app['migrator']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "refresh" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerRefreshCommand()
|
||||
{
|
||||
$this->app['command.migrate.refresh'] = $this->app->share(function($app)
|
||||
{
|
||||
return new RefreshCommand;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "install" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerInstallCommand()
|
||||
{
|
||||
$this->app['command.migrate.install'] = $this->app->share(function($app)
|
||||
{
|
||||
return new InstallCommand($app['migration.repository']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "install" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerMakeCommand()
|
||||
{
|
||||
$this->app['migration.creator'] = $this->app->share(function($app)
|
||||
{
|
||||
return new MigrationCreator($app['files']);
|
||||
});
|
||||
|
||||
$this->app['command.migrate.make'] = $this->app->share(function($app)
|
||||
{
|
||||
// Once we have the migration creator registered, we will create the command
|
||||
// and inject the creator. The creator is responsible for the actual file
|
||||
// creation of the migrations, and may be extended by these developers.
|
||||
$creator = $app['migration.creator'];
|
||||
|
||||
$packagePath = $app['path.base'].'/vendor';
|
||||
|
||||
return new MakeCommand($creator, $packagePath);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array(
|
||||
'migrator', 'migration.repository', 'command.migrate',
|
||||
'command.migrate.rollback', 'command.migrate.reset',
|
||||
'command.migrate.refresh', 'command.migrate.install',
|
||||
'migration.creator', 'command.migrate.make',
|
||||
);
|
||||
}
|
||||
|
||||
}
|
182
vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php
vendored
Executable file
182
vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php
vendored
Executable file
@@ -0,0 +1,182 @@
|
||||
<?php namespace Illuminate\Database\Migrations;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\ConnectionResolverInterface as Resolver;
|
||||
|
||||
class DatabaseMigrationRepository implements MigrationRepositoryInterface {
|
||||
|
||||
/**
|
||||
* The database connection resolver instance.
|
||||
*
|
||||
* @var \Illuminate\Database\ConnectionResolverInterface
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
/**
|
||||
* The name of the migration table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* The name of the database connection to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Create a new database migration repository instance.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionResolverInterface $resolver
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Resolver $resolver, $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ran migrations.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRan()
|
||||
{
|
||||
return $this->table()->lists('migration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last migration batch.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLast()
|
||||
{
|
||||
$query = $this->table()->where('batch', $this->getLastBatchNumber());
|
||||
|
||||
return $query->orderBy('migration', 'desc')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log that a migration was run.
|
||||
*
|
||||
* @param string $file
|
||||
* @param int $batch
|
||||
* @return void
|
||||
*/
|
||||
public function log($file, $batch)
|
||||
{
|
||||
$record = array('migration' => $file, 'batch' => $batch);
|
||||
|
||||
$this->table()->insert($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a migration from the log.
|
||||
*
|
||||
* @param \StdClass $migration
|
||||
* @return void
|
||||
*/
|
||||
public function delete($migration)
|
||||
{
|
||||
$query = $this->table()->where('migration', $migration->migration)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next migration batch number.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNextBatchNumber()
|
||||
{
|
||||
return $this->getLastBatchNumber() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last migration batch number.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLastBatchNumber()
|
||||
{
|
||||
return $this->table()->max('batch');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the migration repository data store.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createRepository()
|
||||
{
|
||||
$schema = $this->getConnection()->getSchemaBuilder();
|
||||
|
||||
$schema->create($this->table, function($table)
|
||||
{
|
||||
// The migrations table is responsible for keeping track of which of the
|
||||
// migrations have actually run for the application. We'll create the
|
||||
// table to hold the migration file's path as well as the batch ID.
|
||||
$table->string('migration');
|
||||
|
||||
$table->integer('batch');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the migration repository exists.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function repositoryExists()
|
||||
{
|
||||
$schema = $this->getConnection()->getSchemaBuilder();
|
||||
|
||||
return $schema->hasTable($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a query builder for the migration table.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected function table()
|
||||
{
|
||||
return $this->getConnection()->table($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connection resolver instance.
|
||||
*
|
||||
* @return \Illuminate\Database\ConnectionResolverInterface
|
||||
*/
|
||||
public function getConnectionResolver()
|
||||
{
|
||||
return $this->resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the database connection instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->resolver->connection($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the information source to gather data.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setSource($name)
|
||||
{
|
||||
$this->connection = $name;
|
||||
}
|
||||
|
||||
}
|
22
vendor/laravel/framework/src/Illuminate/Database/Migrations/Migration.php
vendored
Executable file
22
vendor/laravel/framework/src/Illuminate/Database/Migrations/Migration.php
vendored
Executable file
@@ -0,0 +1,22 @@
|
||||
<?php namespace Illuminate\Database\Migrations;
|
||||
|
||||
abstract class Migration {
|
||||
|
||||
/**
|
||||
* The name of the database connection to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Get the migration connection name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
}
|
171
vendor/laravel/framework/src/Illuminate/Database/Migrations/MigrationCreator.php
vendored
Executable file
171
vendor/laravel/framework/src/Illuminate/Database/Migrations/MigrationCreator.php
vendored
Executable file
@@ -0,0 +1,171 @@
|
||||
<?php namespace Illuminate\Database\Migrations;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class MigrationCreator {
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The registered post create hooks.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $postCreate = array();
|
||||
|
||||
/**
|
||||
* Create a new migration creator instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files)
|
||||
{
|
||||
$this->files = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new migration at the given path.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $path
|
||||
* @param string $table
|
||||
* @param bool $create
|
||||
* @return string
|
||||
*/
|
||||
public function create($name, $path, $table = null, $create = false)
|
||||
{
|
||||
$path = $this->getPath($name, $path);
|
||||
|
||||
// First we will get the stub file for the migration, which serves as a type
|
||||
// of template for the migration. Once we have those we will populate the
|
||||
// various place-holders, save the file, and run the post create event.
|
||||
$stub = $this->getStub($table, $create);
|
||||
|
||||
$this->files->put($path, $this->populateStub($name, $stub, $table));
|
||||
|
||||
$this->firePostCreateHooks();
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the migration stub file.
|
||||
*
|
||||
* @param string $table
|
||||
* @return void
|
||||
*/
|
||||
protected function getStub($table, $create)
|
||||
{
|
||||
if (is_null($table))
|
||||
{
|
||||
return $this->files->get($this->getStubPath().'/blank.stub');
|
||||
}
|
||||
|
||||
// We also have stubs for creating new tables and modifying existing tables
|
||||
// to save the developer some typing when they are creating a new tables
|
||||
// or modifying existing tables. We'll grab the appropriate stub here.
|
||||
else
|
||||
{
|
||||
$stub = $create ? 'create.stub' : 'update.stub';
|
||||
|
||||
return $this->files->get($this->getStubPath()."/{$stub}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the place-holders in the migration stub.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $stub
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function populateStub($name, $stub, $table)
|
||||
{
|
||||
$stub = str_replace('{{class}}', studly_case($name), $stub);
|
||||
|
||||
// Here we will replace the table place-holders with the table specified by
|
||||
// the developer, which is useful for quickly creating a tables creation
|
||||
// or update migration from the console instead of typing it manually.
|
||||
if ( ! is_null($table))
|
||||
{
|
||||
$stub = str_replace('{{table}}', $table, $stub);
|
||||
}
|
||||
|
||||
return $stub;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the registered post create hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function firePostCreateHooks()
|
||||
{
|
||||
foreach ($this->postCreate as $callback)
|
||||
{
|
||||
call_user_func($callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a post migration create hook.
|
||||
*
|
||||
* @param Closure $callback
|
||||
* @return void
|
||||
*/
|
||||
public function afterCreate(Closure $callback)
|
||||
{
|
||||
$this->postCreate[] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path name to the migration.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function getPath($name, $path)
|
||||
{
|
||||
return $path.'/'.$this->getDatePrefix().'_'.$name.'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date prefix for the migration.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getDatePrefix()
|
||||
{
|
||||
return date('Y_m_d_His');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the stubs.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStubPath()
|
||||
{
|
||||
return __DIR__.'/stubs';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filesystem instance.
|
||||
*
|
||||
* @return \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
public function getFilesystem()
|
||||
{
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
}
|
65
vendor/laravel/framework/src/Illuminate/Database/Migrations/MigrationRepositoryInterface.php
vendored
Executable file
65
vendor/laravel/framework/src/Illuminate/Database/Migrations/MigrationRepositoryInterface.php
vendored
Executable file
@@ -0,0 +1,65 @@
|
||||
<?php namespace Illuminate\Database\Migrations;
|
||||
|
||||
interface MigrationRepositoryInterface {
|
||||
|
||||
/**
|
||||
* Get the ran migrations for a given package.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRan();
|
||||
|
||||
/**
|
||||
* Get the last migration batch.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLast();
|
||||
|
||||
/**
|
||||
* Log that a migration was run.
|
||||
*
|
||||
* @param string $file
|
||||
* @param int $batch
|
||||
* @return void
|
||||
*/
|
||||
public function log($file, $batch);
|
||||
|
||||
/**
|
||||
* Remove a migration from the log.
|
||||
*
|
||||
* @param \StdClass $migration
|
||||
* @return void
|
||||
*/
|
||||
public function delete($migration);
|
||||
|
||||
/**
|
||||
* Get the next migration batch number.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNextBatchNumber();
|
||||
|
||||
/**
|
||||
* Create the migration repository data store.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createRepository();
|
||||
|
||||
/**
|
||||
* Determine if the migration repository exists.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function repositoryExists();
|
||||
|
||||
/**
|
||||
* Set the information source to gather data.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setSource($name);
|
||||
|
||||
}
|
383
vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php
vendored
Executable file
383
vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php
vendored
Executable file
@@ -0,0 +1,383 @@
|
||||
<?php namespace Illuminate\Database\Migrations;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Illuminate\Database\ConnectionResolverInterface as Resolver;
|
||||
|
||||
class Migrator {
|
||||
|
||||
/**
|
||||
* The migration repository implementation.
|
||||
*
|
||||
* @var \Illuminate\Database\Migrations\MigrationRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The connection resolver instance.
|
||||
*
|
||||
* @var \Illuminate\Database\ConnectionResolverInterface
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
/**
|
||||
* The name of the default connection.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The notes for the current operation.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $notes = array();
|
||||
|
||||
/**
|
||||
* Create a new migrator instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Migrations\MigrationRepositoryInterface $repository
|
||||
* @param \Illuminate\Database\ConnectionResolverInterface $resolver
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MigrationRepositoryInterface $repository,
|
||||
Resolver $resolver,
|
||||
Filesystem $files)
|
||||
{
|
||||
$this->files = $files;
|
||||
$this->resolver = $resolver;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the outstanding migrations at a given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool $pretend
|
||||
* @return void
|
||||
*/
|
||||
public function run($path, $pretend = false)
|
||||
{
|
||||
$this->notes = array();
|
||||
|
||||
$this->requireFiles($path, $files = $this->getMigrationFiles($path));
|
||||
|
||||
// Once we grab all of the migration files for the path, we will compare them
|
||||
// against the migrations that have already been run for this package then
|
||||
// run all of the oustanding migrations against the database connection.
|
||||
$ran = $this->repository->getRan();
|
||||
|
||||
$migrations = array_diff($files, $ran);
|
||||
|
||||
$this->runMigrationList($migrations, $pretend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an array of migrations.
|
||||
*
|
||||
* @param array $migrations
|
||||
* @param bool $pretend
|
||||
* @return void
|
||||
*/
|
||||
public function runMigrationList($migrations, $pretend = false)
|
||||
{
|
||||
// First we will just make sure that there are any migrations to run. If there
|
||||
// aren't, we will just make a note of it to the developer so they're aware
|
||||
// that all of the migrations have been run against this database system.
|
||||
if (count($migrations) == 0)
|
||||
{
|
||||
$this->note('<info>Nothing to migrate.</info>');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$batch = $this->repository->getNextBatchNumber();
|
||||
|
||||
// Once we have the array of migrations, we will spin through them and run the
|
||||
// migrations "up" so the changes are made to the databases. We'll then log
|
||||
// that the migration was run so we don't repeat it next time we execute.
|
||||
foreach ($migrations as $file)
|
||||
{
|
||||
$this->runUp($file, $batch, $pretend);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run "up" a migration instance.
|
||||
*
|
||||
* @param string $file
|
||||
* @param int $batch
|
||||
* @param bool $pretend
|
||||
* @return void
|
||||
*/
|
||||
protected function runUp($file, $batch, $pretend)
|
||||
{
|
||||
// First we will resolve a "real" instance of the migration class from this
|
||||
// migration file name. Once we have the instances we can run the actual
|
||||
// command such as "up" or "down", or we can just simulate the action.
|
||||
$migration = $this->resolve($file);
|
||||
|
||||
if ($pretend)
|
||||
{
|
||||
return $this->pretendToRun($migration, 'up');
|
||||
}
|
||||
|
||||
$migration->up();
|
||||
|
||||
// Once we have run a migrations class, we will log that it was run in this
|
||||
// repository so that we don't try to run it next time we do a migration
|
||||
// in the application. A migration repository keeps the migrate order.
|
||||
$this->repository->log($file, $batch);
|
||||
|
||||
$this->note("<info>Migrated:</info> $file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback the last migration operation.
|
||||
*
|
||||
* @param bool $pretend
|
||||
* @return int
|
||||
*/
|
||||
public function rollback($pretend = false)
|
||||
{
|
||||
$this->notes = array();
|
||||
|
||||
// We want to pull in the last batch of migrations that ran on the previous
|
||||
// migration operation. We'll then reverse those migrations and run each
|
||||
// of them "down" to reverse the last migration "operation" which ran.
|
||||
$migrations = $this->repository->getLast();
|
||||
|
||||
if (count($migrations) == 0)
|
||||
{
|
||||
$this->note('<info>Nothing to rollback.</info>');
|
||||
|
||||
return count($migrations);
|
||||
}
|
||||
|
||||
// We need to reverse these migrations so that they are "downed" in reverse
|
||||
// to what they run on "up". It lets us backtrack through the migrations
|
||||
// and properly reverse the entire database schema operation that ran.
|
||||
foreach ($migrations as $migration)
|
||||
{
|
||||
$this->runDown((object) $migration, $pretend);
|
||||
}
|
||||
|
||||
return count($migrations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run "down" a migration instance.
|
||||
*
|
||||
* @param \StdClass $migration
|
||||
* @param bool $pretend
|
||||
* @return void
|
||||
*/
|
||||
protected function runDown($migration, $pretend)
|
||||
{
|
||||
$file = $migration->migration;
|
||||
|
||||
// First we will get the file name of the migration so we can resolve out an
|
||||
// instance of the migration. Once we get an instance we can either run a
|
||||
// pretend execution of the migration or we can run the real migration.
|
||||
$instance = $this->resolve($file);
|
||||
|
||||
if ($pretend)
|
||||
{
|
||||
return $this->pretendToRun($instance, 'down');
|
||||
}
|
||||
|
||||
$instance->down();
|
||||
|
||||
// Once we have successfully run the migration "down" we will remove it from
|
||||
// the migration repository so it will be considered to have not been run
|
||||
// by the application then will be able to fire by any later operation.
|
||||
$this->repository->delete($migration);
|
||||
|
||||
$this->note("<info>Rolled back:</info> $file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the migration files in a given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return array
|
||||
*/
|
||||
public function getMigrationFiles($path)
|
||||
{
|
||||
$files = $this->files->glob($path.'/*_*.php');
|
||||
|
||||
// Once we have the array of files in the directory we will just remove the
|
||||
// extension and take the basename of the file which is all we need when
|
||||
// finding the migrations that haven't been run against the databases.
|
||||
if ($files === false) return array();
|
||||
|
||||
$files = array_map(function($file)
|
||||
{
|
||||
return str_replace('.php', '', basename($file));
|
||||
|
||||
}, $files);
|
||||
|
||||
// Once we have all of the formatted file names we will sort them and since
|
||||
// they all start with a timestamp this should give us the migrations in
|
||||
// the order they were actually created by the application developers.
|
||||
sort($files);
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Require in all the migration files in a given path.
|
||||
*
|
||||
* @param array $files
|
||||
* @return void
|
||||
*/
|
||||
public function requireFiles($path, array $files)
|
||||
{
|
||||
foreach ($files as $file) $this->files->requireOnce($path.'/'.$file.'.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Pretend to run the migrations.
|
||||
*
|
||||
* @param object $migration
|
||||
* @return void
|
||||
*/
|
||||
protected function pretendToRun($migration, $method)
|
||||
{
|
||||
foreach ($this->getQueries($migration, $method) as $query)
|
||||
{
|
||||
$name = get_class($migration);
|
||||
|
||||
$this->note("<info>{$name}:</info> {$query['query']}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the queries that would be run for a migration.
|
||||
*
|
||||
* @param object $migration
|
||||
* @param string $method
|
||||
* @return array
|
||||
*/
|
||||
protected function getQueries($migration, $method)
|
||||
{
|
||||
$connection = $migration->getConnection();
|
||||
|
||||
// Now that we have the connections we can resolve it and pretend to run the
|
||||
// queries against the database returning the array of raw SQL statements
|
||||
// that would get fired against the database system for this migration.
|
||||
$db = $this->resolveConnection($connection);
|
||||
|
||||
return $db->pretend(function() use ($migration, $method)
|
||||
{
|
||||
$migration->$method();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a migration instance from a file.
|
||||
*
|
||||
* @param string $file
|
||||
* @return object
|
||||
*/
|
||||
public function resolve($file)
|
||||
{
|
||||
$file = implode('_', array_slice(explode('_', $file), 4));
|
||||
|
||||
$class = studly_case($file);
|
||||
|
||||
return new $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise a note event for the migrator.
|
||||
*
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
protected function note($message)
|
||||
{
|
||||
$this->notes[] = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notes for the last operation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNotes()
|
||||
{
|
||||
return $this->notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the database connection instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function resolveConnection()
|
||||
{
|
||||
return $this->resolver->connection($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default connection name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setConnection($name)
|
||||
{
|
||||
if ( ! is_null($name))
|
||||
{
|
||||
$this->resolver->setDefaultConnection($name);
|
||||
}
|
||||
|
||||
$this->repository->setSource($name);
|
||||
|
||||
$this->connection = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the migration repository instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Migrations\MigrationRepositoryInterface
|
||||
*/
|
||||
public function getRepository()
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the migration repository exists.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function repositoryExists()
|
||||
{
|
||||
return $this->repository->repositoryExists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file system instance.
|
||||
*
|
||||
* @return \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
public function getFilesystem()
|
||||
{
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
}
|
27
vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs/blank.stub
vendored
Normal file
27
vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs/blank.stub
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class {{class}} extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
}
|
32
vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs/create.stub
vendored
Normal file
32
vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs/create.stub
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class {{class}} extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('{{table}}', function(Blueprint $table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('{{table}}');
|
||||
}
|
||||
|
||||
}
|
34
vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs/update.stub
vendored
Normal file
34
vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs/update.stub
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class {{class}} extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('{{table}}', function(Blueprint $table)
|
||||
{
|
||||
//
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('{{table}}', function(Blueprint $table)
|
||||
{
|
||||
//
|
||||
});
|
||||
}
|
||||
|
||||
}
|
47
vendor/laravel/framework/src/Illuminate/Database/MySqlConnection.php
vendored
Executable file
47
vendor/laravel/framework/src/Illuminate/Database/MySqlConnection.php
vendored
Executable file
@@ -0,0 +1,47 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
class MySqlConnection extends Connection {
|
||||
|
||||
/**
|
||||
* Get a schema builder instance for the connection.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Builder
|
||||
*/
|
||||
public function getSchemaBuilder()
|
||||
{
|
||||
if (is_null($this->schemaGrammar)) { $this->useDefaultSchemaGrammar(); }
|
||||
|
||||
return new Schema\MySqlBuilder($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default query grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new Query\Grammars\MySqlGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default schema grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new Schema\Grammars\MySqlGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL Driver.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Driver
|
||||
*/
|
||||
protected function getDoctrineDriver()
|
||||
{
|
||||
return new \Doctrine\DBAL\Driver\PDOMySql\Driver;
|
||||
}
|
||||
|
||||
}
|
45
vendor/laravel/framework/src/Illuminate/Database/PostgresConnection.php
vendored
Executable file
45
vendor/laravel/framework/src/Illuminate/Database/PostgresConnection.php
vendored
Executable file
@@ -0,0 +1,45 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
class PostgresConnection extends Connection {
|
||||
|
||||
/**
|
||||
* Get the default query grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new Query\Grammars\PostgresGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default schema grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new Schema\Grammars\PostgresGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default post processor instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Processors\Processor
|
||||
*/
|
||||
protected function getDefaultPostProcessor()
|
||||
{
|
||||
return new Query\Processors\PostgresProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL Driver.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Driver
|
||||
*/
|
||||
protected function getDoctrineDriver()
|
||||
{
|
||||
return new \Doctrine\DBAL\Driver\PDOPgSql\Driver;
|
||||
}
|
||||
|
||||
}
|
1595
vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php
vendored
Executable file
1595
vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php
vendored
Executable file
File diff suppressed because it is too large
Load Diff
43
vendor/laravel/framework/src/Illuminate/Database/Query/Expression.php
vendored
Executable file
43
vendor/laravel/framework/src/Illuminate/Database/Query/Expression.php
vendored
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php namespace Illuminate\Database\Query;
|
||||
|
||||
class Expression {
|
||||
|
||||
/**
|
||||
* The value of the expression.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Create a new raw query expression.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the expression.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the expression.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return (string) $this->getValue();
|
||||
}
|
||||
|
||||
}
|
654
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php
vendored
Executable file
654
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php
vendored
Executable file
@@ -0,0 +1,654 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Database\Grammar as BaseGrammar;
|
||||
|
||||
class Grammar extends BaseGrammar {
|
||||
|
||||
/**
|
||||
* The keyword identifier wrapper format.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $wrapper = '"%s"';
|
||||
|
||||
/**
|
||||
* The components that make up a select clause.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $selectComponents = array(
|
||||
'aggregate',
|
||||
'columns',
|
||||
'from',
|
||||
'joins',
|
||||
'wheres',
|
||||
'groups',
|
||||
'havings',
|
||||
'orders',
|
||||
'limit',
|
||||
'offset',
|
||||
'unions',
|
||||
);
|
||||
|
||||
/**
|
||||
* Compile a select query into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder
|
||||
* @return string
|
||||
*/
|
||||
public function compileSelect(Builder $query)
|
||||
{
|
||||
if (is_null($query->columns)) $query->columns = array('*');
|
||||
|
||||
return trim($this->concatenate($this->compileComponents($query)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the components necessary for a select clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder
|
||||
* @return array
|
||||
*/
|
||||
protected function compileComponents(Builder $query)
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
foreach ($this->selectComponents as $component)
|
||||
{
|
||||
// To compile the query, we'll spin through each component of the query and
|
||||
// see if that component exists. If it does we'll just call the compiler
|
||||
// function for the component which is responsible for making the SQL.
|
||||
if ( ! is_null($query->$component))
|
||||
{
|
||||
$method = 'compile'.ucfirst($component);
|
||||
|
||||
$sql[$component] = $this->$method($query, $query->$component);
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an aggregated select clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $aggregate
|
||||
* @return string
|
||||
*/
|
||||
protected function compileAggregate(Builder $query, $aggregate)
|
||||
{
|
||||
$column = $this->columnize($aggregate['columns']);
|
||||
|
||||
// If the query has a "distinct" constraint and we're not asking for all columns
|
||||
// we need to prepend "distinct" onto the column name so that the query takes
|
||||
// it into account when it performs the aggregating operations on the data.
|
||||
if ($query->distinct and $column !== '*')
|
||||
{
|
||||
$column = 'distinct '.$column;
|
||||
}
|
||||
|
||||
return 'select '.$aggregate['function'].'('.$column.') as aggregate';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "select *" portion of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $columns
|
||||
* @return string
|
||||
*/
|
||||
protected function compileColumns(Builder $query, $columns)
|
||||
{
|
||||
// If the query is actually performing an aggregating select, we will let that
|
||||
// compiler handle the building of the select clauses, as it will need some
|
||||
// more syntax that is best handled by that function to keep things neat.
|
||||
if ( ! is_null($query->aggregate)) return;
|
||||
|
||||
$select = $query->distinct ? 'select distinct ' : 'select ';
|
||||
|
||||
return $select.$this->columnize($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "from" portion of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function compileFrom(Builder $query, $table)
|
||||
{
|
||||
return 'from '.$this->wrapTable($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "join" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $joins
|
||||
* @return string
|
||||
*/
|
||||
protected function compileJoins(Builder $query, $joins)
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
foreach ($joins as $join)
|
||||
{
|
||||
$table = $this->wrapTable($join->table);
|
||||
|
||||
// First we need to build all of the "on" clauses for the join. There may be many
|
||||
// of these clauses so we will need to iterate through each one and build them
|
||||
// separately, then we'll join them up into a single string when we're done.
|
||||
$clauses = array();
|
||||
|
||||
foreach ($join->clauses as $clause)
|
||||
{
|
||||
$clauses[] = $this->compileJoinConstraint($clause);
|
||||
}
|
||||
|
||||
// Once we have constructed the clauses, we'll need to take the boolean connector
|
||||
// off of the first clause as it obviously will not be required on that clause
|
||||
// because it leads the rest of the clauses, thus not requiring any boolean.
|
||||
$clauses[0] = $this->removeLeadingBoolean($clauses[0]);
|
||||
|
||||
$clauses = implode(' ', $clauses);
|
||||
|
||||
$type = $join->type;
|
||||
|
||||
// Once we have everything ready to go, we will just concatenate all the parts to
|
||||
// build the final join statement SQL for the query and we can then return the
|
||||
// final clause back to the callers as a single, stringified join statement.
|
||||
$sql[] = "$type join $table on $clauses";
|
||||
}
|
||||
|
||||
return implode(' ', $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a join clause constraint segment.
|
||||
*
|
||||
* @param array $clause
|
||||
* @return string
|
||||
*/
|
||||
protected function compileJoinConstraint(array $clause)
|
||||
{
|
||||
$first = $this->wrap($clause['first']);
|
||||
|
||||
$second = $this->wrap($clause['second']);
|
||||
|
||||
return "{$clause['boolean']} $first {$clause['operator']} $second";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "where" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
protected function compileWheres(Builder $query)
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
if (is_null($query->wheres)) return '';
|
||||
|
||||
// Each type of where clauses has its own compiler function which is responsible
|
||||
// for actually creating the where clauses SQL. This helps keep the code nice
|
||||
// and maintainable since each clause has a very small method that it uses.
|
||||
foreach ($query->wheres as $where)
|
||||
{
|
||||
$method = "where{$where['type']}";
|
||||
|
||||
$sql[] = $where['boolean'].' '.$this->$method($query, $where);
|
||||
}
|
||||
|
||||
// If we actually have some where clauses, we will strip off the first boolean
|
||||
// operator, which is added by the query builders for convenience so we can
|
||||
// avoid checking for the first clauses in each of the compilers methods.
|
||||
if (count($sql) > 0)
|
||||
{
|
||||
$sql = implode(' ', $sql);
|
||||
|
||||
return 'where '.preg_replace('/and |or /', '', $sql, 1);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a nested where clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNested(Builder $query, $where)
|
||||
{
|
||||
$nested = $where['query'];
|
||||
|
||||
return '('.substr($this->compileWheres($nested), 6).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a where condition with a sub-select.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereSub(Builder $query, $where)
|
||||
{
|
||||
$select = $this->compileSelect($where['query']);
|
||||
|
||||
return $this->wrap($where['column']).' '.$where['operator']." ($select)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a basic where clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereBasic(Builder $query, $where)
|
||||
{
|
||||
$value = $this->parameter($where['value']);
|
||||
|
||||
return $this->wrap($where['column']).' '.$where['operator'].' '.$value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "between" where clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereBetween(Builder $query, $where)
|
||||
{
|
||||
return $this->wrap($where['column']).' between ? and ?';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a where exists clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereExists(Builder $query, $where)
|
||||
{
|
||||
return 'exists ('.$this->compileSelect($where['query']).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a where exists clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNotExists(Builder $query, $where)
|
||||
{
|
||||
return 'not exists ('.$this->compileSelect($where['query']).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where in" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereIn(Builder $query, $where)
|
||||
{
|
||||
$values = $this->parameterize($where['values']);
|
||||
|
||||
return $this->wrap($where['column']).' in ('.$values.')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where not in" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNotIn(Builder $query, $where)
|
||||
{
|
||||
$values = $this->parameterize($where['values']);
|
||||
|
||||
return $this->wrap($where['column']).' not in ('.$values.')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a where in sub-select clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereInSub(Builder $query, $where)
|
||||
{
|
||||
$select = $this->compileSelect($where['query']);
|
||||
|
||||
return $this->wrap($where['column']).' in ('.$select.')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a where not in sub-select clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNotInSub(Builder $query, $where)
|
||||
{
|
||||
$select = $this->compileSelect($where['query']);
|
||||
|
||||
return $this->wrap($where['column']).' not in ('.$select.')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where null" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNull(Builder $query, $where)
|
||||
{
|
||||
return $this->wrap($where['column']).' is null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where not null" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNotNull(Builder $query, $where)
|
||||
{
|
||||
return $this->wrap($where['column']).' is not null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a raw where clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereRaw(Builder $query, $where)
|
||||
{
|
||||
return $where['sql'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "group by" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $groups
|
||||
* @return string
|
||||
*/
|
||||
protected function compileGroups(Builder $query, $groups)
|
||||
{
|
||||
return 'group by '.$this->columnize($groups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "having" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $havings
|
||||
* @return string
|
||||
*/
|
||||
protected function compileHavings(Builder $query, $havings)
|
||||
{
|
||||
$me = $this;
|
||||
|
||||
$sql = implode(' ', array_map(array($this, 'compileHaving'), $havings));
|
||||
|
||||
return 'having '.preg_replace('/and /', '', $sql, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a single having clause.
|
||||
*
|
||||
* @param array $having
|
||||
* @return string
|
||||
*/
|
||||
protected function compileHaving(array $having)
|
||||
{
|
||||
// If the having clause is "raw", we can just return the clause straight away
|
||||
// without doing any more processing on it. Otherwise, we will compile the
|
||||
// clause into SQL based on the components that make it up from builder.
|
||||
if ($having['type'] === 'raw')
|
||||
{
|
||||
return $having['boolean'].' '.$having['sql'];
|
||||
}
|
||||
|
||||
return $this->compileBasicHaving($having);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a basic having clause.
|
||||
*
|
||||
* @param array $having
|
||||
* @return string
|
||||
*/
|
||||
protected function compileBasicHaving($having)
|
||||
{
|
||||
$column = $this->wrap($having['column']);
|
||||
|
||||
$parameter = $this->parameter($having['value']);
|
||||
|
||||
return 'and '.$column.' '.$having['operator'].' '.$parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "order by" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $orders
|
||||
* @return string
|
||||
*/
|
||||
protected function compileOrders(Builder $query, $orders)
|
||||
{
|
||||
$me = $this;
|
||||
|
||||
return 'order by '.implode(', ', array_map(function($order) use ($me)
|
||||
{
|
||||
return $me->wrap($order['column']).' '.$order['direction'];
|
||||
}
|
||||
, $orders));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "limit" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param int $limit
|
||||
* @return string
|
||||
*/
|
||||
protected function compileLimit(Builder $query, $limit)
|
||||
{
|
||||
return "limit $limit";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "offset" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param int $offset
|
||||
* @return string
|
||||
*/
|
||||
protected function compileOffset(Builder $query, $offset)
|
||||
{
|
||||
return "offset $offset";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "union" queries attached to the main query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUnions(Builder $query)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
foreach ($query->unions as $union)
|
||||
{
|
||||
$joiner = $union['all'] ? 'union all ' : 'union ';
|
||||
|
||||
$sql = $joiner.$union['query']->toSql();
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an insert statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function compileInsert(Builder $query, array $values)
|
||||
{
|
||||
// Essentially we will force every insert to be treated as a batch insert which
|
||||
// simply makes creating the SQL easier for us since we can utilize the same
|
||||
// basic routine regardless of an amount of records given to us to insert.
|
||||
$table = $this->wrapTable($query->from);
|
||||
|
||||
if ( ! is_array(reset($values)))
|
||||
{
|
||||
$values = array($values);
|
||||
}
|
||||
|
||||
$columns = $this->columnize(array_keys(reset($values)));
|
||||
|
||||
// We need to build a list of parameter place-holders of values that are bound
|
||||
// to the query. Each insert should have the exact same amount of parameter
|
||||
// bindings so we can just go off the first list of values in this array.
|
||||
$parameters = $this->parameterize(reset($values));
|
||||
|
||||
$value = array_fill(0, count($values), "($parameters)");
|
||||
|
||||
$parameters = implode(', ', $value);
|
||||
|
||||
return "insert into $table ($columns) values $parameters";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an insert and get ID statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @param string $sequence
|
||||
* @return string
|
||||
*/
|
||||
public function compileInsertGetId(Builder $query, $values, $sequence)
|
||||
{
|
||||
return $this->compileInsert($query, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an update statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function compileUpdate(Builder $query, $values)
|
||||
{
|
||||
$table = $this->wrapTable($query->from);
|
||||
|
||||
// Each one of the columns in the update statements needs to be wrapped in the
|
||||
// keyword identifiers, also a place-holder needs to be created for each of
|
||||
// the values in the list of bindings so we can make the sets statements.
|
||||
$columns = array();
|
||||
|
||||
foreach ($values as $key => $value)
|
||||
{
|
||||
$columns[] = $this->wrap($key).' = '.$this->parameter($value);
|
||||
}
|
||||
|
||||
$columns = implode(', ', $columns);
|
||||
|
||||
// If the query has any "join" clauses, we will setup the joins on the builder
|
||||
// and compile them so we can attach them to this update, as update queries
|
||||
// can get join statements to attach to other tables when they're needed.
|
||||
if (isset($query->joins))
|
||||
{
|
||||
$joins = ' '.$this->compileJoins($query, $query->joins);
|
||||
}
|
||||
else
|
||||
{
|
||||
$joins = '';
|
||||
}
|
||||
|
||||
// Of course, update queries may also be constrained by where clauses so we'll
|
||||
// need to compile the where clauses and attach it to the query so only the
|
||||
// intended records are updated by the SQL statements we generate to run.
|
||||
$where = $this->compileWheres($query);
|
||||
|
||||
return trim("update {$table}{$joins} set $columns $where");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a delete statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function compileDelete(Builder $query)
|
||||
{
|
||||
$table = $this->wrapTable($query->from);
|
||||
|
||||
$where = is_array($query->wheres) ? $this->compileWheres($query) : '';
|
||||
|
||||
return trim("delete from $table ".$where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a truncate table statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return array
|
||||
*/
|
||||
public function compileTruncate(Builder $query)
|
||||
{
|
||||
return array('truncate '.$this->wrapTable($query->from) => array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate an array of segments, removing empties.
|
||||
*
|
||||
* @param array $segments
|
||||
* @return string
|
||||
*/
|
||||
protected function concatenate($segments)
|
||||
{
|
||||
return implode(' ', array_filter($segments, function($value)
|
||||
{
|
||||
return (string) $value !== '';
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the leading boolean from a statement.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function removeLeadingBoolean($value)
|
||||
{
|
||||
return preg_replace('/and |or /', '', $value, 1);
|
||||
}
|
||||
|
||||
}
|
12
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
vendored
Executable file
12
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
class MySqlGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The keyword identifier wrapper format.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $wrapper = '`%s`';
|
||||
|
||||
}
|
151
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
vendored
Executable file
151
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
vendored
Executable file
@@ -0,0 +1,151 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class PostgresGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* Compile an update statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function compileUpdate(Builder $query, $values)
|
||||
{
|
||||
$table = $this->wrapTable($query->from);
|
||||
|
||||
// Each one of the columns in the update statements needs to be wrapped in the
|
||||
// keyword identifiers, also a place-holder needs to be created for each of
|
||||
// the values in the list of bindings so we can make the sets statements.
|
||||
$columns = $this->compileUpdateColumns($values);
|
||||
|
||||
$from = $this->compileUpdateFrom($query);
|
||||
|
||||
$where = $this->compileUpdateWheres($query);
|
||||
|
||||
return trim("update {$table} set {$columns}{$from} $where");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the columns for the update statement.
|
||||
*
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUpdateColumns($values)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
// When gathering the columns for an update statement, we'll wrap each of the
|
||||
// columns and convert it to a parameter value. Then we will concatenate a
|
||||
// list of the columns that can be added into this update query clauses.
|
||||
foreach ($values as $key => $value)
|
||||
{
|
||||
$columns[] = $this->wrap($key).' = '.$this->parameter($value);
|
||||
}
|
||||
|
||||
return implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "from" clause for an update with a join.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUpdateFrom(Builder $query)
|
||||
{
|
||||
if ( ! isset($query->joins)) return '';
|
||||
|
||||
$froms = array();
|
||||
|
||||
// When using Postgres, updates with joins list the joined tables in the from
|
||||
// clause, which is different than other systems like MySQL. Here, we will
|
||||
// compile out the tables that are joined and add them to a from clause.
|
||||
foreach ($query->joins as $join)
|
||||
{
|
||||
$froms[] = $this->wrapTable($join->table);
|
||||
}
|
||||
|
||||
if (count($froms) > 0) return ' from '.implode(', ', $froms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the additional where clauses for updates with joins.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUpdateWheres(Builder $query)
|
||||
{
|
||||
$baseWhere = $this->compileWheres($query);
|
||||
|
||||
if ( ! isset($query->joins)) return $baseWhere;
|
||||
|
||||
// Once we compile the join constraints, we will either use them as the where
|
||||
// clause or append them to the existing base where clauses. If we need to
|
||||
// strip the leading boolean we will do so when using as the only where.
|
||||
$joinWhere = $this->compileUpdateJoinWheres($query);
|
||||
|
||||
if (trim($baseWhere) == '')
|
||||
{
|
||||
return 'where '.$this->removeLeadingBoolean($joinWhere);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $baseWhere.' '.$joinWhere;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "join" clauses for an update.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUpdateJoinWheres(Builder $query)
|
||||
{
|
||||
$joinWheres = array();
|
||||
|
||||
// Here we will just loop through all of the join constraints and compile them
|
||||
// all out then implode them. This should give us "where" like syntax after
|
||||
// everything has been built and then we will join it to the real wheres.
|
||||
foreach ($query->joins as $join)
|
||||
{
|
||||
foreach ($join->clauses as $clause)
|
||||
{
|
||||
$joinWheres[] = $this->compileJoinConstraint($clause);
|
||||
}
|
||||
}
|
||||
|
||||
return implode(' ', $joinWheres);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an insert and get ID statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @param string $sequence
|
||||
* @return string
|
||||
*/
|
||||
public function compileInsertGetId(Builder $query, $values, $sequence)
|
||||
{
|
||||
if (is_null($sequence)) $sequence = 'id';
|
||||
|
||||
return $this->compileInsert($query, $values).' returning '.$this->wrap($sequence);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a truncate table statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return array
|
||||
*/
|
||||
public function compileTruncate(Builder $query)
|
||||
{
|
||||
return array('truncate '.$this->wrapTable($query->from).' restart identity' => array());
|
||||
}
|
||||
|
||||
}
|
84
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php
vendored
Executable file
84
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php
vendored
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class SQLiteGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* Compile the "order by" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $orders
|
||||
* @return string
|
||||
*/
|
||||
protected function compileOrders(Builder $query, $orders)
|
||||
{
|
||||
$me = $this;
|
||||
|
||||
return 'order by '.implode(', ', array_map(function($order) use ($me)
|
||||
{
|
||||
return $me->wrap($order['column']).' collate nocase '.$order['direction'];
|
||||
}
|
||||
, $orders));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an insert statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function compileInsert(Builder $query, array $values)
|
||||
{
|
||||
// Essentially we will force every insert to be treated as a batch insert which
|
||||
// simply makes creating the SQL easier for us since we can utilize the same
|
||||
// basic routine regardless of an amount of records given to us to insert.
|
||||
$table = $this->wrapTable($query->from);
|
||||
|
||||
if ( ! is_array(reset($values)))
|
||||
{
|
||||
$values = array($values);
|
||||
}
|
||||
|
||||
// If there is only one record being inserted, we will just use the usual query
|
||||
// grammar insert builder because no special syntax is needed for the single
|
||||
// row inserts in SQLite. However, if there are multiples, we'll continue.
|
||||
if (count($values) == 1)
|
||||
{
|
||||
return parent::compileInsert($query, $values[0]);
|
||||
}
|
||||
|
||||
$names = $this->columnize(array_keys($values[0]));
|
||||
|
||||
$columns = array();
|
||||
|
||||
// SQLite requires us to build the multi-row insert as a listing of select with
|
||||
// unions joining them together. So we'll build out this list of columns and
|
||||
// then join them all together with select unions to complete the queries.
|
||||
foreach (array_keys($values[0]) as $column)
|
||||
{
|
||||
$columns[] = '? as '.$this->wrap($column);
|
||||
}
|
||||
|
||||
$columns = array_fill(0, count($values), implode(', ', $columns));
|
||||
|
||||
return "insert into $table ($names) select ".implode(' union select ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a truncate table statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return array
|
||||
*/
|
||||
public function compileTruncate(Builder $query)
|
||||
{
|
||||
$sql = array('delete from sqlite_sequence where name = ?' => array($query->from));
|
||||
|
||||
$sql['delete from '.$this->wrapTable($query->from)] = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
188
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
vendored
Executable file
188
vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
vendored
Executable file
@@ -0,0 +1,188 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class SqlServerGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The keyword identifier wrapper format.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $wrapper = '[%s]';
|
||||
|
||||
/**
|
||||
* Compile a select query into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder
|
||||
* @return string
|
||||
*/
|
||||
public function compileSelect(Builder $query)
|
||||
{
|
||||
$components = $this->compileComponents($query);
|
||||
|
||||
// If an offset is present on the query, we will need to wrap the query in
|
||||
// a big "ANSI" offset syntax block. This is very nasty compared to the
|
||||
// other database systems but is necessary for implementing features.
|
||||
if ($query->offset > 0)
|
||||
{
|
||||
return $this->compileAnsiOffset($query, $components);
|
||||
}
|
||||
|
||||
return $this->concatenate($components);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "select *" portion of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $columns
|
||||
* @return string
|
||||
*/
|
||||
protected function compileColumns(Builder $query, $columns)
|
||||
{
|
||||
if ( ! is_null($query->aggregate)) return;
|
||||
|
||||
$select = $query->distinct ? 'select distinct ' : 'select ';
|
||||
|
||||
// If there is a limit on the query, but not an offset, we will add the top
|
||||
// clause to the query, which serves as a "limit" type clause within the
|
||||
// SQL Server system similar to the limit keywords available in MySQL.
|
||||
if ($query->limit > 0 and $query->offset <= 0)
|
||||
{
|
||||
$select .= 'top '.$query->limit.' ';
|
||||
}
|
||||
|
||||
return $select.$this->columnize($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a full ANSI offset clause for the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $components
|
||||
* @return string
|
||||
*/
|
||||
protected function compileAnsiOffset(Builder $query, $components)
|
||||
{
|
||||
// An ORDER BY clause is required to make this offset query work, so if one does
|
||||
// not exist we'll just create a dummy clause to trick the database and so it
|
||||
// does not complain about the queries for not having an "order by" clause.
|
||||
if ( ! isset($components['orders']))
|
||||
{
|
||||
$components['orders'] = 'order by (select 0)';
|
||||
}
|
||||
|
||||
// We need to add the row number to the query so we can compare it to the offset
|
||||
// and limit values given for the statements. So we will add an expression to
|
||||
// the "select" that will give back the row numbers on each of the records.
|
||||
$orderings = $components['orders'];
|
||||
|
||||
$components['columns'] .= $this->compileOver($orderings);
|
||||
|
||||
unset($components['orders']);
|
||||
|
||||
// Next we need to calculate the constraints that should be placed on the query
|
||||
// to get the right offset and limit from our query but if there is no limit
|
||||
// set we will just handle the offset only since that is all that matters.
|
||||
$start = $query->offset + 1;
|
||||
|
||||
$constraint = $this->compileRowConstraint($query);
|
||||
|
||||
$sql = $this->concatenate($components);
|
||||
|
||||
// We are now ready to build the final SQL query so we'll create a common table
|
||||
// expression from the query and get the records with row numbers within our
|
||||
// given limit and offset value that we just put on as a query constraint.
|
||||
return $this->compileTableExpression($sql, $constraint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the over statement for a table expression.
|
||||
*
|
||||
* @param string $orderings
|
||||
* @return string
|
||||
*/
|
||||
protected function compileOver($orderings)
|
||||
{
|
||||
return ", row_number() over ({$orderings}) as row_num";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the limit / offset row constraint for a query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
protected function compileRowConstraint($query)
|
||||
{
|
||||
$start = $query->offset + 1;
|
||||
|
||||
if ($query->limit > 0)
|
||||
{
|
||||
$finish = $query->offset + $query->limit;
|
||||
|
||||
return "between {$start} and {$finish}";
|
||||
}
|
||||
|
||||
return ">= {$start}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a common table expression for a query.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param string $constraint
|
||||
* @return string
|
||||
*/
|
||||
protected function compileTableExpression($sql, $constraint)
|
||||
{
|
||||
return "select * from ({$sql}) as temp_table where row_num {$constraint}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "limit" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param int $limit
|
||||
* @return string
|
||||
*/
|
||||
protected function compileLimit(Builder $query, $limit)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "offset" portions of the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param int $offset
|
||||
* @return string
|
||||
*/
|
||||
protected function compileOffset(Builder $query, $offset)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a truncate table statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return array
|
||||
*/
|
||||
public function compileTruncate(Builder $query)
|
||||
{
|
||||
return array('truncate table '.$this->wrapTable($query->from) => array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the format for database stored dates.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateFormat()
|
||||
{
|
||||
return 'Y-m-d H:i:s.000';
|
||||
}
|
||||
|
||||
}
|
68
vendor/laravel/framework/src/Illuminate/Database/Query/JoinClause.php
vendored
Executable file
68
vendor/laravel/framework/src/Illuminate/Database/Query/JoinClause.php
vendored
Executable file
@@ -0,0 +1,68 @@
|
||||
<?php namespace Illuminate\Database\Query;
|
||||
|
||||
class JoinClause {
|
||||
|
||||
/**
|
||||
* The type of join being performed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* The table the join clause is joining to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $table;
|
||||
|
||||
/**
|
||||
* The "on" clauses for the join.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $clauses = array();
|
||||
|
||||
/**
|
||||
* Create a new join clause instance.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $table
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($type, $table)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an "on" clause to the join.
|
||||
*
|
||||
* @param string $first
|
||||
* @param string $operator
|
||||
* @param string $second
|
||||
* @param string $boolean
|
||||
* @return \Illuminate\Database\Query\JoinClause
|
||||
*/
|
||||
public function on($first, $operator, $second, $boolean = 'and')
|
||||
{
|
||||
$this->clauses[] = compact('first', 'operator', 'second', 'boolean');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an "or on" clause to the join.
|
||||
*
|
||||
* @param string $first
|
||||
* @param string $operator
|
||||
* @param string $second
|
||||
* @return \Illuminate\Database\Query\JoinClause
|
||||
*/
|
||||
public function orOn($first, $operator, $second)
|
||||
{
|
||||
return $this->on($first, $operator, $second, 'or');
|
||||
}
|
||||
|
||||
}
|
27
vendor/laravel/framework/src/Illuminate/Database/Query/Processors/PostgresProcessor.php
vendored
Executable file
27
vendor/laravel/framework/src/Illuminate/Database/Query/Processors/PostgresProcessor.php
vendored
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php namespace Illuminate\Database\Query\Processors;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class PostgresProcessor extends Processor {
|
||||
|
||||
/**
|
||||
* Process an "insert get ID" query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param string $sql
|
||||
* @param array $values
|
||||
* @param string $sequence
|
||||
* @return int
|
||||
*/
|
||||
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
|
||||
{
|
||||
$results = $query->getConnection()->select($sql, $values);
|
||||
|
||||
$sequence = $sequence ?: 'id';
|
||||
|
||||
$result = (array) $results[0];
|
||||
|
||||
return (int) $result[$sequence];
|
||||
}
|
||||
|
||||
}
|
37
vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php
vendored
Executable file
37
vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php
vendored
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php namespace Illuminate\Database\Query\Processors;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class Processor {
|
||||
|
||||
/**
|
||||
* Process the results of a "select" query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
public function processSelect(Builder $query, $results)
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an "insert get ID" query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param string $sql
|
||||
* @param array $values
|
||||
* @param string $sequence
|
||||
* @return int
|
||||
*/
|
||||
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
|
||||
{
|
||||
$query->getConnection()->insert($sql, $values);
|
||||
|
||||
$id = $query->getConnection()->getPdo()->lastInsertId($sequence);
|
||||
|
||||
return is_numeric($id) ? (int) $id : $id;
|
||||
}
|
||||
|
||||
}
|
25
vendor/laravel/framework/src/Illuminate/Database/Query/Processors/SqlServerProcessor.php
vendored
Executable file
25
vendor/laravel/framework/src/Illuminate/Database/Query/Processors/SqlServerProcessor.php
vendored
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php namespace Illuminate\Database\Query\Processors;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class SqlServerProcessor extends Processor {
|
||||
|
||||
/**
|
||||
* Process an "insert get ID" query.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param string $sql
|
||||
* @param array $values
|
||||
* @param string $sequence
|
||||
* @return int
|
||||
*/
|
||||
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
|
||||
{
|
||||
$query->getConnection()->insert($sql, $values);
|
||||
|
||||
$id = $query->getConnection()->getPdo()->lastInsertId();
|
||||
|
||||
return is_numeric($id) ? (int) $id : $id;
|
||||
}
|
||||
|
||||
}
|
69
vendor/laravel/framework/src/Illuminate/Database/README.md
vendored
Executable file
69
vendor/laravel/framework/src/Illuminate/Database/README.md
vendored
Executable file
@@ -0,0 +1,69 @@
|
||||
## Illuminate Database
|
||||
|
||||
The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style ORM, and schema builder. It currently supports MySQL, Postgres, SQL Server, and SQLite. It also serves as the database layer of the Laravel PHP framework.
|
||||
|
||||
### Usage Instructions
|
||||
|
||||
First, create a new "Capsule" manager instance. Capsule aims to make configuring the library for usage outside of the Laravel framework as easy as possible.
|
||||
|
||||
```
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
$capsule = new Capsule;
|
||||
|
||||
$capsule->addConnection([
|
||||
'driver' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'database' => 'database',
|
||||
'username' => 'root',
|
||||
'password' => 'password',
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
]);
|
||||
|
||||
// Setup the Eloquent ORM... (optional)
|
||||
$capsule->bootEloquent();
|
||||
|
||||
// Set the event dispatcher used by Eloquent models... (optional)
|
||||
$capsule->setEventDispatcher(...);
|
||||
|
||||
// Set the cache manager instance used by connections... (optional)
|
||||
$capsule->setCacheManager(...);
|
||||
|
||||
// Make this Capsule instance available globally via static methods... (optional)
|
||||
$capsule->setAsGlobal();
|
||||
```
|
||||
|
||||
Once the Capsule instance has been registered. You may use it like so:
|
||||
|
||||
**Using The Query Builder**
|
||||
|
||||
```
|
||||
$users = Capsule::table('users')->where('votes', '>' 100)->get();
|
||||
```
|
||||
Other core methods may be accessed directly from the Capsule in the same manner as from the DB facade:
|
||||
```
|
||||
$results = Capsule::select('select * from users where id = ?', array(1));
|
||||
```
|
||||
|
||||
**Using The Schema Builder**
|
||||
|
||||
```
|
||||
Capsule::schema()->create('users', function($table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
```
|
||||
|
||||
**Using The Eloquent ORM**
|
||||
|
||||
```
|
||||
class User extends Illuminate\Database\Eloquent\Model {}
|
||||
|
||||
$users = User::where('votes', '>', 1)->get();
|
||||
```
|
||||
|
||||
For further documentation on using the various database facilities this library provides, consult the [Laravel framework documentation](http://laravel.com/docs).
|
35
vendor/laravel/framework/src/Illuminate/Database/SQLiteConnection.php
vendored
Executable file
35
vendor/laravel/framework/src/Illuminate/Database/SQLiteConnection.php
vendored
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
class SQLiteConnection extends Connection {
|
||||
|
||||
/**
|
||||
* Get the default query grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new Query\Grammars\SQLiteGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default schema grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new Schema\Grammars\SQLiteGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL Driver.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Driver
|
||||
*/
|
||||
protected function getDoctrineDriver()
|
||||
{
|
||||
return new \Doctrine\DBAL\Driver\PDOSqlite\Driver;
|
||||
}
|
||||
|
||||
}
|
757
vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php
vendored
Executable file
757
vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php
vendored
Executable file
@@ -0,0 +1,757 @@
|
||||
<?php namespace Illuminate\Database\Schema;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Grammars\Grammar;
|
||||
|
||||
class Blueprint {
|
||||
|
||||
/**
|
||||
* The table the blueprint describes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* The columns that should be added to the table.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $columns = array();
|
||||
|
||||
/**
|
||||
* The commands that should be run for the table.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = array();
|
||||
|
||||
/**
|
||||
* The storage engine that should be used for the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $engine;
|
||||
|
||||
/**
|
||||
* Create a new schema blueprint.
|
||||
*
|
||||
* @param string $table
|
||||
* @param Closure $callback
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($table, Closure $callback = null)
|
||||
{
|
||||
$this->table = $table;
|
||||
|
||||
if ( ! is_null($callback)) $callback($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the blueprint against the database.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return void
|
||||
*/
|
||||
public function build(Connection $connection, Grammar $grammar)
|
||||
{
|
||||
foreach ($this->toSql($connection, $grammar) as $statement)
|
||||
{
|
||||
$connection->statement($statement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw SQL statements for the blueprint.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return array
|
||||
*/
|
||||
public function toSql(Connection $connection, Grammar $grammar)
|
||||
{
|
||||
$this->addImpliedCommands();
|
||||
|
||||
$statements = array();
|
||||
|
||||
// Each type of command has a corresponding compiler function on the schema
|
||||
// grammar which is used to build the necessary SQL statements to build
|
||||
// the blueprint element, so we'll just call that compilers function.
|
||||
foreach ($this->commands as $command)
|
||||
{
|
||||
$method = 'compile'.ucfirst($command->name);
|
||||
|
||||
if (method_exists($grammar, $method))
|
||||
{
|
||||
if ( ! is_null($sql = $grammar->$method($this, $command, $connection)))
|
||||
{
|
||||
$statements = array_merge($statements, (array) $sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the commands that are implied by the blueprint.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addImpliedCommands()
|
||||
{
|
||||
if (count($this->columns) > 0 and ! $this->creating())
|
||||
{
|
||||
array_unshift($this->commands, $this->createCommand('add'));
|
||||
}
|
||||
|
||||
$this->addFluentIndexes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the index commands fluently specified on columns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addFluentIndexes()
|
||||
{
|
||||
foreach ($this->columns as $column)
|
||||
{
|
||||
foreach (array('primary', 'unique', 'index') as $index)
|
||||
{
|
||||
// If the index has been specified on the given column, but is simply
|
||||
// equal to "true" (boolean), no name has been specified for this
|
||||
// index, so we will simply call the index methods without one.
|
||||
if ($column->$index === true)
|
||||
{
|
||||
$this->$index($column->name);
|
||||
|
||||
continue 2;
|
||||
}
|
||||
|
||||
// If the index has been specified on the column and it is something
|
||||
// other than boolean true, we will assume a name was provided on
|
||||
// the index specification, and pass in the name to the method.
|
||||
elseif (isset($column->$index))
|
||||
{
|
||||
$this->$index($column->name, $column->$index);
|
||||
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the blueprint has a create command.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function creating()
|
||||
{
|
||||
foreach ($this->commands as $command)
|
||||
{
|
||||
if ($command->name == 'create') return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the table needs to be created.
|
||||
*
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return $this->addCommand('create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the table should be dropped.
|
||||
*
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function drop()
|
||||
{
|
||||
return $this->addCommand('drop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the table should be dropped if it exists.
|
||||
*
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropIfExists()
|
||||
{
|
||||
return $this->addCommand('dropIfExists');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given columns should be dropped.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropColumn($columns)
|
||||
{
|
||||
$columns = is_array($columns) ? $columns : (array) func_get_args();
|
||||
|
||||
return $this->addCommand('dropColumn', compact('columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given columns should be renamed.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function renameColumn($from, $to)
|
||||
{
|
||||
return $this->addCommand('renameColumn', compact('from', 'to'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given primary key should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropPrimary($index = null)
|
||||
{
|
||||
return $this->dropIndexCommand('dropPrimary', 'primary', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given unique key should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropUnique($index)
|
||||
{
|
||||
return $this->dropIndexCommand('dropUnique', 'unique', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given index should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropIndex($index)
|
||||
{
|
||||
return $this->dropIndexCommand('dropIndex', 'index', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given foreign key should be dropped.
|
||||
*
|
||||
* @param string $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropForeign($index)
|
||||
{
|
||||
return $this->dropIndexCommand('dropForeign', 'foreign', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the timestamp columns should be dropped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropTimestamps()
|
||||
{
|
||||
$this->dropColumn('created_at', 'updated_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename the table to a given name.
|
||||
*
|
||||
* @param string $to
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function rename($to)
|
||||
{
|
||||
return $this->addCommand('rename', compact('to'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the primary key(s) for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function primary($columns, $name = null)
|
||||
{
|
||||
return $this->indexCommand('primary', $columns, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a unique index for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function unique($columns, $name = null)
|
||||
{
|
||||
return $this->indexCommand('unique', $columns, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify an index for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function index($columns, $name = null)
|
||||
{
|
||||
return $this->indexCommand('index', $columns, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a foreign key for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function foreign($columns, $name = null)
|
||||
{
|
||||
return $this->indexCommand('foreign', $columns, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new auto-incrementing integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function increments($column)
|
||||
{
|
||||
return $this->unsignedInteger($column, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new auto-incrementing big integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function bigIncrements($column)
|
||||
{
|
||||
return $this->unsignedBigInteger($column, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new string column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $length
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function string($column, $length = 255)
|
||||
{
|
||||
return $this->addColumn('string', $column, compact('length'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function text($column)
|
||||
{
|
||||
return $this->addColumn('text', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new medium text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function mediumText($column)
|
||||
{
|
||||
return $this->addColumn('mediumText', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new long text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function longText($column)
|
||||
{
|
||||
return $this->addColumn('longText', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function integer($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new big integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function bigInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('bigInteger', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new medium integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function mediumInteger($column)
|
||||
{
|
||||
return $this->addColumn('mediumInteger', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new tiny integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function tinyInteger($column)
|
||||
{
|
||||
return $this->addColumn('tinyInteger', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new small integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function smallInteger($column)
|
||||
{
|
||||
return $this->addColumn('smallInteger', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new unsigned integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function unsignedInteger($column, $autoIncrement = false)
|
||||
{
|
||||
return $this->integer($column, $autoIncrement, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new unsigned big integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function unsignedBigInteger($column, $autoIncrement = false)
|
||||
{
|
||||
return $this->bigInteger($column, $autoIncrement, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new float column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function float($column, $total = 8, $places = 2)
|
||||
{
|
||||
return $this->addColumn('float', $column, compact('total', 'places'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new decimal column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function decimal($column, $total = 8, $places = 2)
|
||||
{
|
||||
return $this->addColumn('decimal', $column, compact('total', 'places'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new boolean column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function boolean($column)
|
||||
{
|
||||
return $this->addColumn('boolean', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new enum column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param array $allowed
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function enum($column, array $allowed)
|
||||
{
|
||||
return $this->addColumn('enum', $column, compact('allowed'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new date column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function date($column)
|
||||
{
|
||||
return $this->addColumn('date', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new date-time column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dateTime($column)
|
||||
{
|
||||
return $this->addColumn('dateTime', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new time column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function time($column)
|
||||
{
|
||||
return $this->addColumn('time', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new timestamp column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function timestamp($column)
|
||||
{
|
||||
return $this->addColumn('timestamp', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add creation and update timestamps to the table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function timestamps()
|
||||
{
|
||||
$this->timestamp('created_at');
|
||||
|
||||
$this->timestamp('updated_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a "deleted at" timestamp for the table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function softDeletes()
|
||||
{
|
||||
$this->timestamp('deleted_at')->nullable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new binary column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function binary($column)
|
||||
{
|
||||
return $this->addColumn('binary', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the proper columns for a polymorphic table.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function morphs($name)
|
||||
{
|
||||
$this->integer("{$name}_id");
|
||||
|
||||
$this->string("{$name}_type");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new drop index command on the blueprint.
|
||||
*
|
||||
* @param string $command
|
||||
* @param string $type
|
||||
* @param string|array $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function dropIndexCommand($command, $type, $index)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
// If the given "index" is actually an array of columns, the developer means
|
||||
// to drop an index merely by specifying the columns involved without the
|
||||
// conventional name, so we will built the index name from the columns.
|
||||
if (is_array($index))
|
||||
{
|
||||
$columns = $index;
|
||||
|
||||
$index = $this->createIndexName($type, $columns);
|
||||
}
|
||||
|
||||
return $this->indexCommand($command, $columns, $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new index command to the blueprint.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string|array $columns
|
||||
* @param string $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function indexCommand($type, $columns, $index)
|
||||
{
|
||||
$columns = (array) $columns;
|
||||
|
||||
// If no name was specified for this index, we will create one using a basic
|
||||
// convention of the table name, followed by the columns, followed by an
|
||||
// index type, such as primary or index, which makes the index unique.
|
||||
if (is_null($index))
|
||||
{
|
||||
$index = $this->createIndexName($type, $columns);
|
||||
}
|
||||
|
||||
return $this->addCommand($type, compact('index', 'columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a default index name for the table.
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $columns
|
||||
* @return string
|
||||
*/
|
||||
protected function createIndexName($type, array $columns)
|
||||
{
|
||||
$table = str_replace(array('-', '.'), '_', $this->table);
|
||||
|
||||
return strtolower($table.'_'.implode('_', $columns).'_'.$type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new column to the blueprint.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function addColumn($type, $name, array $parameters = array())
|
||||
{
|
||||
$attributes = array_merge(compact('type', 'name'), $parameters);
|
||||
|
||||
$this->columns[] = $column = new Fluent($attributes);
|
||||
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new command to the blueprint.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function addCommand($name, array $parameters = array())
|
||||
{
|
||||
$this->commands[] = $command = $this->createCommand($name, $parameters);
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Fluent command.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function createCommand($name, array $parameters = array())
|
||||
{
|
||||
return new Fluent(array_merge(compact('name'), $parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the table the blueprint describes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTable()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columns that should be added.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the commands on the blueprint.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCommands()
|
||||
{
|
||||
return $this->commands;
|
||||
}
|
||||
|
||||
}
|
186
vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php
vendored
Executable file
186
vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php
vendored
Executable file
@@ -0,0 +1,186 @@
|
||||
<?php namespace Illuminate\Database\Schema;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Grammars\Grammar;
|
||||
|
||||
class Builder {
|
||||
|
||||
/**
|
||||
* The database connection instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The schema grammar instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Schema\Grammars\Grammar
|
||||
*/
|
||||
protected $grammar;
|
||||
|
||||
/**
|
||||
* Create a new database Schema manager.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->grammar = $connection->getSchemaGrammar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given table exists.
|
||||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTable($table)
|
||||
{
|
||||
$sql = $this->grammar->compileTableExists();
|
||||
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
|
||||
return count($this->connection->select($sql, array($table))) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given table has a given column.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @return bool
|
||||
*/
|
||||
public function hasColumn($table, $column)
|
||||
{
|
||||
$schema = $this->connection->getDoctrineSchemaManager();
|
||||
|
||||
return in_array($column, array_keys($schema->listTableColumns($table)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify a table on the schema.
|
||||
*
|
||||
* @param string $table
|
||||
* @param Closure $callback
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function table($table, Closure $callback)
|
||||
{
|
||||
$this->build($this->createBlueprint($table, $callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new table on the schema.
|
||||
*
|
||||
* @param string $table
|
||||
* @param Closure $callback
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function create($table, Closure $callback)
|
||||
{
|
||||
$blueprint = $this->createBlueprint($table);
|
||||
|
||||
$blueprint->create();
|
||||
|
||||
$callback($blueprint);
|
||||
|
||||
$this->build($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop a table from the schema.
|
||||
*
|
||||
* @param string $table
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function drop($table)
|
||||
{
|
||||
$blueprint = $this->createBlueprint($table);
|
||||
|
||||
$blueprint->drop();
|
||||
|
||||
$this->build($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop a table from the schema if it exists.
|
||||
*
|
||||
* @param string $table
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function dropIfExists($table)
|
||||
{
|
||||
$blueprint = $this->createBlueprint($table);
|
||||
|
||||
$blueprint->dropIfExists();
|
||||
|
||||
$this->build($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a table on the schema.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function rename($from, $to)
|
||||
{
|
||||
$blueprint = $this->createBlueprint($from);
|
||||
|
||||
$blueprint->rename($to);
|
||||
|
||||
$this->build($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the blueprint to build / modify the table.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @return void
|
||||
*/
|
||||
protected function build(Blueprint $blueprint)
|
||||
{
|
||||
$blueprint->build($this->connection, $this->grammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new command set with a Closure.
|
||||
*
|
||||
* @param string $table
|
||||
* @param Closure $callback
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
protected function createBlueprint($table, Closure $callback = null)
|
||||
{
|
||||
return new Blueprint($table, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database connection instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the database connection instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection
|
||||
* @return \Illuminate\Database\Schema\Builder
|
||||
*/
|
||||
public function setConnection(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
265
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/Grammar.php
vendored
Executable file
265
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/Grammar.php
vendored
Executable file
@@ -0,0 +1,265 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\TableDiff;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Grammar as BaseGrammar;
|
||||
use Doctrine\DBAL\Schema\AbstractSchemaManager as SchemaManager;
|
||||
|
||||
abstract class Grammar extends BaseGrammar {
|
||||
|
||||
/**
|
||||
* Compile a rename column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return array
|
||||
*/
|
||||
public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
{
|
||||
$schema = $connection->getDoctrineSchemaManager();
|
||||
|
||||
$column = $connection->getDoctrineColumn($blueprint->getTable(), $command->from);
|
||||
|
||||
$tableDiff = $this->getRenamedDiff($blueprint, $command, $column, $schema);
|
||||
|
||||
return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new column instance with the new column name.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
protected function getRenamedDiff(Blueprint $blueprint, Fluent $command, Column $column, SchemaManager $schema)
|
||||
{
|
||||
$tableDiff = $this->getDoctrineTableDiff($blueprint, $schema);
|
||||
|
||||
return $this->setRenamedColumns($tableDiff, $command, $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the renamed columns on the table diff.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
protected function setRenamedColumns(TableDiff $tableDiff, Fluent $command, Column $column)
|
||||
{
|
||||
$newColumn = new Column($command->to, $column->getType(), $column->toArray());
|
||||
|
||||
$tableDiff->renamedColumns = array($command->from => $newColumn);
|
||||
|
||||
return $tableDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$on = $this->wrapTable($command->on);
|
||||
|
||||
// We need to prepare several of the elements of the foreign key definition
|
||||
// before we can create the SQL, such as wrapping the tables and convert
|
||||
// an array of columns to comma-delimited strings for the SQL queries.
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$onColumns = $this->columnize((array) $command->references);
|
||||
|
||||
$sql = "alter table {$table} add constraint {$command->index} ";
|
||||
|
||||
$sql .= "foreign key ({$columns}) references {$on} ({$onColumns})";
|
||||
|
||||
// Once we have the basic foreign key creation statement constructed we can
|
||||
// build out the syntax for what should happen on an update or delete of
|
||||
// the affected columns, which will get something like "cascade", etc.
|
||||
if ( ! is_null($command->onDelete))
|
||||
{
|
||||
$sql .= " on delete {$command->onDelete}";
|
||||
}
|
||||
|
||||
if ( ! is_null($command->onUpdate))
|
||||
{
|
||||
$sql .= " on update {$command->onUpdate}";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the blueprint's column definitions.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @return array
|
||||
*/
|
||||
protected function getColumns(Blueprint $blueprint)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
foreach ($blueprint->getColumns() as $column)
|
||||
{
|
||||
// Each of the column types have their own compiler functions which are tasked
|
||||
// with turning the column definition into its SQL format for this platform
|
||||
// used by the connection. The column's modifiers are compiled and added.
|
||||
$sql = $this->wrap($column).' '.$this->getType($column);
|
||||
|
||||
$columns[] = $this->addModifiers($sql, $blueprint, $column);
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the column modifiers to the definition.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function addModifiers($sql, Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
foreach ($this->modifiers as $modifier)
|
||||
{
|
||||
if (method_exists($this, $method = "modify{$modifier}"))
|
||||
{
|
||||
$sql .= $this->{$method}($blueprint, $column);
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary key command if it exists on the blueprint.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @return \Illuminate\Support\Fluent|null
|
||||
*/
|
||||
protected function getCommandByName(Blueprint $blueprint, $name)
|
||||
{
|
||||
$commands = $this->getCommandsByName($blueprint, $name);
|
||||
|
||||
if (count($commands) > 0)
|
||||
{
|
||||
return reset($commands);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the commands with a given name.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function getCommandsByName(Blueprint $blueprint, $name)
|
||||
{
|
||||
return array_filter($blueprint->getCommands(), function($value) use ($name)
|
||||
{
|
||||
return $value->name == $name;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for the column data type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function getType(Fluent $column)
|
||||
{
|
||||
return $this->{"type".ucfirst($column->type)}($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a prefix to an array of values.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function prefixArray($prefix, array $values)
|
||||
{
|
||||
return array_map(function($value) use ($prefix)
|
||||
{
|
||||
return $prefix.' '.$value;
|
||||
|
||||
}, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a table in keyword identifiers.
|
||||
*
|
||||
* @param mixed $table
|
||||
* @return string
|
||||
*/
|
||||
public function wrapTable($table)
|
||||
{
|
||||
if ($table instanceof Blueprint) $table = $table->getTable();
|
||||
|
||||
return parent::wrapTable($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a value in keyword identifiers.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function wrap($value)
|
||||
{
|
||||
if ($value instanceof Fluent) $value = $value->name;
|
||||
|
||||
return parent::wrap($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a value so that it can be used in "default" clauses.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefaultValue($value)
|
||||
{
|
||||
if ($value instanceof Expression) return $value;
|
||||
|
||||
if (is_bool($value)) return "'".intval($value)."'";
|
||||
|
||||
return "'".strval($value)."'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty Doctrine DBAL TableDiff from the Blueprint.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
protected function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema)
|
||||
{
|
||||
$tableDiff = new TableDiff($blueprint->getTable());
|
||||
|
||||
$tableDiff->fromTable = $schema->listTableDetails($blueprint->getTable());
|
||||
|
||||
return $tableDiff;
|
||||
}
|
||||
|
||||
}
|
537
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
vendored
Executable file
537
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
vendored
Executable file
@@ -0,0 +1,537 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class MySqlGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The keyword identifier wrapper format.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $wrapper = '`%s`';
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Unsigned', 'Nullable', 'Default', 'Increment', 'After');
|
||||
|
||||
/**
|
||||
* The possible column serials
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer');
|
||||
|
||||
/**
|
||||
* Compile the query to determine if a table exists.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return 'select * from information_schema.tables where table_schema = ? and table_name = ?';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return string
|
||||
*/
|
||||
public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
{
|
||||
$columns = implode(', ', $this->getColumns($blueprint));
|
||||
|
||||
$sql = 'create table '.$this->wrapTable($blueprint)." ($columns)";
|
||||
|
||||
// Once we have the primary SQL, we can add the encoding option to the SQL for
|
||||
// the table. Then, we can check if a storage engine has been supplied for
|
||||
// the table. If so, we will add the engine declaration to the SQL query.
|
||||
$sql = $this->compileCreateEncoding($sql, $connection);
|
||||
|
||||
if (isset($blueprint->engine))
|
||||
{
|
||||
$sql .= ' engine = '.$blueprint->engine;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the character set specifications to a command.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCreateEncoding($sql, Connection $connection)
|
||||
{
|
||||
if ( ! is_null($charset = $connection->getConfig('charset')))
|
||||
{
|
||||
$sql .= ' default character set '.$charset;
|
||||
}
|
||||
|
||||
if ( ! is_null($collation = $connection->getConfig('collation')))
|
||||
{
|
||||
$sql .= ' collate '.$collation;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->prefixArray('add', $this->getColumns($blueprint));
|
||||
|
||||
return 'alter table '.$table.' '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a primary key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compilePrimary(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$command->name(null);
|
||||
|
||||
return $this->compileKey($blueprint, $command, 'primary key');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return $this->compileKey($blueprint, $command, 'unique');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a plain index key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return $this->compileKey($blueprint, $command, 'index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an index creation command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} add {$type} {$command->index}($columns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table (if exists) command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table if exists '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->prefixArray('drop', $this->wrapArray($command->columns));
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return 'alter table '.$table.' '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop primary key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'alter table '.$this->wrapTable($blueprint).' drop primary key';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop index command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop foreign key {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a rename table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRename(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$from = $this->wrapTable($blueprint);
|
||||
|
||||
return "rename table {$from} to ".$this->wrapTable($command->to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a string type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeString(Fluent $column)
|
||||
{
|
||||
return "varchar({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumText(Fluent $column)
|
||||
{
|
||||
return 'mediumtext';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a long text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeLongText(Fluent $column)
|
||||
{
|
||||
return 'longtext';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a big integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBigInteger(Fluent $column)
|
||||
{
|
||||
return 'bigint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeInteger(Fluent $column)
|
||||
{
|
||||
return 'int';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumInteger(Fluent $column)
|
||||
{
|
||||
return 'mediumint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
{
|
||||
return 'tinyint(1)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
{
|
||||
return 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
{
|
||||
return "float({$column->total}, {$column->places})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a decimal type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDecimal(Fluent $column)
|
||||
{
|
||||
return "decimal({$column->total}, {$column->places})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a boolean type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBoolean(Fluent $column)
|
||||
{
|
||||
return 'tinyint(1)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
return "enum('".implode("', '", $column->allowed)."')";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDate(Fluent $column)
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTime(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
{
|
||||
if ( ! $column->nullable) return 'timestamp default 0';
|
||||
|
||||
return 'timestamp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a binary type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBinary(Fluent $column)
|
||||
{
|
||||
return 'blob';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an unsigned column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyUnsigned(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ($column->unsigned) return ' unsigned';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a nullable column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
return $column->nullable ? ' null' : ' not null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a default column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->default))
|
||||
{
|
||||
return " default ".$this->getDefaultValue($column->default);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an auto-increment column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (in_array($column->type, $this->serials) and $column->autoIncrement)
|
||||
{
|
||||
return ' auto_increment primary key';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an "after" column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyAfter(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->after))
|
||||
{
|
||||
return ' after '.$this->wrap($column->after);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
463
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
vendored
Executable file
463
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
vendored
Executable file
@@ -0,0 +1,463 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class PostgresGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The keyword identifier wrapper format.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $wrapper = '"%s"';
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Increment', 'Nullable', 'Default');
|
||||
|
||||
/**
|
||||
* The columns available as serials.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer');
|
||||
|
||||
/**
|
||||
* Compile the query to determine if a table exists.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return 'select * from information_schema.tables where table_name = ?';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileCreate(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = implode(', ', $this->getColumns($blueprint));
|
||||
|
||||
return 'create table '.$this->wrapTable($blueprint)." ($columns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->prefixArray('add column', $this->getColumns($blueprint));
|
||||
|
||||
return 'alter table '.$table.' '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a primary key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compilePrimary(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
return 'alter table '.$this->wrapTable($blueprint)." add primary key ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
return "alter table $table add constraint {$command->index} unique ($columns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a plain index key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
return "create index {$command->index} on ".$this->wrapTable($blueprint)." ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table (if exists) command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table if exists '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->prefixArray('drop column', $this->wrapArray($command->columns));
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return 'alter table '.$table.' '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop primary key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $blueprint->getTable();
|
||||
|
||||
return 'alter table '.$this->wrapTable($blueprint)." drop constraint {$table}_pkey";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop constraint {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop index command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return "drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop constraint {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a rename table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRename(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$from = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$from} rename to ".$this->wrapTable($command->to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a string type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeString(Fluent $column)
|
||||
{
|
||||
return "varchar({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a long text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeLongText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeInteger(Fluent $column)
|
||||
{
|
||||
return $column->autoIncrement ? 'serial' : 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a big integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBigInteger(Fluent $column)
|
||||
{
|
||||
return $column->autoIncrement ? 'bigserial' : 'bigint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
{
|
||||
return 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
{
|
||||
return 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
{
|
||||
return 'real';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a decimal type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDecimal(Fluent $column)
|
||||
{
|
||||
return "decimal({$column->total}, {$column->places})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a boolean type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBoolean(Fluent $column)
|
||||
{
|
||||
return 'boolean';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for an enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
$allowed = array_map(function($a) { return "'".$a."'"; }, $column->allowed);
|
||||
|
||||
return "varchar(255) check ({$column->name} in (".implode(', ', $allowed)."))";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDate(Fluent $column)
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTime(Fluent $column)
|
||||
{
|
||||
return 'timestamp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
{
|
||||
return 'timestamp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a binary type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBinary(Fluent $column)
|
||||
{
|
||||
return 'bytea';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a nullable column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
return $column->nullable ? ' null' : ' not null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a default column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->default))
|
||||
{
|
||||
return " default ".$this->getDefaultValue($column->default);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an auto-increment column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (in_array($column->type, $this->serials) and $column->autoIncrement)
|
||||
{
|
||||
return ' primary key';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
525
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php
vendored
Executable file
525
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php
vendored
Executable file
@@ -0,0 +1,525 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class SQLiteGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The keyword identifier wrapper format.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $wrapper = '"%s"';
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Nullable', 'Default', 'Increment');
|
||||
|
||||
/**
|
||||
* The columns available as serials.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer');
|
||||
|
||||
/**
|
||||
* Compile the query to determine if a table exists.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return "select * from sqlite_master where type = 'table' and name = ?";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileCreate(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = implode(', ', $this->getColumns($blueprint));
|
||||
|
||||
$sql = 'create table '.$this->wrapTable($blueprint)." ($columns";
|
||||
|
||||
// SQLite forces primary keys to be added when the table is initially created
|
||||
// so we will need to check for a primary key commands and add the columns
|
||||
// to the table's declaration here so they can be created on the tables.
|
||||
$sql .= (string) $this->addForeignKeys($blueprint);
|
||||
|
||||
$sql .= (string) $this->addPrimaryKeys($blueprint);
|
||||
|
||||
return $sql .= ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreign key syntax for a table creation statement.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @return string|null
|
||||
*/
|
||||
protected function addForeignKeys(Blueprint $blueprint)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
$foreigns = $this->getCommandsByName($blueprint, 'foreign');
|
||||
|
||||
// Once we have all the foreign key commands for the table creation statement
|
||||
// we'll loop through each of them and add them to the create table SQL we
|
||||
// are building, since SQLite needs foreign keys on the tables creation.
|
||||
foreach ($foreigns as $foreign)
|
||||
{
|
||||
$sql .= $this->getForeignKey($foreign);
|
||||
|
||||
if ( ! is_null($foreign->onDelete))
|
||||
{
|
||||
$sql .= " on delete {$foreign->onDelete}";
|
||||
}
|
||||
|
||||
if ( ! is_null($foreign->onUpdate))
|
||||
{
|
||||
$sql .= " on update {$foreign->onUpdate}";
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for the foreign key.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $foreign
|
||||
* @return string
|
||||
*/
|
||||
protected function getForeignKey($foreign)
|
||||
{
|
||||
$on = $this->wrapTable($foreign->on);
|
||||
|
||||
// We need to columnize the columns that the foreign key is being defined for
|
||||
// so that it is a properly formatted list. Once we have done this, we can
|
||||
// return the foreign key SQL declaration to the calling method for use.
|
||||
$columns = $this->columnize($foreign->columns);
|
||||
|
||||
$onColumns = $this->columnize((array) $foreign->references);
|
||||
|
||||
return ", foreign key($columns) references $on($onColumns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary key syntax for a table creation statement.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @return string|null
|
||||
*/
|
||||
protected function addPrimaryKeys(Blueprint $blueprint)
|
||||
{
|
||||
$primary = $this->getCommandByName($blueprint, 'primary');
|
||||
|
||||
if ( ! is_null($primary))
|
||||
{
|
||||
$columns = $this->columnize($primary->columns);
|
||||
|
||||
return ", primary key ({$columns})";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile alter table commands for adding columns
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return array
|
||||
*/
|
||||
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->prefixArray('add column', $this->getColumns($blueprint));
|
||||
|
||||
foreach ($columns as $column)
|
||||
{
|
||||
$statements[] = 'alter table '.$table.' '.$column;
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "create unique index {$command->index} on {$table} ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a plain index key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "create index {$command->index} on {$table} ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
// Handled on table creation...
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table (if exists) command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table if exists '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return array
|
||||
*/
|
||||
public function compileDropColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
{
|
||||
$schema = $connection->getDoctrineSchemaManager();
|
||||
|
||||
$tableDiff = $this->getDoctrineTableDiff($blueprint, $schema);
|
||||
|
||||
foreach ($command->columns as $name)
|
||||
{
|
||||
$column = $connection->getDoctrineColumn($blueprint->getTable(), $name);
|
||||
|
||||
$tableDiff->removedColumns[$name] = $column;
|
||||
}
|
||||
|
||||
return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return "drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop index command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return "drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a rename table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRename(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$from = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$from} rename to ".$this->wrapTable($command->to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a string type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeString(Fluent $column)
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a long text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeLongText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a big integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBigInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a decimal type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDecimal(Fluent $column)
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a boolean type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBoolean(Fluent $column)
|
||||
{
|
||||
return 'tinyint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDate(Fluent $column)
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTime(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a binary type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBinary(Fluent $column)
|
||||
{
|
||||
return 'blob';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a nullable column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
return ' null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a default column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->default))
|
||||
{
|
||||
return " default ".$this->getDefaultValue($column->default);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an auto-increment column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (in_array($column->type, $this->serials) and $column->autoIncrement)
|
||||
{
|
||||
return ' primary key autoincrement';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
457
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
vendored
Executable file
457
vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
vendored
Executable file
@@ -0,0 +1,457 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class SqlServerGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The keyword identifier wrapper format.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $wrapper = '"%s"';
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Increment', 'Nullable', 'Default');
|
||||
|
||||
/**
|
||||
* The columns available as serials.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer');
|
||||
|
||||
/**
|
||||
* Compile the query to determine if a table exists.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return "select * from sysobjects where type = 'U' and name = ?";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileCreate(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = implode(', ', $this->getColumns($blueprint));
|
||||
|
||||
return 'create table '.$this->wrapTable($blueprint)." ($columns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->getColumns($blueprint);
|
||||
|
||||
return 'alter table '.$table.' add '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a primary key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compilePrimary(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} add constraint {$command->index} primary key ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "create unique index {$command->index} on {$table} ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a plain index key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "create index {$command->index} on {$table} ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->wrapArray($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return 'alter table '.$table.' drop column '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop primary key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $blueprint->getTable();
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop constraint {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "drop index {$command->index} on {$table}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop index command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "drop index {$command->index} on {$table}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop constraint {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a rename table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRename(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$from = $this->wrapTable($blueprint);
|
||||
|
||||
return "sp_rename {$from}, ".$this->wrapTable($command->to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a string type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeString(Fluent $column)
|
||||
{
|
||||
return "nvarchar({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeText(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumText(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a long text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeLongText(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeInteger(Fluent $column)
|
||||
{
|
||||
return 'int';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a big integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBigInteger(Fluent $column)
|
||||
{
|
||||
return 'bigint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumInteger(Fluent $column)
|
||||
{
|
||||
return 'int';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
{
|
||||
return 'tinyint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
{
|
||||
return 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a decimal type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDecimal(Fluent $column)
|
||||
{
|
||||
return "decimal({$column->total}, {$column->places})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a boolean type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBoolean(Fluent $column)
|
||||
{
|
||||
return 'tinyint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(255)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDate(Fluent $column)
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTime(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a binary type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBinary(Fluent $column)
|
||||
{
|
||||
return 'varbinary(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a nullable column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
return $column->nullable ? ' null' : ' not null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a default column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->default))
|
||||
{
|
||||
return " default ".$this->getDefaultValue($column->default);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an auto-increment column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (in_array($column->type, $this->serials) and $column->autoIncrement)
|
||||
{
|
||||
return ' identity primary key';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
22
vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php
vendored
Executable file
22
vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php
vendored
Executable file
@@ -0,0 +1,22 @@
|
||||
<?php namespace Illuminate\Database\Schema;
|
||||
|
||||
class MySqlBuilder extends Builder {
|
||||
|
||||
/**
|
||||
* Determine if the given table exists.
|
||||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTable($table)
|
||||
{
|
||||
$sql = $this->grammar->compileTableExists();
|
||||
|
||||
$database = $this->connection->getDatabaseName();
|
||||
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
|
||||
return count($this->connection->select($sql, array($database, $table))) > 0;
|
||||
}
|
||||
|
||||
}
|
55
vendor/laravel/framework/src/Illuminate/Database/SeedServiceProvider.php
vendored
Executable file
55
vendor/laravel/framework/src/Illuminate/Database/SeedServiceProvider.php
vendored
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Database\Console\SeedCommand;
|
||||
|
||||
class SeedServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerSeedCommand();
|
||||
|
||||
$this->app['seeder'] = $this->app->share(function($app)
|
||||
{
|
||||
return new Seeder;
|
||||
});
|
||||
|
||||
$this->commands('command.seed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the seed console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerSeedCommand()
|
||||
{
|
||||
$this->app['command.seed'] = $this->app->share(function($app)
|
||||
{
|
||||
return new SeedCommand($app['db']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('seeder', 'command.seed');
|
||||
}
|
||||
|
||||
}
|
87
vendor/laravel/framework/src/Illuminate/Database/Seeder.php
vendored
Executable file
87
vendor/laravel/framework/src/Illuminate/Database/Seeder.php
vendored
Executable file
@@ -0,0 +1,87 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class Seeder {
|
||||
|
||||
/**
|
||||
* The container instance.
|
||||
*
|
||||
* @var \Illuminate\Container\Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* The console command instance.
|
||||
*
|
||||
* @var \Illuminate\Console\Command
|
||||
*/
|
||||
protected $command;
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run() {}
|
||||
|
||||
/**
|
||||
* Seed the given connection from the given path.
|
||||
*
|
||||
* @param string $class
|
||||
* @return void
|
||||
*/
|
||||
public function call($class)
|
||||
{
|
||||
$this->resolve($class)->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an instance of the given seeder class.
|
||||
*
|
||||
* @param string $class
|
||||
* @return \Illuminate\Database\Seeder
|
||||
*/
|
||||
protected function resolve($class)
|
||||
{
|
||||
if (isset($this->container))
|
||||
{
|
||||
$instance = $this->container->make($class);
|
||||
|
||||
return $instance->setContainer($this->container)->setCommand($this->command);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IoC container instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function setContainer(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the console command instance.
|
||||
*
|
||||
* @param \Illuminate\Console\Command $command
|
||||
* @return void
|
||||
*/
|
||||
public function setCommand(Command $command)
|
||||
{
|
||||
$this->command = $command;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
80
vendor/laravel/framework/src/Illuminate/Database/SqlServerConnection.php
vendored
Executable file
80
vendor/laravel/framework/src/Illuminate/Database/SqlServerConnection.php
vendored
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Closure;
|
||||
|
||||
class SqlServerConnection extends Connection {
|
||||
|
||||
/**
|
||||
* Execute a Closure within a transaction.
|
||||
*
|
||||
* @param Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function transaction(Closure $callback)
|
||||
{
|
||||
$this->pdo->exec('BEGIN TRAN');
|
||||
|
||||
// We'll simply execute the given callback within a try / catch block
|
||||
// and if we catch any exception we can rollback the transaction
|
||||
// so that none of the changes are persisted to the database.
|
||||
try
|
||||
{
|
||||
$result = $callback($this);
|
||||
|
||||
$this->pdo->exec('COMMIT TRAN');
|
||||
}
|
||||
|
||||
// If we catch an exception, we will roll back so nothing gets messed
|
||||
// up in the database. Then we'll re-throw the exception so it can
|
||||
// be handled how the developer sees fit for their applications.
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->pdo->exec('ROLLBACK TRAN');
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default query grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new Query\Grammars\SqlServerGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default schema grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Grammars\Grammar
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new Schema\Grammars\SqlServerGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL Driver.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Driver
|
||||
*/
|
||||
protected function getDoctrineDriver()
|
||||
{
|
||||
return new \Doctrine\DBAL\Driver\PDOSqlsrv\Driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default post processor instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Processors\Processor
|
||||
*/
|
||||
protected function getDefaultPostProcessor()
|
||||
{
|
||||
return new Query\Processors\SqlServerProcessor;
|
||||
}
|
||||
|
||||
}
|
39
vendor/laravel/framework/src/Illuminate/Database/composer.json
vendored
Executable file
39
vendor/laravel/framework/src/Illuminate/Database/composer.json
vendored
Executable file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "illuminate/database",
|
||||
"license": "MIT",
|
||||
"keywords": ["laravel", "database", "sql", "orm"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"illuminate/container": "4.0.x",
|
||||
"illuminate/events": "4.0.x",
|
||||
"illuminate/support": "4.0.x",
|
||||
"nesbot/carbon": "1.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/cache": "4.0.x",
|
||||
"illuminate/console": "4.0.x",
|
||||
"illuminate/filesystem": "4.0.x",
|
||||
"illuminate/pagination": "4.0.x",
|
||||
"illuminate/support": "4.0.x",
|
||||
"mockery/mockery": "0.7.2",
|
||||
"phpunit/phpunit": "3.7.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Illuminate\\Database": ""
|
||||
}
|
||||
},
|
||||
"target-dir": "Illuminate/Database",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.0-dev"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
Reference in New Issue
Block a user