Added vendor/ directory for Composer's installed files
This commit is contained in:
202
vendor/illuminate/database/Capsule/Manager.php
vendored
Executable file
202
vendor/illuminate/database/Capsule/Manager.php
vendored
Executable file
@ -0,0 +1,202 @@
|
||||
<?php namespace Illuminate\Database\Capsule;
|
||||
|
||||
use PDO;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Connectors\ConnectionFactory;
|
||||
use Illuminate\Support\Traits\CapsuleManagerTrait;
|
||||
|
||||
class Manager {
|
||||
|
||||
use CapsuleManagerTrait;
|
||||
|
||||
/**
|
||||
* The database manager instance.
|
||||
*
|
||||
* @var \Illuminate\Database\DatabaseManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* Create a new database capsule manager.
|
||||
*
|
||||
* @param \Illuminate\Container\Container|null $container
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $container = null)
|
||||
{
|
||||
$this->setupContainer($container ?: new 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 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 $this
|
||||
*/
|
||||
public function setFetchMode($fetchMode)
|
||||
{
|
||||
$this->container['config']['database.fetch'] = $fetchMode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database manager instance.
|
||||
*
|
||||
* @return \Illuminate\Database\DatabaseManager
|
||||
*/
|
||||
public function getDatabaseManager()
|
||||
{
|
||||
return $this->manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current event dispatcher instance.
|
||||
*
|
||||
* @return \Illuminate\Contracts\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\Contracts\Events\Dispatcher $dispatcher
|
||||
* @return void
|
||||
*/
|
||||
public function setEventDispatcher(Dispatcher $dispatcher)
|
||||
{
|
||||
$this->container->instance('events', $dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
1126
vendor/illuminate/database/Connection.php
vendored
Executable file
1126
vendor/illuminate/database/Connection.php
vendored
Executable file
File diff suppressed because it is too large
Load Diff
148
vendor/illuminate/database/ConnectionInterface.php
vendored
Executable file
148
vendor/illuminate/database/ConnectionInterface.php
vendored
Executable file
@ -0,0 +1,148 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Closure;
|
||||
|
||||
interface ConnectionInterface {
|
||||
|
||||
/**
|
||||
* Begin a fluent query against a database table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
public function table($table);
|
||||
|
||||
/**
|
||||
* Get a new raw query expression.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return \Illuminate\Database\Query\Expression
|
||||
*/
|
||||
public function raw($value);
|
||||
|
||||
/**
|
||||
* 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());
|
||||
|
||||
/**
|
||||
* 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());
|
||||
|
||||
/**
|
||||
* Run a raw, unprepared query against the PDO connection.
|
||||
*
|
||||
* @param string $query
|
||||
* @return bool
|
||||
*/
|
||||
public function unprepared($query);
|
||||
|
||||
/**
|
||||
* Prepare the query bindings for execution.
|
||||
*
|
||||
* @param array $bindings
|
||||
* @return array
|
||||
*/
|
||||
public function prepareBindings(array $bindings);
|
||||
|
||||
/**
|
||||
* Execute a Closure within a transaction.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function transaction(Closure $callback);
|
||||
|
||||
/**
|
||||
* Start a new database transaction.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function beginTransaction();
|
||||
|
||||
/**
|
||||
* Commit the active database transaction.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function commit();
|
||||
|
||||
/**
|
||||
* Rollback the active database transaction.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rollBack();
|
||||
|
||||
/**
|
||||
* Get the number of active transactions.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function transactionLevel();
|
||||
|
||||
/**
|
||||
* Execute the given callback in "dry run" mode.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return array
|
||||
*/
|
||||
public function pretend(Closure $callback);
|
||||
|
||||
}
|
90
vendor/illuminate/database/ConnectionResolver.php
vendored
Executable file
90
vendor/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\ConnectionInterface
|
||||
*/
|
||||
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\ConnectionInterface $connection
|
||||
* @return void
|
||||
*/
|
||||
public function addConnection($name, ConnectionInterface $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/illuminate/database/ConnectionResolverInterface.php
vendored
Executable file
28
vendor/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);
|
||||
|
||||
}
|
231
vendor/illuminate/database/Connectors/ConnectionFactory.php
vendored
Executable file
231
vendor/illuminate/database/Connectors/ConnectionFactory.php
vendored
Executable file
@ -0,0 +1,231 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
use PDO;
|
||||
use InvalidArgumentException;
|
||||
use Illuminate\Database\MySqlConnection;
|
||||
use Illuminate\Database\SQLiteConnection;
|
||||
use Illuminate\Database\PostgresConnection;
|
||||
use Illuminate\Database\SqlServerConnection;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class ConnectionFactory {
|
||||
|
||||
/**
|
||||
* The IoC container instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Container\Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Create a new connection factory instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\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);
|
||||
|
||||
if (isset($config['read']))
|
||||
{
|
||||
return $this->createReadWriteConnection($config);
|
||||
}
|
||||
|
||||
return $this->createSingleConnection($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a single database connection instance.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
protected function createSingleConnection(array $config)
|
||||
{
|
||||
$pdo = $this->createConnector($config)->connect($config);
|
||||
|
||||
return $this->createConnection($config['driver'], $pdo, $config['database'], $config['prefix'], $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a single database connection instance.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
protected function createReadWriteConnection(array $config)
|
||||
{
|
||||
$connection = $this->createSingleConnection($this->getWriteConfig($config));
|
||||
|
||||
return $connection->setReadPdo($this->createReadPdo($config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new PDO instance for reading.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \PDO
|
||||
*/
|
||||
protected function createReadPdo(array $config)
|
||||
{
|
||||
$readConfig = $this->getReadConfig($config);
|
||||
|
||||
return $this->createConnector($readConfig)->connect($readConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the read configuration for a read / write connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function getReadConfig(array $config)
|
||||
{
|
||||
$readConfig = $this->getReadWriteConfig($config, 'read');
|
||||
|
||||
return $this->mergeReadWriteConfig($config, $readConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the read configuration for a read / write connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function getWriteConfig(array $config)
|
||||
{
|
||||
$writeConfig = $this->getReadWriteConfig($config, 'write');
|
||||
|
||||
return $this->mergeReadWriteConfig($config, $writeConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a read / write level configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function getReadWriteConfig(array $config, $type)
|
||||
{
|
||||
if (isset($config[$type][0]))
|
||||
{
|
||||
return $config[$type][array_rand($config[$type])];
|
||||
}
|
||||
|
||||
return $config[$type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge a configuration for a read / write connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @param array $merge
|
||||
* @return array
|
||||
*/
|
||||
protected function mergeReadWriteConfig(array $config, array $merge)
|
||||
{
|
||||
return array_except(array_merge($config, $merge), array('read', 'write'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function createConnector(array $config)
|
||||
{
|
||||
if ( ! isset($config['driver']))
|
||||
{
|
||||
throw new InvalidArgumentException("A driver must be specified.");
|
||||
}
|
||||
|
||||
if ($this->container->bound($key = "db.connector.{$config['driver']}"))
|
||||
{
|
||||
return $this->container->make($key);
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array())
|
||||
{
|
||||
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/illuminate/database/Connectors/Connector.php
vendored
Executable file
71
vendor/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/illuminate/database/Connectors/ConnectorInterface.php
vendored
Executable file
13
vendor/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);
|
||||
|
||||
}
|
112
vendor/illuminate/database/Connectors/MySqlConnector.php
vendored
Executable file
112
vendor/illuminate/database/Connectors/MySqlConnector.php
vendored
Executable file
@ -0,0 +1,112 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
class MySqlConnector extends Connector implements ConnectorInterface {
|
||||
|
||||
/**
|
||||
* Establish a database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \PDO
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
$dsn = $this->getDsn($config);
|
||||
|
||||
$options = $this->getOptions($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.
|
||||
$connection = $this->createConnection($dsn, $config, $options);
|
||||
|
||||
if (isset($config['unix_socket']))
|
||||
{
|
||||
$connection->exec("use `{$config['database']}`;");
|
||||
}
|
||||
|
||||
$collation = $config['collation'];
|
||||
|
||||
// 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.
|
||||
$charset = $config['charset'];
|
||||
|
||||
$names = "set names '$charset'".
|
||||
( ! is_null($collation) ? " collate '$collation'" : '');
|
||||
|
||||
$connection->prepare($names)->execute();
|
||||
|
||||
// Next, we will check to see if a timezone has been specified in this config
|
||||
// and if it has we will issue a statement to modify the timezone with the
|
||||
// database. Setting this DB timezone is an optional configuration item.
|
||||
if (isset($config['timezone']))
|
||||
{
|
||||
$connection->prepare(
|
||||
'set time_zone="'.$config['timezone'].'"'
|
||||
)->execute();
|
||||
}
|
||||
|
||||
// If the "strict" option has been configured for the connection we'll enable
|
||||
// strict mode on all of these tables. This enforces some extra rules when
|
||||
// using the MySQL database system and is a quicker way to enforce them.
|
||||
if (isset($config['strict']) && $config['strict'])
|
||||
{
|
||||
$connection->prepare("set session sql_mode='STRICT_ALL_TABLES'")->execute();
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a DSN string from a configuration.
|
||||
*
|
||||
* Chooses socket or host/port based on the 'unix_socket' config value.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getDsn(array $config)
|
||||
{
|
||||
return $this->configHasSocket($config) ? $this->getSocketDsn($config) : $this->getHostDsn($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given configuration array has a UNIX socket value.
|
||||
*
|
||||
* @param array $config
|
||||
* @return bool
|
||||
*/
|
||||
protected function configHasSocket(array $config)
|
||||
{
|
||||
return isset($config['unix_socket']) && ! empty($config['unix_socket']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DSN string for a socket configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getSocketDsn(array $config)
|
||||
{
|
||||
extract($config);
|
||||
|
||||
return "mysql:unix_socket={$config['unix_socket']};dbname={$database}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DSN string for a host / port configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getHostDsn(array $config)
|
||||
{
|
||||
extract($config);
|
||||
|
||||
return isset($config['port'])
|
||||
? "mysql:host={$host};port={$port};dbname={$database}"
|
||||
: "mysql:host={$host};dbname={$database}";
|
||||
}
|
||||
|
||||
}
|
96
vendor/illuminate/database/Connectors/PostgresConnector.php
vendored
Executable file
96
vendor/illuminate/database/Connectors/PostgresConnector.php
vendored
Executable file
@ -0,0 +1,96 @@
|
||||
<?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 $config
|
||||
* @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();
|
||||
|
||||
// Next, we will check to see if a timezone has been specified in this config
|
||||
// and if it has we will issue a statement to modify the timezone with the
|
||||
// database. Setting this DB timezone is an optional configuration item.
|
||||
if (isset($config['timezone']))
|
||||
{
|
||||
$timezone = $config['timezone'];
|
||||
|
||||
$connection->prepare("set time zone '$timezone'")->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}";
|
||||
}
|
||||
|
||||
if (isset($config['sslmode']))
|
||||
{
|
||||
$dsn .= ";sslmode={$sslmode}";
|
||||
}
|
||||
|
||||
return $dsn;
|
||||
}
|
||||
|
||||
}
|
40
vendor/illuminate/database/Connectors/SQLiteConnector.php
vendored
Executable file
40
vendor/illuminate/database/Connectors/SQLiteConnector.php
vendored
Executable file
@ -0,0 +1,40 @@
|
||||
<?php namespace Illuminate\Database\Connectors;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class SQLiteConnector extends Connector implements ConnectorInterface {
|
||||
|
||||
/**
|
||||
* Establish a database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \PDO
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
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 going any 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);
|
||||
}
|
||||
|
||||
}
|
142
vendor/illuminate/database/Connectors/SqlServerConnector.php
vendored
Executable file
142
vendor/illuminate/database/Connectors/SqlServerConnector.php
vendored
Executable file
@ -0,0 +1,142 @@
|
||||
<?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 $config
|
||||
* @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)
|
||||
{
|
||||
// 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.
|
||||
if (in_array('dblib', $this->getAvailableDrivers()))
|
||||
{
|
||||
return $this->getDblibDsn($config);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->getSqlSrvDsn($config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DSN string for a DbLib connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getDblibDsn(array $config)
|
||||
{
|
||||
$arguments = array(
|
||||
'host' => $this->buildHostString($config, ':'),
|
||||
'dbname' => $config['database']
|
||||
);
|
||||
|
||||
$arguments = array_merge(
|
||||
$arguments, array_only($config, ['appname', 'charset'])
|
||||
);
|
||||
|
||||
return $this->buildConnectString('dblib', $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DSN string for a SqlSrv connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getSqlSrvDsn(array $config)
|
||||
{
|
||||
$arguments = array(
|
||||
'Server' => $this->buildHostString($config, ',')
|
||||
);
|
||||
|
||||
if (isset($config['database'])) {
|
||||
$arguments['Database'] = $config['database'];
|
||||
}
|
||||
|
||||
if (isset($config['appname'])) {
|
||||
$arguments['APP'] = $config['appname'];
|
||||
}
|
||||
|
||||
return $this->buildConnectString('sqlsrv', $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a connection string from the given arguments.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param array $arguments
|
||||
* @return string
|
||||
*/
|
||||
protected function buildConnectString($driver, array $arguments)
|
||||
{
|
||||
$options = array_map(function($key) use ($arguments)
|
||||
{
|
||||
return sprintf("%s=%s", $key, $arguments[$key]);
|
||||
}, array_keys($arguments));
|
||||
|
||||
return $driver.":".implode(';', $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a host string from the given configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $separator
|
||||
* @return string
|
||||
*/
|
||||
protected function buildHostString(array $config, $separator)
|
||||
{
|
||||
if(isset($config['port']))
|
||||
{
|
||||
return $config['host'].$separator.$config['port'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $config['host'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the available PDO drivers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAvailableDrivers()
|
||||
{
|
||||
return PDO::getAvailableDrivers();
|
||||
}
|
||||
|
||||
}
|
17
vendor/illuminate/database/Console/Migrations/BaseCommand.php
vendored
Executable file
17
vendor/illuminate/database/Console/Migrations/BaseCommand.php
vendored
Executable file
@ -0,0 +1,17 @@
|
||||
<?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()
|
||||
{
|
||||
return $this->laravel->databasePath().'/migrations';
|
||||
}
|
||||
|
||||
}
|
69
vendor/illuminate/database/Console/Migrations/InstallCommand.php
vendored
Executable file
69
vendor/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\Migrations\MigrationRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Create a new migration install command instance.
|
||||
*
|
||||
* @param \Illuminate\Database\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.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
129
vendor/illuminate/database/Console/Migrations/MigrateCommand.php
vendored
Executable file
129
vendor/illuminate/database/Console/Migrations/MigrateCommand.php
vendored
Executable file
@ -0,0 +1,129 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\ConfirmableTrait;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class MigrateCommand extends BaseCommand {
|
||||
|
||||
use ConfirmableTrait;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Create a new migration 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()
|
||||
{
|
||||
if ( ! $this->confirmToProceed()) return;
|
||||
|
||||
$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');
|
||||
|
||||
// Next, 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 = $this->input->getOption('path')))
|
||||
{
|
||||
$path = $this->laravel->basePath().'/'.$path;
|
||||
}
|
||||
else
|
||||
{
|
||||
$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', ['--force' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
|
||||
|
||||
array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
|
||||
|
||||
array('path', null, InputOption::VALUE_OPTIONAL, 'The path of migrations files to be executed.'),
|
||||
|
||||
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.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
120
vendor/illuminate/database/Console/Migrations/MigrateMakeCommand.php
vendored
Executable file
120
vendor/illuminate/database/Console/Migrations/MigrateMakeCommand.php
vendored
Executable file
@ -0,0 +1,120 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Foundation\Composer;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Illuminate\Database\Migrations\MigrationCreator;
|
||||
|
||||
class MigrateMakeCommand extends BaseCommand {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'make:migration';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new migration file';
|
||||
|
||||
/**
|
||||
* The migration creator instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Migrations\MigrationCreator
|
||||
*/
|
||||
protected $creator;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Foundation\Composer
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* Create a new migration install command instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Migrations\MigrationCreator $creator
|
||||
* @param \Illuminate\Foundation\Composer $composer
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MigrationCreator $creator, Composer $composer)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->creator = $creator;
|
||||
$this->composer = $composer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
||||
if ( ! $table && is_string($create)) $table = $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->composer->dumpAutoloads();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('create', null, InputOption::VALUE_OPTIONAL, 'The table to be created.'),
|
||||
|
||||
array('table', null, InputOption::VALUE_OPTIONAL, 'The table to migrate.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
96
vendor/illuminate/database/Console/Migrations/RefreshCommand.php
vendored
Executable file
96
vendor/illuminate/database/Console/Migrations/RefreshCommand.php
vendored
Executable file
@ -0,0 +1,96 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Console\ConfirmableTrait;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class RefreshCommand extends Command {
|
||||
|
||||
use ConfirmableTrait;
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
if ( ! $this->confirmToProceed()) return;
|
||||
|
||||
$database = $this->input->getOption('database');
|
||||
|
||||
$force = $this->input->getOption('force');
|
||||
|
||||
$this->call('migrate:reset', array(
|
||||
'--database' => $database, '--force' => $force,
|
||||
));
|
||||
|
||||
// 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 re-seed the database.
|
||||
$this->call('migrate', array(
|
||||
'--database' => $database, '--force' => $force,
|
||||
));
|
||||
|
||||
if ($this->needsSeeding())
|
||||
{
|
||||
$this->runSeeder($database);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the developer has requested database seeding.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function needsSeeding()
|
||||
{
|
||||
return $this->option('seed') || $this->option('seeder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the database seeder command.
|
||||
*
|
||||
* @param string $database
|
||||
* @return void
|
||||
*/
|
||||
protected function runSeeder($database)
|
||||
{
|
||||
$class = $this->option('seeder') ?: 'DatabaseSeeder';
|
||||
|
||||
$this->call('db:seed', array('--database' => $database, '--class' => $class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
|
||||
|
||||
array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
|
||||
|
||||
array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'),
|
||||
|
||||
array('seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
86
vendor/illuminate/database/Console/Migrations/ResetCommand.php
vendored
Executable file
86
vendor/illuminate/database/Console/Migrations/ResetCommand.php
vendored
Executable file
@ -0,0 +1,86 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Console\ConfirmableTrait;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ResetCommand extends Command {
|
||||
|
||||
use ConfirmableTrait;
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
if ( ! $this->confirmToProceed()) return;
|
||||
|
||||
$this->migrator->setConnection($this->input->getOption('database'));
|
||||
|
||||
$pretend = $this->input->getOption('pretend');
|
||||
|
||||
$this->migrator->reset($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('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
|
||||
|
||||
array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
86
vendor/illuminate/database/Console/Migrations/RollbackCommand.php
vendored
Executable file
86
vendor/illuminate/database/Console/Migrations/RollbackCommand.php
vendored
Executable file
@ -0,0 +1,86 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Console\ConfirmableTrait;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class RollbackCommand extends Command {
|
||||
|
||||
use ConfirmableTrait;
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
if ( ! $this->confirmToProceed()) return;
|
||||
|
||||
$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('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
|
||||
|
||||
array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
82
vendor/illuminate/database/Console/Migrations/StatusCommand.php
vendored
Executable file
82
vendor/illuminate/database/Console/Migrations/StatusCommand.php
vendored
Executable file
@ -0,0 +1,82 @@
|
||||
<?php namespace Illuminate\Database\Console\Migrations;
|
||||
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
|
||||
class StatusCommand extends BaseCommand {
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:status';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Show the status of each 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 \Illuminate\Database\Console\Migrations\StatusCommand
|
||||
*/
|
||||
public function __construct(Migrator $migrator)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->migrator = $migrator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
if ( ! $this->migrator->repositoryExists())
|
||||
{
|
||||
return $this->error('No migrations found.');
|
||||
}
|
||||
|
||||
$ran = $this->migrator->getRepository()->getRan();
|
||||
|
||||
$migrations = [];
|
||||
|
||||
foreach ($this->getAllMigrationFiles() as $migration)
|
||||
{
|
||||
$migrations[] = in_array($migration, $ran) ? ['<info>Y</info>', $migration] : ['<fg=red>N</fg=red>', $migration];
|
||||
}
|
||||
|
||||
if (count($migrations) > 0)
|
||||
{
|
||||
$this->table(['Ran?', 'Migration'], $migrations);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error('No migrations found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the migration files.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllMigrationFiles()
|
||||
{
|
||||
return $this->migrator->getMigrationFiles($this->getMigrationPath());
|
||||
}
|
||||
|
||||
}
|
100
vendor/illuminate/database/Console/SeedCommand.php
vendored
Executable file
100
vendor/illuminate/database/Console/SeedCommand.php
vendored
Executable file
@ -0,0 +1,100 @@
|
||||
<?php namespace Illuminate\Database\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Console\ConfirmableTrait;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Illuminate\Database\ConnectionResolverInterface as Resolver;
|
||||
|
||||
class SeedCommand extends Command {
|
||||
|
||||
use ConfirmableTrait;
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
if ( ! $this->confirmToProceed()) return;
|
||||
|
||||
$this->resolver->setDefaultConnection($this->getDatabase());
|
||||
|
||||
$this->getSeeder()->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'),
|
||||
|
||||
array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
307
vendor/illuminate/database/DatabaseManager.php
vendored
Executable file
307
vendor/illuminate/database/DatabaseManager.php
vendored
Executable file
@ -0,0 +1,307 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use InvalidArgumentException;
|
||||
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)
|
||||
{
|
||||
list($name, $type) = $this->parseConnectionName($name);
|
||||
|
||||
// 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->setPdoForType($connection, $type);
|
||||
|
||||
$this->connections[$name] = $this->prepare($connection);
|
||||
}
|
||||
|
||||
return $this->connections[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the connection into an array of the name and read / write type.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function parseConnectionName($name)
|
||||
{
|
||||
$name = $name ?: $this->getDefaultConnection();
|
||||
|
||||
return Str::endsWith($name, ['::read', '::write'])
|
||||
? explode('::', $name, 2) : [$name, null];
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the given database and remove from local cache.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function purge($name = null)
|
||||
{
|
||||
$this->disconnect($name);
|
||||
|
||||
unset($this->connections[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the given database.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect($name = null)
|
||||
{
|
||||
if (isset($this->connections[$name = $name ?: $this->getDefaultConnection()]))
|
||||
{
|
||||
$this->connections[$name]->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnect to the given database.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function reconnect($name = null)
|
||||
{
|
||||
$this->disconnect($name = $name ?: $this->getDefaultConnection());
|
||||
|
||||
if ( ! isset($this->connections[$name]))
|
||||
{
|
||||
return $this->connection($name);
|
||||
}
|
||||
|
||||
return $this->refreshPdoConnections($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the PDO connections on a given connection.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
protected function refreshPdoConnections($name)
|
||||
{
|
||||
$fresh = $this->makeConnection($name);
|
||||
|
||||
return $this->connections[$name]
|
||||
->setPdo($fresh->getPdo())
|
||||
->setReadPdo($fresh->getReadPdo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, $name);
|
||||
}
|
||||
|
||||
$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, $name);
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
// Here we'll set a reconnector callback. This reconnector can be any callable
|
||||
// so we will set a Closure to reconnect from this manager with the name of
|
||||
// the connection, which will allow us to reconnect from the connections.
|
||||
$connection->setReconnector(function($connection)
|
||||
{
|
||||
$this->reconnect($connection->getName());
|
||||
});
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the read write mode for database connection instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @param string $type
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
protected function setPdoForType(Connection $connection, $type = null)
|
||||
{
|
||||
if ($type == 'read')
|
||||
{
|
||||
$connection->setPdo($connection->getReadPdo());
|
||||
}
|
||||
elseif ($type == 'write')
|
||||
{
|
||||
$connection->setReadPdo($connection->getPdo());
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration for a connection.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
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, callable $resolver)
|
||||
{
|
||||
$this->extensions[$name] = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the created connections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConnections()
|
||||
{
|
||||
return $this->connections;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
61
vendor/illuminate/database/DatabaseServiceProvider.php
vendored
Executable file
61
vendor/illuminate/database/DatabaseServiceProvider.php
vendored
Executable file
@ -0,0 +1,61 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Database\Eloquent\QueueEntityResolver;
|
||||
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()
|
||||
{
|
||||
$this->registerQueueableEntityResolver();
|
||||
|
||||
// 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->singleton('db.factory', 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->singleton('db', function($app)
|
||||
{
|
||||
return new DatabaseManager($app, $app['db.factory']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the queueable entity resolver implementation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerQueueableEntityResolver()
|
||||
{
|
||||
$this->app->singleton('Illuminate\Contracts\Queue\EntityResolver', function()
|
||||
{
|
||||
return new QueueEntityResolver;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
948
vendor/illuminate/database/Eloquent/Builder.php
vendored
Executable file
948
vendor/illuminate/database/Eloquent/Builder.php
vendored
Executable file
@ -0,0 +1,948 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
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();
|
||||
|
||||
/**
|
||||
* All of the registered builder macros.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $macros = array();
|
||||
|
||||
/**
|
||||
* A replacement for the typical delete function.
|
||||
*
|
||||
* @var \Closure
|
||||
*/
|
||||
protected $onDelete;
|
||||
|
||||
/**
|
||||
* 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', 'getBindings',
|
||||
);
|
||||
|
||||
/**
|
||||
* 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|\Illuminate\Database\Eloquent\Collection|null
|
||||
*/
|
||||
public function find($id, $columns = array('*'))
|
||||
{
|
||||
if (is_array($id))
|
||||
{
|
||||
return $this->findMany($id, $columns);
|
||||
}
|
||||
|
||||
$this->query->where($this->model->getQualifiedKeyName(), '=', $id);
|
||||
|
||||
return $this->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a model by its primary key.
|
||||
*
|
||||
* @param array $ids
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function findMany($ids, $columns = array('*'))
|
||||
{
|
||||
if (empty($ids)) return $this->model->newCollection();
|
||||
|
||||
$this->query->whereIn($this->model->getQualifiedKeyName(), $ids);
|
||||
|
||||
return $this->get($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a model by its primary key or throw an exception.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*/
|
||||
public function findOrFail($id, $columns = array('*'))
|
||||
{
|
||||
$result = $this->find($id, $columns);
|
||||
|
||||
if (is_array($id))
|
||||
{
|
||||
if (count($result) == count(array_unique($id))) return $result;
|
||||
}
|
||||
elseif ( ! is_null($result))
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
throw (new ModelNotFoundException)->setModel(get_class($this->model));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*/
|
||||
public function firstOrFail($columns = array('*'))
|
||||
{
|
||||
if ( ! is_null($model = $this->first($columns))) return $model;
|
||||
|
||||
throw (new ModelNotFoundException)->setModel(get_class($this->model));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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};
|
||||
}
|
||||
|
||||
/**
|
||||
* Chunk the results of the query.
|
||||
*
|
||||
* @param int $count
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public function chunk($count, callable $callback)
|
||||
{
|
||||
$results = $this->forPage($page = 1, $count)->get();
|
||||
|
||||
while (count($results) > 0)
|
||||
{
|
||||
// On each chunk result set, we will pass them to the callback and then let the
|
||||
// developer take care of everything within the callback, which allows us to
|
||||
// keep the memory low for spinning through large result sets for working.
|
||||
call_user_func($callback, $results);
|
||||
|
||||
$page++;
|
||||
|
||||
$results = $this->forPage($page, $count)->get();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginate the given query.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function paginate($perPage = null, $columns = ['*'])
|
||||
{
|
||||
$total = $this->query->getCountForPagination();
|
||||
|
||||
$this->query->forPage(
|
||||
$page = Paginator::resolveCurrentPage(),
|
||||
$perPage = $perPage ?: $this->model->getPerPage()
|
||||
);
|
||||
|
||||
return new LengthAwarePaginator($this->get($columns), $total, $perPage, $page, [
|
||||
'path' => Paginator::resolveCurrentPath(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginate the given query into a simple paginator.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Contracts\Pagination\Paginator
|
||||
*/
|
||||
public function simplePaginate($perPage = null, $columns = ['*'])
|
||||
{
|
||||
$page = Paginator::resolveCurrentPage();
|
||||
|
||||
$perPage = $perPage ?: $this->model->getPerPage();
|
||||
|
||||
$this->skip(($page - 1) * $perPage)->take($perPage + 1);
|
||||
|
||||
return new Paginator($this->get($columns), $perPage, $page, [
|
||||
'path' => Paginator::resolveCurrentPath(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 mixed
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if (isset($this->onDelete))
|
||||
{
|
||||
return call_user_func($this->onDelete, $this);
|
||||
}
|
||||
|
||||
return $this->query->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the default delete function on the builder.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function forceDelete()
|
||||
{
|
||||
return $this->query->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a replacement for the default delete function.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return void
|
||||
*/
|
||||
public function onDelete(Closure $callback)
|
||||
{
|
||||
$this->onDelete = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hydrated models without eager loading.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Model[]
|
||||
*/
|
||||
public function getModels($columns = array('*'))
|
||||
{
|
||||
$results = $this->query->get($columns);
|
||||
|
||||
$connection = $this->model->getConnectionName();
|
||||
|
||||
return $this->model->hydrate($results, $connection)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->getEager();
|
||||
|
||||
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)
|
||||
{
|
||||
// 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 ($relation)
|
||||
{
|
||||
return $this->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 && starts_with($name, $relation.'.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a basic where clause to the query.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $operator
|
||||
* @param mixed $value
|
||||
* @param string $boolean
|
||||
* @return $this
|
||||
*/
|
||||
public function where($column, $operator = null, $value = null, $boolean = 'and')
|
||||
{
|
||||
if ($column instanceof Closure)
|
||||
{
|
||||
$query = $this->model->newQueryWithoutScopes();
|
||||
|
||||
call_user_func($column, $query);
|
||||
|
||||
$this->query->addNestedWhereQuery($query->getQuery(), $boolean);
|
||||
}
|
||||
else
|
||||
{
|
||||
call_user_func_array(array($this->query, 'where'), func_get_args());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an "or where" clause to the query.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $operator
|
||||
* @param mixed $value
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function orWhere($column, $operator = null, $value = null)
|
||||
{
|
||||
return $this->where($column, $operator, $value, 'or');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a relationship count condition to the query.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @param \Closure|null $callback
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null)
|
||||
{
|
||||
if (strpos($relation, '.') !== false)
|
||||
{
|
||||
return $this->hasNested($relation, $operator, $count, $boolean, $callback);
|
||||
}
|
||||
|
||||
$relation = $this->getHasRelationQuery($relation);
|
||||
|
||||
$query = $relation->getRelationCountQuery($relation->getRelated()->newQuery(), $this);
|
||||
|
||||
if ($callback) call_user_func($callback, $query);
|
||||
|
||||
return $this->addHasWhere($query, $relation, $operator, $count, $boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add nested relationship count conditions to the query.
|
||||
*
|
||||
* @param string $relations
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @param \Closure $callback
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
protected function hasNested($relations, $operator = '>=', $count = 1, $boolean = 'and', $callback = null)
|
||||
{
|
||||
$relations = explode('.', $relations);
|
||||
|
||||
// In order to nest "has", we need to add count relation constraints on the
|
||||
// callback Closure. We'll do this by simply passing the Closure its own
|
||||
// reference to itself so it calls itself recursively on each segment.
|
||||
$closure = function ($q) use (&$closure, &$relations, $operator, $count, $boolean, $callback)
|
||||
{
|
||||
if (count($relations) > 1)
|
||||
{
|
||||
$q->whereHas(array_shift($relations), $closure);
|
||||
}
|
||||
else
|
||||
{
|
||||
$q->has(array_shift($relations), $operator, $count, 'and', $callback);
|
||||
}
|
||||
};
|
||||
|
||||
return $this->has(array_shift($relations), '>=', 1, $boolean, $closure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a relationship count condition to the query.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $boolean
|
||||
* @param \Closure|null $callback
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function doesntHave($relation, $boolean = 'and', Closure $callback = null)
|
||||
{
|
||||
return $this->has($relation, '<', 1, $boolean, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a relationship count condition to the query with where clauses.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param \Closure $callback
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function whereHas($relation, Closure $callback, $operator = '>=', $count = 1)
|
||||
{
|
||||
return $this->has($relation, $operator, $count, 'and', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a relationship count condition to the query with where clauses.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param \Closure|null $callback
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function whereDoesntHave($relation, Closure $callback = null)
|
||||
{
|
||||
return $this->doesntHave($relation, 'and', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a relationship count condition to the query with where clauses and an "or".
|
||||
*
|
||||
* @param string $relation
|
||||
* @param \Closure $callback
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public function orWhereHas($relation, Closure $callback, $operator = '>=', $count = 1)
|
||||
{
|
||||
return $this->has($relation, $operator, $count, 'or', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the "has" condition where clause to the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $hasQuery
|
||||
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, $count, $boolean)
|
||||
{
|
||||
$this->mergeWheresToHas($hasQuery, $relation);
|
||||
|
||||
if (is_numeric($count))
|
||||
{
|
||||
$count = new Expression($count);
|
||||
}
|
||||
|
||||
return $this->where(new Expression('('.$hasQuery->toSql().')'), $operator, $count, $boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the "wheres" from a relation query to a has query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $hasQuery
|
||||
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation
|
||||
* @return void
|
||||
*/
|
||||
protected function mergeWheresToHas(Builder $hasQuery, Relation $relation)
|
||||
{
|
||||
// Here we have the "has" query and the original relation. We need to copy over any
|
||||
// where clauses the developer may have put in the relationship function over to
|
||||
// the has query, and then copy the bindings from the "has" query to the main.
|
||||
$relationQuery = $relation->getBaseQuery();
|
||||
|
||||
$hasQuery = $hasQuery->getModel()->removeGlobalScopes($hasQuery);
|
||||
|
||||
$hasQuery->mergeWheres(
|
||||
$relationQuery->wheres, $relationQuery->getBindings()
|
||||
);
|
||||
|
||||
$this->query->mergeBindings($hasQuery->getQuery());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "has relation" base query instance.
|
||||
*
|
||||
* @param string $relation
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function getHasRelationQuery($relation)
|
||||
{
|
||||
return Relation::noConstraints(function() use ($relation)
|
||||
{
|
||||
return $this->getModel()->$relation();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the relationships that should be eager loaded.
|
||||
*
|
||||
* @param mixed $relations
|
||||
* @return $this
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the given model scope on the underlying model.
|
||||
*
|
||||
* @param string $scope
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected function callScope($scope, $parameters)
|
||||
{
|
||||
array_unshift($parameters, $this);
|
||||
|
||||
return call_user_func_array(array($this->model, $scope), $parameters) ?: $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $this
|
||||
*/
|
||||
public function setQuery($query)
|
||||
{
|
||||
$this->query = $query;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relationships being eagerly loaded.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEagerLoads()
|
||||
{
|
||||
return $this->eagerLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the relationships being eagerly loaded.
|
||||
*
|
||||
* @param array $eagerLoad
|
||||
* @return $this
|
||||
*/
|
||||
public function setEagerLoads(array $eagerLoad)
|
||||
{
|
||||
$this->eagerLoad = $eagerLoad;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $this
|
||||
*/
|
||||
public function setModel(Model $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
|
||||
$this->query->from($model->getTable());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the builder with a given callback.
|
||||
*
|
||||
* @param string $name
|
||||
* @param \Closure $callback
|
||||
* @return void
|
||||
*/
|
||||
public function macro($name, Closure $callback)
|
||||
{
|
||||
$this->macros[$name] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the given macro by name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Closure
|
||||
*/
|
||||
public function getMacro($name)
|
||||
{
|
||||
return array_get($this->macros, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically handle calls into the query instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (isset($this->macros[$method]))
|
||||
{
|
||||
array_unshift($parameters, $this);
|
||||
|
||||
return call_user_func_array($this->macros[$method], $parameters);
|
||||
}
|
||||
elseif (method_exists($this->model, $scope = 'scope'.ucfirst($method)))
|
||||
{
|
||||
return $this->callScope($scope, $parameters);
|
||||
}
|
||||
|
||||
$result = call_user_func_array(array($this->query, $method), $parameters);
|
||||
|
||||
return in_array($method, $this->passthru) ? $result : $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a clone of the underlying query builder when cloning.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$this->query = clone $this->query;
|
||||
}
|
||||
|
||||
}
|
266
vendor/illuminate/database/Eloquent/Collection.php
vendored
Executable file
266
vendor/illuminate/database/Eloquent/Collection.php
vendored
Executable file
@ -0,0 +1,266 @@
|
||||
<?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)
|
||||
{
|
||||
if ($key instanceof Model)
|
||||
{
|
||||
$key = $key->getKey();
|
||||
}
|
||||
|
||||
return array_first($this->items, function($itemKey, $model) use ($key)
|
||||
{
|
||||
return $model->getKey() == $key;
|
||||
|
||||
}, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a set of relationships onto the collection.
|
||||
*
|
||||
* @param mixed $relations
|
||||
* @return $this
|
||||
*/
|
||||
public function load($relations)
|
||||
{
|
||||
if (count($this->items) > 0)
|
||||
{
|
||||
if (is_string($relations)) $relations = func_get_args();
|
||||
|
||||
$query = $this->first()->newQuery()->with($relations);
|
||||
|
||||
$this->items = $query->eagerLoadRelations($this->items);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to the collection.
|
||||
*
|
||||
* @param mixed $item
|
||||
* @return $this
|
||||
*/
|
||||
public function add($item)
|
||||
{
|
||||
$this->items[] = $item;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a key exists in the collection.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function contains($key, $value = null)
|
||||
{
|
||||
if (func_num_args() == 2) return parent::contains($key, $value);
|
||||
|
||||
if ( ! $this->useAsCallable($key))
|
||||
{
|
||||
$key = $key instanceof Model ? $key->getKey() : $key;
|
||||
|
||||
return parent::contains(function($k, $m) use ($key)
|
||||
{
|
||||
return $m->getKey() == $key;
|
||||
});
|
||||
}
|
||||
|
||||
return parent::contains($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a nested element of the collection.
|
||||
*
|
||||
* @param string $key
|
||||
* @return static
|
||||
*/
|
||||
public function fetch($key)
|
||||
{
|
||||
return new static(array_fetch($this->toArray(), $key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the max value of a given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function max($key)
|
||||
{
|
||||
return $this->reduce(function($result, $item) use ($key)
|
||||
{
|
||||
return is_null($result) || $item->{$key} > $result ? $item->{$key} : $result;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the min value of a given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function min($key)
|
||||
{
|
||||
return $this->reduce(function($result, $item) use ($key)
|
||||
{
|
||||
return is_null($result) || $item->{$key} < $result ? $item->{$key} : $result;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of primary keys.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function modelKeys()
|
||||
{
|
||||
return array_map(function($m) { return $m->getKey(); }, $this->items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the collection with the given items.
|
||||
*
|
||||
* @param \ArrayAccess|array $items
|
||||
* @return static
|
||||
*/
|
||||
public function merge($items)
|
||||
{
|
||||
$dictionary = $this->getDictionary();
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$dictionary[$item->getKey()] = $item;
|
||||
}
|
||||
|
||||
return new static(array_values($dictionary));
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff the collection with the given items.
|
||||
*
|
||||
* @param \ArrayAccess|array $items
|
||||
* @return static
|
||||
*/
|
||||
public function diff($items)
|
||||
{
|
||||
$diff = new static;
|
||||
|
||||
$dictionary = $this->getDictionary($items);
|
||||
|
||||
foreach ($this->items as $item)
|
||||
{
|
||||
if ( ! isset($dictionary[$item->getKey()]))
|
||||
{
|
||||
$diff->add($item);
|
||||
}
|
||||
}
|
||||
|
||||
return $diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect the collection with the given items.
|
||||
*
|
||||
* @param \ArrayAccess|array $items
|
||||
* @return static
|
||||
*/
|
||||
public function intersect($items)
|
||||
{
|
||||
$intersect = new static;
|
||||
|
||||
$dictionary = $this->getDictionary($items);
|
||||
|
||||
foreach ($this->items as $item)
|
||||
{
|
||||
if (isset($dictionary[$item->getKey()]))
|
||||
{
|
||||
$intersect->add($item);
|
||||
}
|
||||
}
|
||||
|
||||
return $intersect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only unique items from the collection.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function unique()
|
||||
{
|
||||
$dictionary = $this->getDictionary();
|
||||
|
||||
return new static(array_values($dictionary));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns only the models from the collection with the specified keys.
|
||||
*
|
||||
* @param mixed $keys
|
||||
* @return static
|
||||
*/
|
||||
public function only($keys)
|
||||
{
|
||||
$dictionary = array_only($this->getDictionary(), $keys);
|
||||
|
||||
return new static(array_values($dictionary));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all models in the collection except the models with specified keys.
|
||||
*
|
||||
* @param mixed $keys
|
||||
* @return static
|
||||
*/
|
||||
public function except($keys)
|
||||
{
|
||||
$dictionary = array_except($this->getDictionary(), $keys);
|
||||
|
||||
return new static(array_values($dictionary));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a dictionary keyed by primary keys.
|
||||
*
|
||||
* @param \ArrayAccess|array $items
|
||||
* @return array
|
||||
*/
|
||||
public function getDictionary($items = null)
|
||||
{
|
||||
$items = is_null($items) ? $this->items : $items;
|
||||
|
||||
$dictionary = array();
|
||||
|
||||
foreach ($items as $value)
|
||||
{
|
||||
$dictionary[$value->getKey()] = $value;
|
||||
}
|
||||
|
||||
return $dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a base Support collection instance from this collection.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function toBase()
|
||||
{
|
||||
return new BaseCollection($this->items);
|
||||
}
|
||||
|
||||
}
|
5
vendor/illuminate/database/Eloquent/MassAssignmentException.php
vendored
Executable file
5
vendor/illuminate/database/Eloquent/MassAssignmentException.php
vendored
Executable file
@ -0,0 +1,5 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class MassAssignmentException extends RuntimeException {}
|
3399
vendor/illuminate/database/Eloquent/Model.php
vendored
Executable file
3399
vendor/illuminate/database/Eloquent/Model.php
vendored
Executable file
File diff suppressed because it is too large
Load Diff
39
vendor/illuminate/database/Eloquent/ModelNotFoundException.php
vendored
Executable file
39
vendor/illuminate/database/Eloquent/ModelNotFoundException.php
vendored
Executable file
@ -0,0 +1,39 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class ModelNotFoundException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Name of the affected Eloquent model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Set the affected Eloquent model.
|
||||
*
|
||||
* @param string $model
|
||||
* @return $this
|
||||
*/
|
||||
public function setModel($model)
|
||||
{
|
||||
$this->model = $model;
|
||||
|
||||
$this->message = "No query results for model [{$model}].";
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the affected Eloquent model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
}
|
27
vendor/illuminate/database/Eloquent/QueueEntityResolver.php
vendored
Executable file
27
vendor/illuminate/database/Eloquent/QueueEntityResolver.php
vendored
Executable file
@ -0,0 +1,27 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
use Illuminate\Contracts\Queue\EntityNotFoundException;
|
||||
use Illuminate\Contracts\Queue\EntityResolver as EntityResolverContract;
|
||||
|
||||
class QueueEntityResolver implements EntityResolverContract {
|
||||
|
||||
/**
|
||||
* Resolve the entity for the given ID.
|
||||
*
|
||||
* @param string $type
|
||||
* @param mixed $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function resolve($type, $id)
|
||||
{
|
||||
$instance = (new $type)->find($id);
|
||||
|
||||
if ($instance)
|
||||
{
|
||||
return $instance;
|
||||
}
|
||||
|
||||
throw new EntityNotFoundException($type, $id);
|
||||
}
|
||||
|
||||
}
|
310
vendor/illuminate/database/Eloquent/Relations/BelongsTo.php
vendored
Executable file
310
vendor/illuminate/database/Eloquent/Relations/BelongsTo.php
vendored
Executable file
@ -0,0 +1,310 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class BelongsTo extends Relation {
|
||||
|
||||
/**
|
||||
* The foreign key of the parent model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $foreignKey;
|
||||
|
||||
/**
|
||||
* The associated key on the parent model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $otherKey;
|
||||
|
||||
/**
|
||||
* The name of the relationship.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $relation;
|
||||
|
||||
/**
|
||||
* Create a new belongs to relationship instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $otherKey
|
||||
* @param string $relation
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $relation)
|
||||
{
|
||||
$this->otherKey = $otherKey;
|
||||
$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.
|
||||
$table = $this->related->getTable();
|
||||
|
||||
$this->query->where($table.'.'.$this->otherKey, '=', $this->parent->{$this->foreignKey});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $parent
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query, Builder $parent)
|
||||
{
|
||||
if ($parent->getQuery()->from == $query->getQuery()->from)
|
||||
{
|
||||
return $this->getRelationCountQueryForSelfRelation($query, $parent);
|
||||
}
|
||||
|
||||
$query->select(new Expression('count(*)'));
|
||||
|
||||
$otherKey = $this->wrap($query->getModel()->getTable().'.'.$this->otherKey);
|
||||
|
||||
return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query on the same table.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $parent
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQueryForSelfRelation(Builder $query, Builder $parent)
|
||||
{
|
||||
$query->select(new Expression('count(*)'));
|
||||
|
||||
$tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix();
|
||||
|
||||
$query->from($query->getModel()->getTable().' as '.$tablePrefix.$hash = $this->getRelationCountHash());
|
||||
|
||||
$key = $this->wrap($this->getQualifiedForeignKey());
|
||||
|
||||
return $query->where($hash.'.'.$query->getModel()->getKeyName(), '=', new Expression($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a relationship join table hash.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRelationCountHash()
|
||||
{
|
||||
return 'self_'.md5(microtime(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->getTable().'.'.$this->otherKey;
|
||||
|
||||
$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 array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
{
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$model->setRelation($relation, null);
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
{
|
||||
$foreign = $this->foreignKey;
|
||||
|
||||
$other = $this->otherKey;
|
||||
|
||||
// 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->getAttribute($other)] = $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->getAttribute($this->otherKey));
|
||||
|
||||
return $this->parent->setRelation($this->relation, $model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dissociate previously associated model from the given parent.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function dissociate()
|
||||
{
|
||||
$this->parent->setAttribute($this->foreignKey, null);
|
||||
|
||||
return $this->parent->setRelation($this->relation, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully qualified foreign key of the relationship.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQualifiedForeignKey()
|
||||
{
|
||||
return $this->parent->getTable().'.'.$this->foreignKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the associated key of the relationship.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOtherKey()
|
||||
{
|
||||
return $this->otherKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully qualified associated key of the relationship.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQualifiedOtherKeyName()
|
||||
{
|
||||
return $this->related->getTable().'.'.$this->otherKey;
|
||||
}
|
||||
|
||||
}
|
1195
vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php
vendored
Executable file
1195
vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php
vendored
Executable file
File diff suppressed because it is too large
Load Diff
47
vendor/illuminate/database/Eloquent/Relations/HasMany.php
vendored
Executable file
47
vendor/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 array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
{
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$model->setRelation($relation, $this->related->newCollection());
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
{
|
||||
return $this->matchMany($models, $results, $relation);
|
||||
}
|
||||
|
||||
}
|
340
vendor/illuminate/database/Eloquent/Relations/HasManyThrough.php
vendored
Executable file
340
vendor/illuminate/database/Eloquent/Relations/HasManyThrough.php
vendored
Executable file
@ -0,0 +1,340 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class HasManyThrough extends Relation {
|
||||
|
||||
/**
|
||||
* The distance parent model instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
protected $farParent;
|
||||
|
||||
/**
|
||||
* The near key on the relationship.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $firstKey;
|
||||
|
||||
/**
|
||||
* The far key on the relationship.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $secondKey;
|
||||
|
||||
/**
|
||||
* Create a new has many through relationship instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Model $farParent
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @param string $firstKey
|
||||
* @param string $secondKey
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $farParent, Model $parent, $firstKey, $secondKey)
|
||||
{
|
||||
$this->firstKey = $firstKey;
|
||||
$this->secondKey = $secondKey;
|
||||
$this->farParent = $farParent;
|
||||
|
||||
parent::__construct($query, $parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
$parentTable = $this->parent->getTable();
|
||||
|
||||
$this->setJoin();
|
||||
|
||||
if (static::$constraints)
|
||||
{
|
||||
$this->query->where($parentTable.'.'.$this->firstKey, '=', $this->farParent->getKey());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $parent
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query, Builder $parent)
|
||||
{
|
||||
$parentTable = $this->parent->getTable();
|
||||
|
||||
$this->setJoin($query);
|
||||
|
||||
$query->select(new Expression('count(*)'));
|
||||
|
||||
$key = $this->wrap($parentTable.'.'.$this->firstKey);
|
||||
|
||||
return $query->where($this->getHasCompareKey(), '=', new Expression($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the join clause on the query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder|null $query
|
||||
* @return void
|
||||
*/
|
||||
protected function setJoin(Builder $query = null)
|
||||
{
|
||||
$query = $query ?: $this->query;
|
||||
|
||||
$foreignKey = $this->related->getTable().'.'.$this->secondKey;
|
||||
|
||||
$query->join($this->parent->getTable(), $this->getQualifiedParentKeyName(), '=', $foreignKey);
|
||||
|
||||
if ($this->parentSoftDeletes())
|
||||
{
|
||||
$query->whereNull($this->parent->getQualifiedDeletedAtColumn());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether close parent of the relation uses Soft Deletes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function parentSoftDeletes()
|
||||
{
|
||||
return in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses_recursive(get_class($this->parent)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
$table = $this->parent->getTable();
|
||||
|
||||
$this->query->whereIn($table.'.'.$this->firstKey, $this->getKeys($models));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
{
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$model->setRelation($relation, $this->related->newCollection());
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
{
|
||||
$dictionary = $this->buildDictionary($results);
|
||||
|
||||
// Once we have the dictionary we can simply spin through the parent models to
|
||||
// link them up with their children using the keyed dictionary to make the
|
||||
// matching very convenient and easy work. Then we'll just return them.
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$key = $model->getKey();
|
||||
|
||||
if (isset($dictionary[$key]))
|
||||
{
|
||||
$value = $this->related->newCollection($dictionary[$key]);
|
||||
|
||||
$model->setRelation($relation, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build model dictionary keyed by the relation's foreign key.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @return array
|
||||
*/
|
||||
protected function buildDictionary(Collection $results)
|
||||
{
|
||||
$dictionary = [];
|
||||
|
||||
$foreign = $this->firstKey;
|
||||
|
||||
// First we will create a dictionary of models keyed by the foreign key of the
|
||||
// relationship as this will allow us to quickly access all of the related
|
||||
// models without having to do nested looping which will be quite slow.
|
||||
foreach ($results as $result)
|
||||
{
|
||||
$dictionary[$result->{$foreign}][] = $result;
|
||||
}
|
||||
|
||||
return $dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
return $this->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query and get the first related model.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return mixed
|
||||
*/
|
||||
public function first($columns = ['*'])
|
||||
{
|
||||
$results = $this->take(1)->get($columns);
|
||||
|
||||
return count($results) > 0 ? $results->first() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a related model by its primary key.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|null
|
||||
*/
|
||||
public function find($id, $columns = ['*'])
|
||||
{
|
||||
if (is_array($id))
|
||||
{
|
||||
return $this->findMany($id, $columns);
|
||||
}
|
||||
|
||||
$this->where($this->getRelated()->getQualifiedKeyName(), '=', $id);
|
||||
|
||||
return $this->first($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find multiple related models by their primary keys.
|
||||
*
|
||||
* @param mixed $ids
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function findMany($ids, $columns = ['*'])
|
||||
{
|
||||
if (empty($ids)) return $this->getRelated()->newCollection();
|
||||
|
||||
$this->whereIn($this->getRelated()->getQualifiedKeyName(), $ids);
|
||||
|
||||
return $this->get($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query as a "select" statement.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function get($columns = ['*'])
|
||||
{
|
||||
// First we'll add the proper select columns onto the query so it is run with
|
||||
// the proper columns. Then, we will get the results and hydrate out pivot
|
||||
// models with the result of those columns as a separate model relation.
|
||||
$columns = $this->query->getQuery()->columns ? [] : $columns;
|
||||
|
||||
$select = $this->getSelectColumns($columns);
|
||||
|
||||
$models = $this->query->addSelect($select)->getModels();
|
||||
|
||||
// If we actually found models we will also eager load any relationships that
|
||||
// have been specified as needing to be eager loaded. This will solve the
|
||||
// n + 1 query problem for the developer and also increase performance.
|
||||
if (count($models) > 0)
|
||||
{
|
||||
$models = $this->query->eagerLoadRelations($models);
|
||||
}
|
||||
|
||||
return $this->related->newCollection($models);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the select clause for the relation query.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
protected function getSelectColumns(array $columns = ['*'])
|
||||
{
|
||||
if ($columns == ['*'])
|
||||
{
|
||||
$columns = [$this->related->getTable().'.*'];
|
||||
}
|
||||
|
||||
return array_merge($columns, [$this->parent->getTable().'.'.$this->firstKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a paginator for the "select" statement.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function paginate($perPage = null, $columns = ['*'])
|
||||
{
|
||||
$this->query->addSelect($this->getSelectColumns($columns));
|
||||
|
||||
return $this->query->paginate($perPage, $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginate the given query into a simple paginator.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Contracts\Pagination\Paginator
|
||||
*/
|
||||
public function simplePaginate($perPage = null, $columns = ['*'])
|
||||
{
|
||||
$this->query->addSelect($this->getSelectColumns($columns));
|
||||
|
||||
return $this->query->simplePaginate($perPage, $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key for comparing against the parent key in "has" query.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHasCompareKey()
|
||||
{
|
||||
return $this->farParent->getQualifiedKeyName();
|
||||
}
|
||||
|
||||
}
|
47
vendor/illuminate/database/Eloquent/Relations/HasOne.php
vendored
Executable file
47
vendor/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 array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
{
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$model->setRelation($relation, null);
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
{
|
||||
return $this->matchOne($models, $results, $relation);
|
||||
}
|
||||
|
||||
}
|
412
vendor/illuminate/database/Eloquent/Relations/HasOneOrMany.php
vendored
Executable file
412
vendor/illuminate/database/Eloquent/Relations/HasOneOrMany.php
vendored
Executable file
@ -0,0 +1,412 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* The local key of the parent model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $localKey;
|
||||
|
||||
/**
|
||||
* Create a new has one or many relationship instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $foreignKey, $localKey)
|
||||
{
|
||||
$this->localKey = $localKey;
|
||||
$this->foreignKey = $foreignKey;
|
||||
|
||||
parent::__construct($query, $parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
if (static::$constraints)
|
||||
{
|
||||
$this->query->where($this->foreignKey, '=', $this->getParentKey());
|
||||
|
||||
$this->query->whereNotNull($this->foreignKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $parent
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query, Builder $parent)
|
||||
{
|
||||
if ($parent->getQuery()->from == $query->getQuery()->from)
|
||||
{
|
||||
return $this->getRelationCountQueryForSelfRelation($query, $parent);
|
||||
}
|
||||
|
||||
return parent::getRelationCountQuery($query, $parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query on the same table.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $parent
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQueryForSelfRelation(Builder $query, Builder $parent)
|
||||
{
|
||||
$query->select(new Expression('count(*)'));
|
||||
|
||||
$tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix();
|
||||
|
||||
$query->from($query->getModel()->getTable().' as '.$tablePrefix.$hash = $this->getRelationCountHash());
|
||||
|
||||
$key = $this->wrap($this->getQualifiedParentKeyName());
|
||||
|
||||
return $query->where($hash.'.'.$this->getPlainForeignKey(), '=', new Expression($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a relationship join table hash.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRelationCountHash()
|
||||
{
|
||||
return 'self_'.md5(microtime(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
$this->query->whereIn($this->foreignKey, $this->getKeys($models, $this->localKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their single parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function matchOne(array $models, Collection $results, $relation)
|
||||
{
|
||||
return $this->matchOneOrMany($models, $results, $relation, 'one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their many parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function matchMany(array $models, Collection $results, $relation)
|
||||
{
|
||||
return $this->matchOneOrMany($models, $results, $relation, 'many');
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their many parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function matchOneOrMany(array $models, Collection $results, $relation, $type)
|
||||
{
|
||||
$dictionary = $this->buildDictionary($results);
|
||||
|
||||
// Once we have the dictionary we can simply spin through the parent models to
|
||||
// link them up with their children using the keyed dictionary to make the
|
||||
// matching very convenient and easy work. Then we'll just return them.
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$key = $model->getAttribute($this->localKey);
|
||||
|
||||
if (isset($dictionary[$key]))
|
||||
{
|
||||
$value = $this->getRelationValue($dictionary, $key, $type);
|
||||
|
||||
$model->setRelation($relation, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a relationship by one or many type.
|
||||
*
|
||||
* @param array $dictionary
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getRelationValue(array $dictionary, $key, $type)
|
||||
{
|
||||
$value = $dictionary[$key];
|
||||
|
||||
return $type == 'one' ? reset($value) : $this->related->newCollection($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build model dictionary keyed by the relation's foreign key.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @return array
|
||||
*/
|
||||
protected function buildDictionary(Collection $results)
|
||||
{
|
||||
$dictionary = array();
|
||||
|
||||
$foreign = $this->getPlainForeignKey();
|
||||
|
||||
// First we will create a dictionary of models keyed by the foreign key of the
|
||||
// relationship as this will allow us to quickly access all of the related
|
||||
// models without having to do nested looping which will be quite slow.
|
||||
foreach ($results as $result)
|
||||
{
|
||||
$dictionary[$result->{$foreign}][] = $result;
|
||||
}
|
||||
|
||||
return $dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a model instance to the parent model.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function save(Model $model)
|
||||
{
|
||||
$model->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
|
||||
|
||||
return $model->save() ? $model : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach an array of models to the parent instance.
|
||||
*
|
||||
* @param array $models
|
||||
* @return array
|
||||
*/
|
||||
public function saveMany(array $models)
|
||||
{
|
||||
array_walk($models, array($this, 'save'));
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a model by its primary key or return new instance of the related model.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrNew($id, $columns = ['*'])
|
||||
{
|
||||
if (is_null($instance = $this->find($id, $columns)))
|
||||
{
|
||||
$instance = $this->related->newInstance();
|
||||
|
||||
$instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first related model record matching the attributes or instantiate it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function firstOrNew(array $attributes)
|
||||
{
|
||||
if (is_null($instance = $this->where($attributes)->first()))
|
||||
{
|
||||
$instance = $this->related->newInstance($attributes);
|
||||
|
||||
$instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first related record matching the attributes or create it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function firstOrCreate(array $attributes)
|
||||
{
|
||||
if (is_null($instance = $this->where($attributes)->first()))
|
||||
{
|
||||
$instance = $this->create($attributes);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update a related record matching the attributes, and fill it with values.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function updateOrCreate(array $attributes, array $values = [])
|
||||
{
|
||||
$instance = $this->firstOrNew($attributes);
|
||||
|
||||
$instance->fill($values);
|
||||
|
||||
$instance->save();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the related model.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create(array $attributes)
|
||||
{
|
||||
// Here we will set the raw attributes to avoid hitting the "fill" method so
|
||||
// that we do not have to worry about a mass accessor rules blocking sets
|
||||
// on the models. Otherwise, some of these attributes will not get set.
|
||||
$instance = $this->related->newInstance($attributes);
|
||||
|
||||
$instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
|
||||
|
||||
$instance->save();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an array of new instances of the related model.
|
||||
*
|
||||
* @param array $records
|
||||
* @return array
|
||||
*/
|
||||
public function createMany(array $records)
|
||||
{
|
||||
$instances = array();
|
||||
|
||||
foreach ($records as $record)
|
||||
{
|
||||
$instances[] = $this->create($record);
|
||||
}
|
||||
|
||||
return $instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an update on all the related models.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return int
|
||||
*/
|
||||
public function update(array $attributes)
|
||||
{
|
||||
if ($this->related->usesTimestamps())
|
||||
{
|
||||
$attributes[$this->relatedUpdatedAt()] = $this->related->freshTimestampString();
|
||||
}
|
||||
|
||||
return $this->query->update($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key for comparing against the parent key in "has" query.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHasCompareKey()
|
||||
{
|
||||
return $this->getForeignKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreign key for the relationship.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getForeignKey()
|
||||
{
|
||||
return $this->foreignKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plain foreign key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPlainForeignKey()
|
||||
{
|
||||
$segments = explode('.', $this->getForeignKey());
|
||||
|
||||
return $segments[count($segments) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key value of the parent's local key.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParentKey()
|
||||
{
|
||||
return $this->parent->getAttribute($this->localKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully qualified parent key name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQualifiedParentKeyName()
|
||||
{
|
||||
return $this->parent->getTable().'.'.$this->localKey;
|
||||
}
|
||||
|
||||
}
|
47
vendor/illuminate/database/Eloquent/Relations/MorphMany.php
vendored
Executable file
47
vendor/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 array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
{
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$model->setRelation($relation, $this->related->newCollection());
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
{
|
||||
return $this->matchMany($models, $results, $relation);
|
||||
}
|
||||
|
||||
}
|
47
vendor/illuminate/database/Eloquent/Relations/MorphOne.php
vendored
Executable file
47
vendor/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 array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
{
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$model->setRelation($relation, null);
|
||||
}
|
||||
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
{
|
||||
return $this->matchOne($models, $results, $relation);
|
||||
}
|
||||
|
||||
}
|
236
vendor/illuminate/database/Eloquent/Relations/MorphOneOrMany.php
vendored
Executable file
236
vendor/illuminate/database/Eloquent/Relations/MorphOneOrMany.php
vendored
Executable file
@ -0,0 +1,236 @@
|
||||
<?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 morph one or many relationship instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $type, $id, $localKey)
|
||||
{
|
||||
$this->morphType = $type;
|
||||
|
||||
$this->morphClass = $parent->getMorphClass();
|
||||
|
||||
parent::__construct($query, $parent, $id, $localKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
if (static::$constraints)
|
||||
{
|
||||
parent::addConstraints();
|
||||
|
||||
$this->query->where($this->morphType, $this->morphClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relationship count query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $parent
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query, Builder $parent)
|
||||
{
|
||||
$query = parent::getRelationCountQuery($query, $parent);
|
||||
|
||||
return $query->where($this->morphType, $this->morphClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
parent::addEagerConstraints($models);
|
||||
|
||||
$this->query->where($this->morphType, $this->morphClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a model instance to the parent model.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function save(Model $model)
|
||||
{
|
||||
$model->setAttribute($this->getPlainMorphType(), $this->morphClass);
|
||||
|
||||
return parent::save($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a related model by its primary key or return new instance of the related model.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function findOrNew($id, $columns = ['*'])
|
||||
{
|
||||
if (is_null($instance = $this->find($id, $columns)))
|
||||
{
|
||||
$instance = $this->related->newInstance();
|
||||
|
||||
// When saving a polymorphic relationship, we need to set not only the foreign
|
||||
// key, but also the foreign key type, which is typically the class name of
|
||||
// the parent model. This makes the polymorphic item unique in the table.
|
||||
$this->setForeignAttributesForCreate($instance);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first related model record matching the attributes or instantiate it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function firstOrNew(array $attributes)
|
||||
{
|
||||
if (is_null($instance = $this->where($attributes)->first()))
|
||||
{
|
||||
$instance = $this->related->newInstance();
|
||||
|
||||
// When saving a polymorphic relationship, we need to set not only the foreign
|
||||
// key, but also the foreign key type, which is typically the class name of
|
||||
// the parent model. This makes the polymorphic item unique in the table.
|
||||
$this->setForeignAttributesForCreate($instance);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first related record matching the attributes or create it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function firstOrCreate(array $attributes)
|
||||
{
|
||||
if (is_null($instance = $this->where($attributes)->first()))
|
||||
{
|
||||
$instance = $this->create($attributes);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update a related record matching the attributes, and fill it with values.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function updateOrCreate(array $attributes, array $values = [])
|
||||
{
|
||||
$instance = $this->firstOrNew($attributes);
|
||||
|
||||
$instance->fill($values);
|
||||
|
||||
$instance->save();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the related model.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function create(array $attributes)
|
||||
{
|
||||
$instance = $this->related->newInstance($attributes);
|
||||
|
||||
// When saving a polymorphic relationship, we need to set not only the foreign
|
||||
// key, but also the foreign key type, which is typically the class name of
|
||||
// the parent model. This makes the polymorphic item unique in the table.
|
||||
$this->setForeignAttributesForCreate($instance);
|
||||
|
||||
$instance->save();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the foreign ID and type for creating a related model.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
protected function setForeignAttributesForCreate(Model $model)
|
||||
{
|
||||
$model->{$this->getPlainForeignKey()} = $this->getParentKey();
|
||||
|
||||
$model->{last(explode('.', $this->morphType))} = $this->morphClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreign key "type" name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMorphType()
|
||||
{
|
||||
return $this->morphType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plain morph type name without the table.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPlainMorphType()
|
||||
{
|
||||
return last(explode('.', $this->morphType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name of the parent model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMorphClass()
|
||||
{
|
||||
return $this->morphClass;
|
||||
}
|
||||
|
||||
}
|
78
vendor/illuminate/database/Eloquent/Relations/MorphPivot.php
vendored
Executable file
78
vendor/illuminate/database/Eloquent/Relations/MorphPivot.php
vendored
Executable file
@ -0,0 +1,78 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class MorphPivot extends Pivot {
|
||||
|
||||
/**
|
||||
* The type of the polymorphic relation.
|
||||
*
|
||||
* Explicitly define this so it's not included in saved attributes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $morphType;
|
||||
|
||||
/**
|
||||
* The value of the polymorphic relation.
|
||||
*
|
||||
* Explicitly define this so it's not included in saved attributes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $morphClass;
|
||||
|
||||
/**
|
||||
* Set the keys for a save update query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function setKeysForSaveQuery(Builder $query)
|
||||
{
|
||||
$query->where($this->morphType, $this->morphClass);
|
||||
|
||||
return parent::setKeysForSaveQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the pivot model record from the database.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$query = $this->getDeleteQuery();
|
||||
|
||||
$query->where($this->morphType, $this->morphClass);
|
||||
|
||||
return $query->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the morph type for the pivot.
|
||||
*
|
||||
* @param string $morphType
|
||||
* @return $this
|
||||
*/
|
||||
public function setMorphType($morphType)
|
||||
{
|
||||
$this->morphType = $morphType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the morph class for the pivot.
|
||||
*
|
||||
* @param string $morphClass
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphPivot
|
||||
*/
|
||||
public function setMorphClass($morphClass)
|
||||
{
|
||||
$this->morphClass = $morphClass;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
247
vendor/illuminate/database/Eloquent/Relations/MorphTo.php
vendored
Executable file
247
vendor/illuminate/database/Eloquent/Relations/MorphTo.php
vendored
Executable file
@ -0,0 +1,247 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Collection as BaseCollection;
|
||||
|
||||
class MorphTo extends BelongsTo {
|
||||
|
||||
/**
|
||||
* The type of the polymorphic relation.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $morphType;
|
||||
|
||||
/**
|
||||
* The models whose relations are being eager loaded.
|
||||
*
|
||||
* @var \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
protected $models;
|
||||
|
||||
/**
|
||||
* All of the models keyed by ID.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dictionary = array();
|
||||
|
||||
/*
|
||||
* Indicates if soft-deleted model instances should be fetched.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $withTrashed = false;
|
||||
|
||||
/**
|
||||
* Create a new morph to relationship instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $otherKey
|
||||
* @param string $type
|
||||
* @param string $relation
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $type, $relation)
|
||||
{
|
||||
$this->morphType = $type;
|
||||
|
||||
parent::__construct($query, $parent, $foreignKey, $otherKey, $relation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
$this->buildDictionary($this->models = Collection::make($models));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a dictionary with the models.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Collection $models
|
||||
* @return void
|
||||
*/
|
||||
protected function buildDictionary(Collection $models)
|
||||
{
|
||||
foreach ($models as $model)
|
||||
{
|
||||
if ($model->{$this->morphType})
|
||||
{
|
||||
$this->dictionary[$model->{$this->morphType}][$model->{$this->foreignKey}][] = $model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
{
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate the model instance to the given parent.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function associate(Model $model)
|
||||
{
|
||||
$this->parent->setAttribute($this->foreignKey, $model->getKey());
|
||||
|
||||
$this->parent->setAttribute($this->morphType, $model->getMorphClass());
|
||||
|
||||
return $this->parent->setRelation($this->relation, $model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* Called via eager load method of Eloquent query builder.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEager()
|
||||
{
|
||||
foreach (array_keys($this->dictionary) as $type)
|
||||
{
|
||||
$this->matchToMorphParents($type, $this->getResultsByType($type));
|
||||
}
|
||||
|
||||
return $this->models;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the results for a given type to their parents.
|
||||
*
|
||||
* @param string $type
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @return void
|
||||
*/
|
||||
protected function matchToMorphParents($type, Collection $results)
|
||||
{
|
||||
foreach ($results as $result)
|
||||
{
|
||||
if (isset($this->dictionary[$type][$result->getKey()]))
|
||||
{
|
||||
foreach ($this->dictionary[$type][$result->getKey()] as $model)
|
||||
{
|
||||
$model->setRelation($this->relation, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the relation results for a type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
protected function getResultsByType($type)
|
||||
{
|
||||
$instance = $this->createModelByType($type);
|
||||
|
||||
$key = $instance->getKeyName();
|
||||
|
||||
$query = $instance->newQuery();
|
||||
|
||||
$query = $this->useWithTrashed($query);
|
||||
|
||||
return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather all of the foreign keys for a given type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function gatherKeysByType($type)
|
||||
{
|
||||
$foreign = $this->foreignKey;
|
||||
|
||||
return BaseCollection::make($this->dictionary[$type])->map(function($models) use ($foreign)
|
||||
{
|
||||
return head($models)->{$foreign};
|
||||
|
||||
})->unique();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model instance by type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function createModelByType($type)
|
||||
{
|
||||
return new $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreign key "type" name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMorphType()
|
||||
{
|
||||
return $this->morphType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dictionary used by the relationship.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDictionary()
|
||||
{
|
||||
return $this->dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch soft-deleted model instances with query.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withTrashed()
|
||||
{
|
||||
$this->withTrashed = true;
|
||||
|
||||
$this->query = $this->useWithTrashed($this->query);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return trashed models with query if told so.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function useWithTrashed(Builder $query)
|
||||
{
|
||||
if ($this->withTrashed && $query->getMacro('withTrashed') !== null)
|
||||
{
|
||||
return $query->withTrashed();
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
158
vendor/illuminate/database/Eloquent/Relations/MorphToMany.php
vendored
Executable file
158
vendor/illuminate/database/Eloquent/Relations/MorphToMany.php
vendored
Executable file
@ -0,0 +1,158 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class MorphToMany extends BelongsToMany {
|
||||
|
||||
/**
|
||||
* The type of the polymorphic relation.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $morphType;
|
||||
|
||||
/**
|
||||
* The class name of the morph type constraint.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $morphClass;
|
||||
|
||||
/**
|
||||
* Indicates if we are connecting the inverse of the relation.
|
||||
*
|
||||
* This primarily affects the morphClass constraint.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $inverse;
|
||||
|
||||
/**
|
||||
* Create a new morph to many relationship instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param string $foreignKey
|
||||
* @param string $otherKey
|
||||
* @param string $relationName
|
||||
* @param bool $inverse
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false)
|
||||
{
|
||||
$this->inverse = $inverse;
|
||||
$this->morphType = $name.'_type';
|
||||
$this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass();
|
||||
|
||||
parent::__construct($query, $parent, $table, $foreignKey, $otherKey, $relationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the where clause for the relation query.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setWhere()
|
||||
{
|
||||
parent::setWhere();
|
||||
|
||||
$this->query->where($this->table.'.'.$this->morphType, $this->morphClass);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $parent
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query, Builder $parent)
|
||||
{
|
||||
$query = parent::getRelationCountQuery($query, $parent);
|
||||
|
||||
return $query->where($this->table.'.'.$this->morphType, $this->morphClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
parent::addEagerConstraints($models);
|
||||
|
||||
$this->query->where($this->table.'.'.$this->morphType, $this->morphClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new pivot attachment record.
|
||||
*
|
||||
* @param int $id
|
||||
* @param bool $timed
|
||||
* @return array
|
||||
*/
|
||||
protected function createAttachRecord($id, $timed)
|
||||
{
|
||||
$record = parent::createAttachRecord($id, $timed);
|
||||
|
||||
return array_add($record, $this->morphType, $this->morphClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new query builder for the pivot table.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected function newPivotQuery()
|
||||
{
|
||||
$query = parent::newPivotQuery();
|
||||
|
||||
return $query->where($this->morphType, $this->morphClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new pivot model instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param bool $exists
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Pivot
|
||||
*/
|
||||
public function newPivot(array $attributes = array(), $exists = false)
|
||||
{
|
||||
$pivot = new MorphPivot($this->parent, $attributes, $this->table, $exists);
|
||||
|
||||
$pivot->setPivotKeys($this->foreignKey, $this->otherKey)
|
||||
->setMorphType($this->morphType)
|
||||
->setMorphClass($this->morphClass);
|
||||
|
||||
return $pivot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreign key "type" name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMorphType()
|
||||
{
|
||||
return $this->morphType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name of the parent model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMorphClass()
|
||||
{
|
||||
return $this->morphClass;
|
||||
}
|
||||
|
||||
}
|
171
vendor/illuminate/database/Eloquent/Relations/Pivot.php
vendored
Executable file
171
vendor/illuminate/database/Eloquent/Relations/Pivot.php
vendored
Executable file
@ -0,0 +1,171 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class Pivot extends Model {
|
||||
|
||||
/**
|
||||
* The parent model of the relationship.
|
||||
*
|
||||
* @var \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* The name of the foreign key column.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $foreignKey;
|
||||
|
||||
/**
|
||||
* The name of the "other key" column.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $otherKey;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = array();
|
||||
|
||||
/**
|
||||
* Create a new pivot model instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @param array $attributes
|
||||
* @param string $table
|
||||
* @param bool $exists
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Model $parent, $attributes, $table, $exists = false)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// The pivot model is a "dynamic" model since we will set the tables dynamically
|
||||
// for the instance. This allows it work for any intermediate tables for the
|
||||
// many to many relationship that are defined by this developer's classes.
|
||||
$this->setRawAttributes($attributes, true);
|
||||
|
||||
$this->setTable($table);
|
||||
|
||||
$this->setConnection($parent->getConnectionName());
|
||||
|
||||
// We store off the parent instance so we will access the timestamp column names
|
||||
// for the model, since the pivot model timestamps aren't easily configurable
|
||||
// from the developer's point of view. We can use the parents to get these.
|
||||
$this->parent = $parent;
|
||||
|
||||
$this->exists = $exists;
|
||||
|
||||
$this->timestamps = $this->hasTimestampAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the keys for a save update query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function setKeysForSaveQuery(Builder $query)
|
||||
{
|
||||
$query->where($this->foreignKey, $this->getAttribute($this->foreignKey));
|
||||
|
||||
return $query->where($this->otherKey, $this->getAttribute($this->otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the pivot model record from the database.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
return $this->getDeleteQuery()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query builder for a delete operation on the pivot.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function getDeleteQuery()
|
||||
{
|
||||
$foreign = $this->getAttribute($this->foreignKey);
|
||||
|
||||
$query = $this->newQuery()->where($this->foreignKey, $foreign);
|
||||
|
||||
return $query->where($this->otherKey, $this->getAttribute($this->otherKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreign key column name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getForeignKey()
|
||||
{
|
||||
return $this->foreignKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "other key" column name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOtherKey()
|
||||
{
|
||||
return $this->otherKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the key names for the pivot model instance.
|
||||
*
|
||||
* @param string $foreignKey
|
||||
* @param string $otherKey
|
||||
* @return $this
|
||||
*/
|
||||
public function setPivotKeys($foreignKey, $otherKey)
|
||||
{
|
||||
$this->foreignKey = $foreignKey;
|
||||
|
||||
$this->otherKey = $otherKey;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the pivot model has timestamp attributes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTimestampAttributes()
|
||||
{
|
||||
return array_key_exists($this->getCreatedAtColumn(), $this->attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the "created at" column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCreatedAtColumn()
|
||||
{
|
||||
return $this->parent->getCreatedAtColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the "updated at" column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdatedAtColumn()
|
||||
{
|
||||
return $this->parent->getUpdatedAtColumn();
|
||||
}
|
||||
|
||||
}
|
290
vendor/illuminate/database/Eloquent/Relations/Relation.php
vendored
Executable file
290
vendor/illuminate/database/Eloquent/Relations/Relation.php
vendored
Executable file
@ -0,0 +1,290 @@
|
||||
<?php namespace Illuminate\Database\Eloquent\Relations;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
abstract class Relation {
|
||||
|
||||
/**
|
||||
* The Eloquent query builder instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected $query;
|
||||
|
||||
/**
|
||||
* The parent model instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* The related model instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
protected $related;
|
||||
|
||||
/**
|
||||
* Indicates if the relation is adding constraints.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $constraints = true;
|
||||
|
||||
/**
|
||||
* Create a new relation instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Model $parent
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->parent = $parent;
|
||||
$this->related = $query->getModel();
|
||||
|
||||
$this->addConstraints();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function addConstraints();
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
abstract public function addEagerConstraints(array $models);
|
||||
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
abstract public function initRelation(array $models, $relation);
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Illuminate\Database\Eloquent\Collection $results
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
abstract public function match(array $models, Collection $results, $relation);
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function getResults();
|
||||
|
||||
/**
|
||||
* Get the relationship for eager loading.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getEager()
|
||||
{
|
||||
return $this->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Touch all of the related models for the relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$column = $this->getRelated()->getUpdatedAtColumn();
|
||||
|
||||
$this->rawUpdate(array($column => $this->getRelated()->freshTimestampString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a raw update against the base query.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return int
|
||||
*/
|
||||
public function rawUpdate(array $attributes = array())
|
||||
{
|
||||
return $this->query->update($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \Illuminate\Database\Eloquent\Builder $parent
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getRelationCountQuery(Builder $query, Builder $parent)
|
||||
{
|
||||
$query->select(new Expression('count(*)'));
|
||||
|
||||
$key = $this->wrap($this->getQualifiedParentKeyName());
|
||||
|
||||
return $query->where($this->getHasCompareKey(), '=', new Expression($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a callback with constraints disabled on the relation.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public static function noConstraints(Closure $callback)
|
||||
{
|
||||
$previous = static::$constraints;
|
||||
|
||||
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 = $previous;
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the primary keys for an array of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
protected function getKeys(array $models, $key = null)
|
||||
{
|
||||
return array_unique(array_values(array_map(function($value) use ($key)
|
||||
{
|
||||
return $key ? $value->getAttribute($key) : $value->getKey();
|
||||
|
||||
}, $models)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying query for the relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base query builder driving the Eloquent builder.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->query->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent model of the relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully qualified parent key name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQualifiedParentKeyName()
|
||||
{
|
||||
return $this->parent->getQualifiedKeyName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the related model of the relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function getRelated()
|
||||
{
|
||||
return $this->related;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the "created at" column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function createdAt()
|
||||
{
|
||||
return $this->parent->getCreatedAtColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the "updated at" column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function updatedAt()
|
||||
{
|
||||
return $this->parent->getUpdatedAtColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the related model's "updated at" column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function relatedUpdatedAt()
|
||||
{
|
||||
return $this->related->getUpdatedAtColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the given value with the parent query's grammar.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function wrap($value)
|
||||
{
|
||||
return $this->parent->newQueryWithoutScopes()->getQuery()->getGrammar()->wrap($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dynamic method calls to the relationship.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
$result = call_user_func_array(array($this->query, $method), $parameters);
|
||||
|
||||
if ($result === $this->query) return $this;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
24
vendor/illuminate/database/Eloquent/ScopeInterface.php
vendored
Executable file
24
vendor/illuminate/database/Eloquent/ScopeInterface.php
vendored
Executable file
@ -0,0 +1,24 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
interface ScopeInterface {
|
||||
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model);
|
||||
|
||||
/**
|
||||
* Remove the scope from the given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function remove(Builder $builder, Model $model);
|
||||
|
||||
}
|
170
vendor/illuminate/database/Eloquent/SoftDeletes.php
vendored
Executable file
170
vendor/illuminate/database/Eloquent/SoftDeletes.php
vendored
Executable file
@ -0,0 +1,170 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
trait SoftDeletes {
|
||||
|
||||
/**
|
||||
* Indicates if the model is currently force deleting.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $forceDeleting = false;
|
||||
|
||||
/**
|
||||
* Boot the soft deleting trait for a model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function bootSoftDeletes()
|
||||
{
|
||||
static::addGlobalScope(new SoftDeletingScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a hard delete on a soft deleted model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function forceDelete()
|
||||
{
|
||||
$this->forceDeleting = true;
|
||||
|
||||
$this->delete();
|
||||
|
||||
$this->forceDeleting = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the actual delete query on this model instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function performDeleteOnModel()
|
||||
{
|
||||
if ($this->forceDeleting)
|
||||
{
|
||||
return $this->withTrashed()->where($this->getKeyName(), $this->getKey())->forceDelete();
|
||||
}
|
||||
|
||||
return $this->runSoftDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the actual delete query on this model instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function runSoftDelete()
|
||||
{
|
||||
$query = $this->newQuery()->where($this->getKeyName(), $this->getKey());
|
||||
|
||||
$this->{$this->getDeletedAtColumn()} = $time = $this->freshTimestamp();
|
||||
|
||||
$query->update(array($this->getDeletedAtColumn() => $this->fromDateTime($time)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a soft-deleted model instance.
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
// If the restoring event does not return false, we will proceed with this
|
||||
// restore operation. Otherwise, we bail out so the developer will stop
|
||||
// the restore totally. We will clear the deleted timestamp and save.
|
||||
if ($this->fireModelEvent('restoring') === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->{$this->getDeletedAtColumn()} = null;
|
||||
|
||||
// Once we have saved the model, we will fire the "restored" event so this
|
||||
// developer will do anything they need to after a restore operation is
|
||||
// totally finished. Then we will return the result of the save call.
|
||||
$this->exists = true;
|
||||
|
||||
$result = $this->save();
|
||||
|
||||
$this->fireModelEvent('restored', false);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the model instance has been soft-deleted.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function trashed()
|
||||
{
|
||||
return ! is_null($this->{$this->getDeletedAtColumn()});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new query builder that includes soft deletes.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public static function withTrashed()
|
||||
{
|
||||
return (new static)->newQueryWithoutScope(new SoftDeletingScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new query builder that only includes soft deletes.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||
*/
|
||||
public static function onlyTrashed()
|
||||
{
|
||||
$instance = new static;
|
||||
|
||||
$column = $instance->getQualifiedDeletedAtColumn();
|
||||
|
||||
return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a restoring model event with the dispatcher.
|
||||
*
|
||||
* @param \Closure|string $callback
|
||||
* @return void
|
||||
*/
|
||||
public static function restoring($callback)
|
||||
{
|
||||
static::registerModelEvent('restoring', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a restored model event with the dispatcher.
|
||||
*
|
||||
* @param \Closure|string $callback
|
||||
* @return void
|
||||
*/
|
||||
public static function restored($callback)
|
||||
{
|
||||
static::registerModelEvent('restored', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the "deleted at" column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDeletedAtColumn()
|
||||
{
|
||||
return defined('static::DELETED_AT') ? static::DELETED_AT : 'deleted_at';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully qualified "deleted at" column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQualifiedDeletedAtColumn()
|
||||
{
|
||||
return $this->getTable().'.'.$this->getDeletedAtColumn();
|
||||
}
|
||||
|
||||
}
|
164
vendor/illuminate/database/Eloquent/SoftDeletingScope.php
vendored
Executable file
164
vendor/illuminate/database/Eloquent/SoftDeletingScope.php
vendored
Executable file
@ -0,0 +1,164 @@
|
||||
<?php namespace Illuminate\Database\Eloquent;
|
||||
|
||||
class SoftDeletingScope implements ScopeInterface {
|
||||
|
||||
/**
|
||||
* All of the extensions to be added to the builder.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $extensions = ['ForceDelete', 'Restore', 'WithTrashed', 'OnlyTrashed'];
|
||||
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model)
|
||||
{
|
||||
$builder->whereNull($model->getQualifiedDeletedAtColumn());
|
||||
|
||||
$this->extend($builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the scope from the given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
public function remove(Builder $builder, Model $model)
|
||||
{
|
||||
$column = $model->getQualifiedDeletedAtColumn();
|
||||
|
||||
$query = $builder->getQuery();
|
||||
|
||||
$query->wheres = collect($query->wheres)->reject(function($where) use ($column)
|
||||
{
|
||||
return $this->isSoftDeleteConstraint($where, $column);
|
||||
})->values()->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the query builder with the needed functions.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return void
|
||||
*/
|
||||
public function extend(Builder $builder)
|
||||
{
|
||||
foreach ($this->extensions as $extension)
|
||||
{
|
||||
$this->{"add{$extension}"}($builder);
|
||||
}
|
||||
|
||||
$builder->onDelete(function(Builder $builder)
|
||||
{
|
||||
$column = $this->getDeletedAtColumn($builder);
|
||||
|
||||
return $builder->update(array(
|
||||
$column => $builder->getModel()->freshTimestampString(),
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "deleted at" column for the builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return string
|
||||
*/
|
||||
protected function getDeletedAtColumn(Builder $builder)
|
||||
{
|
||||
if (count($builder->getQuery()->joins) > 0)
|
||||
{
|
||||
return $builder->getModel()->getQualifiedDeletedAtColumn();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $builder->getModel()->getDeletedAtColumn();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the force delete extension to the builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return void
|
||||
*/
|
||||
protected function addForceDelete(Builder $builder)
|
||||
{
|
||||
$builder->macro('forceDelete', function(Builder $builder)
|
||||
{
|
||||
return $builder->getQuery()->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the restore extension to the builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return void
|
||||
*/
|
||||
protected function addRestore(Builder $builder)
|
||||
{
|
||||
$builder->macro('restore', function(Builder $builder)
|
||||
{
|
||||
$builder->withTrashed();
|
||||
|
||||
return $builder->update(array($builder->getModel()->getDeletedAtColumn() => null));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the with-trashed extension to the builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return void
|
||||
*/
|
||||
protected function addWithTrashed(Builder $builder)
|
||||
{
|
||||
$builder->macro('withTrashed', function(Builder $builder)
|
||||
{
|
||||
$this->remove($builder, $builder->getModel());
|
||||
|
||||
return $builder;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the only-trashed extension to the builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return void
|
||||
*/
|
||||
protected function addOnlyTrashed(Builder $builder)
|
||||
{
|
||||
$builder->macro('onlyTrashed', function(Builder $builder)
|
||||
{
|
||||
$model = $builder->getModel();
|
||||
|
||||
$this->remove($builder, $model);
|
||||
|
||||
$builder->getQuery()->whereNotNull($model->getQualifiedDeletedAtColumn());
|
||||
|
||||
return $builder;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given where clause is a soft delete constraint.
|
||||
*
|
||||
* @param array $where
|
||||
* @param string $column
|
||||
* @return bool
|
||||
*/
|
||||
protected function isSoftDeleteConstraint(array $where, $column)
|
||||
{
|
||||
return $where['type'] == 'Null' && $where['column'] == $column;
|
||||
}
|
||||
|
||||
}
|
184
vendor/illuminate/database/Grammar.php
vendored
Executable file
184
vendor/illuminate/database/Grammar.php
vendored
Executable file
@ -0,0 +1,184 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Database\Query\Expression;
|
||||
|
||||
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, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a value in keyword identifiers.
|
||||
*
|
||||
* @param string $value
|
||||
* @param bool $prefixAlias
|
||||
* @return string
|
||||
*/
|
||||
public function wrap($value, $prefixAlias = false)
|
||||
{
|
||||
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);
|
||||
|
||||
if ($prefixAlias) $segments[2] = $this->tablePrefix.$segments[2];
|
||||
|
||||
return $this->wrap($segments[0]).' as '.$this->wrapValue($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 && 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)
|
||||
{
|
||||
if ($value === '*') return $value;
|
||||
|
||||
return '"'.str_replace('"', '""', $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 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 $this
|
||||
*/
|
||||
public function setTablePrefix($prefix)
|
||||
{
|
||||
$this->tablePrefix = $prefix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
226
vendor/illuminate/database/MigrationServiceProvider.php
vendored
Executable file
226
vendor/illuminate/database/MigrationServiceProvider.php
vendored
Executable file
@ -0,0 +1,226 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Illuminate\Database\Migrations\MigrationCreator;
|
||||
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\Console\Migrations\MigrateMakeCommand;
|
||||
use Illuminate\Database\Console\Migrations\StatusCommand;
|
||||
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->singleton('migration.repository', 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->singleton('migrator', 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', 'Status');
|
||||
|
||||
// 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',
|
||||
'command.migrate.status'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "migrate" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerMigrateCommand()
|
||||
{
|
||||
$this->app->singleton('command.migrate', function($app)
|
||||
{
|
||||
return new MigrateCommand($app['migrator']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "rollback" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerRollbackCommand()
|
||||
{
|
||||
$this->app->singleton('command.migrate.rollback', function($app)
|
||||
{
|
||||
return new RollbackCommand($app['migrator']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "reset" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerResetCommand()
|
||||
{
|
||||
$this->app->singleton('command.migrate.reset', function($app)
|
||||
{
|
||||
return new ResetCommand($app['migrator']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "refresh" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerRefreshCommand()
|
||||
{
|
||||
$this->app->singleton('command.migrate.refresh', function()
|
||||
{
|
||||
return new RefreshCommand;
|
||||
});
|
||||
}
|
||||
|
||||
protected function registerStatusCommand()
|
||||
{
|
||||
$this->app->singleton('command.migrate.status', function($app)
|
||||
{
|
||||
return new StatusCommand($app['migrator']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "install" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerInstallCommand()
|
||||
{
|
||||
$this->app->singleton('command.migrate.install', function($app)
|
||||
{
|
||||
return new InstallCommand($app['migration.repository']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the "make" migration command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerMakeCommand()
|
||||
{
|
||||
$this->registerCreator();
|
||||
|
||||
$this->app->singleton('command.migrate.make', 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'];
|
||||
|
||||
$composer = $app['composer'];
|
||||
|
||||
return new MigrateMakeCommand($creator, $composer);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the migration creator.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerCreator()
|
||||
{
|
||||
$this->app->singleton('migration.creator', function($app)
|
||||
{
|
||||
return new MigrationCreator($app['files']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'command.migrate.status', 'migration.creator',
|
||||
'command.migrate.make',
|
||||
);
|
||||
}
|
||||
|
||||
}
|
181
vendor/illuminate/database/Migrations/DatabaseMigrationRepository.php
vendored
Executable file
181
vendor/illuminate/database/Migrations/DatabaseMigrationRepository.php
vendored
Executable file
@ -0,0 +1,181 @@
|
||||
<?php namespace Illuminate\Database\Migrations;
|
||||
|
||||
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
|
||||
* @param string $table
|
||||
* @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 object $migration
|
||||
* @return void
|
||||
*/
|
||||
public function delete($migration)
|
||||
{
|
||||
$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/illuminate/database/Migrations/Migration.php
vendored
Executable file
22
vendor/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;
|
||||
}
|
||||
|
||||
}
|
183
vendor/illuminate/database/Migrations/MigrationCreator.php
vendored
Executable file
183
vendor/illuminate/database/Migrations/MigrationCreator.php
vendored
Executable file
@ -0,0 +1,183 @@
|
||||
<?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
|
||||
* @param bool $create
|
||||
* @return string
|
||||
*/
|
||||
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}}', $this->getClassName($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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name of a migration name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function getClassName($name)
|
||||
{
|
||||
return studly_case($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 string
|
||||
*/
|
||||
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/illuminate/database/Migrations/MigrationRepositoryInterface.php
vendored
Executable file
65
vendor/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 object $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);
|
||||
|
||||
}
|
411
vendor/illuminate/database/Migrations/Migrator.php
vendored
Executable file
411
vendor/illuminate/database/Migrations/Migrator.php
vendored
Executable file
@ -0,0 +1,411 @@
|
||||
<?php namespace Illuminate\Database\Migrations;
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
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();
|
||||
|
||||
$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 each of the outstanding migrations against a database connection.
|
||||
$ran = $this->repository->getRan();
|
||||
|
||||
$migrations = array_diff($files, $ran);
|
||||
|
||||
$this->requireFiles($path, $migrations);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rolls all of the currently applied migrations back.
|
||||
*
|
||||
* @param bool $pretend
|
||||
* @return int
|
||||
*/
|
||||
public function reset($pretend = false)
|
||||
{
|
||||
$this->notes = [];
|
||||
|
||||
$migrations = array_reverse($this->repository->getRan());
|
||||
|
||||
if (count($migrations) == 0)
|
||||
{
|
||||
$this->note('<info>Nothing to rollback.</info>');
|
||||
|
||||
return count($migrations);
|
||||
}
|
||||
|
||||
foreach ($migrations as $migration)
|
||||
{
|
||||
$this->runDown((object) ['migration' => $migration], $pretend);
|
||||
}
|
||||
|
||||
return count($migrations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run "down" a migration instance.
|
||||
*
|
||||
* @param object $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 string $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
|
||||
* @param string $method
|
||||
* @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.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function resolveConnection($connection)
|
||||
{
|
||||
return $this->resolver->connection($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;
|
||||
}
|
||||
|
||||
}
|
28
vendor/illuminate/database/Migrations/stubs/blank.stub
vendored
Executable file
28
vendor/illuminate/database/Migrations/stubs/blank.stub
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
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/illuminate/database/Migrations/stubs/create.stub
vendored
Executable file
32
vendor/illuminate/database/Migrations/stubs/create.stub
vendored
Executable 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/illuminate/database/Migrations/stubs/update.stub
vendored
Executable file
34
vendor/illuminate/database/Migrations/stubs/update.stub
vendored
Executable 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)
|
||||
{
|
||||
//
|
||||
});
|
||||
}
|
||||
|
||||
}
|
63
vendor/illuminate/database/MySqlConnection.php
vendored
Executable file
63
vendor/illuminate/database/MySqlConnection.php
vendored
Executable file
@ -0,0 +1,63 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Database\Schema\MySqlBuilder;
|
||||
use Illuminate\Database\Query\Processors\MySqlProcessor;
|
||||
use Doctrine\DBAL\Driver\PDOMySql\Driver as DoctrineDriver;
|
||||
use Illuminate\Database\Query\Grammars\MySqlGrammar as QueryGrammar;
|
||||
use Illuminate\Database\Schema\Grammars\MySqlGrammar as SchemaGrammar;
|
||||
|
||||
class MySqlConnection extends Connection {
|
||||
|
||||
/**
|
||||
* Get a schema builder instance for the connection.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\MySqlBuilder
|
||||
*/
|
||||
public function getSchemaBuilder()
|
||||
{
|
||||
if (is_null($this->schemaGrammar)) { $this->useDefaultSchemaGrammar(); }
|
||||
|
||||
return new MySqlBuilder($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default query grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\MySqlGrammar
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new QueryGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default schema grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Grammars\MySqlGrammar
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new SchemaGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default post processor instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Processors\Processor
|
||||
*/
|
||||
protected function getDefaultPostProcessor()
|
||||
{
|
||||
return new MySqlProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL driver.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Driver\PDOMySql\Driver
|
||||
*/
|
||||
protected function getDoctrineDriver()
|
||||
{
|
||||
return new DoctrineDriver;
|
||||
}
|
||||
|
||||
}
|
50
vendor/illuminate/database/PostgresConnection.php
vendored
Executable file
50
vendor/illuminate/database/PostgresConnection.php
vendored
Executable file
@ -0,0 +1,50 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Doctrine\DBAL\Driver\PDOPgSql\Driver as DoctrineDriver;
|
||||
use Illuminate\Database\Query\Processors\PostgresProcessor;
|
||||
use Illuminate\Database\Query\Grammars\PostgresGrammar as QueryGrammar;
|
||||
use Illuminate\Database\Schema\Grammars\PostgresGrammar as SchemaGrammar;
|
||||
|
||||
class PostgresConnection extends Connection {
|
||||
|
||||
/**
|
||||
* Get the default query grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\PostgresGrammar
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new QueryGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default schema grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Grammars\PostgresGrammar
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new SchemaGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default post processor instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Processors\PostgresProcessor
|
||||
*/
|
||||
protected function getDefaultPostProcessor()
|
||||
{
|
||||
return new PostgresProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL driver.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Driver\PDOPgSql\Driver
|
||||
*/
|
||||
protected function getDoctrineDriver()
|
||||
{
|
||||
return new DoctrineDriver;
|
||||
}
|
||||
|
||||
}
|
1995
vendor/illuminate/database/Query/Builder.php
vendored
Executable file
1995
vendor/illuminate/database/Query/Builder.php
vendored
Executable file
File diff suppressed because it is too large
Load Diff
43
vendor/illuminate/database/Query/Expression.php
vendored
Executable file
43
vendor/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();
|
||||
}
|
||||
|
||||
}
|
758
vendor/illuminate/database/Query/Grammars/Grammar.php
vendored
Executable file
758
vendor/illuminate/database/Query/Grammars/Grammar.php
vendored
Executable file
@ -0,0 +1,758 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Database\Grammar as BaseGrammar;
|
||||
|
||||
class Grammar extends BaseGrammar {
|
||||
|
||||
/**
|
||||
* The components that make up a select clause.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $selectComponents = array(
|
||||
'aggregate',
|
||||
'columns',
|
||||
'from',
|
||||
'joins',
|
||||
'wheres',
|
||||
'groups',
|
||||
'havings',
|
||||
'orders',
|
||||
'limit',
|
||||
'offset',
|
||||
'unions',
|
||||
'lock',
|
||||
);
|
||||
|
||||
/**
|
||||
* 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 && $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();
|
||||
|
||||
$query->setBindings(array(), 'join');
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
foreach ($join->bindings as $binding)
|
||||
{
|
||||
$query->addBinding($binding, 'join');
|
||||
}
|
||||
|
||||
// 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 = $clause['where'] ? '?' : $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 '.$this->removeLeadingBoolean($sql);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$between = $where['not'] ? 'not between' : 'between';
|
||||
|
||||
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)
|
||||
{
|
||||
if (empty($where['values'])) return '0 = 1';
|
||||
|
||||
$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)
|
||||
{
|
||||
if (empty($where['values'])) return '1 = 1';
|
||||
|
||||
$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 "where date" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereDate(Builder $query, $where)
|
||||
{
|
||||
return $this->dateBasedWhere('date', $query, $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where day" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereDay(Builder $query, $where)
|
||||
{
|
||||
return $this->dateBasedWhere('day', $query, $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where month" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereMonth(Builder $query, $where)
|
||||
{
|
||||
return $this->dateBasedWhere('month', $query, $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where year" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereYear(Builder $query, $where)
|
||||
{
|
||||
return $this->dateBasedWhere('year', $query, $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a date based where clause.
|
||||
*
|
||||
* @param string $type
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function dateBasedWhere($type, Builder $query, $where)
|
||||
{
|
||||
$value = $this->parameter($where['value']);
|
||||
|
||||
return $type.'('.$this->wrap($where['column']).') '.$where['operator'].' '.$value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$sql = implode(' ', array_map(array($this, 'compileHaving'), $havings));
|
||||
|
||||
return 'having '.$this->removeLeadingBoolean($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $having['boolean'].' '.$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)
|
||||
{
|
||||
return 'order by '.implode(', ', array_map(function($order)
|
||||
{
|
||||
if (isset($order['sql'])) return $order['sql'];
|
||||
|
||||
return $this->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 '.(int) $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 '.(int) $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)
|
||||
{
|
||||
$sql .= $this->compileUnion($union);
|
||||
}
|
||||
|
||||
if (isset($query->unionOrders))
|
||||
{
|
||||
$sql .= ' '.$this->compileOrders($query, $query->unionOrders);
|
||||
}
|
||||
|
||||
if (isset($query->unionLimit))
|
||||
{
|
||||
$sql .= ' '.$this->compileLimit($query, $query->unionLimit);
|
||||
}
|
||||
|
||||
if (isset($query->unionOffset))
|
||||
{
|
||||
$sql .= ' '.$this->compileOffset($query, $query->unionOffset);
|
||||
}
|
||||
|
||||
return ltrim($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a single union statement.
|
||||
*
|
||||
* @param array $union
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUnion(array $union)
|
||||
{
|
||||
$joiner = $union['all'] ? ' union all ' : ' union ';
|
||||
|
||||
return $joiner.$union['query']->toSql();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the lock into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param bool|string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileLock(Builder $query, $value)
|
||||
{
|
||||
return is_string($value) ? $value : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
144
vendor/illuminate/database/Query/Grammars/MySqlGrammar.php
vendored
Executable file
144
vendor/illuminate/database/Query/Grammars/MySqlGrammar.php
vendored
Executable file
@ -0,0 +1,144 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class MySqlGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The components that make up a select clause.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $selectComponents = array(
|
||||
'aggregate',
|
||||
'columns',
|
||||
'from',
|
||||
'joins',
|
||||
'wheres',
|
||||
'groups',
|
||||
'havings',
|
||||
'orders',
|
||||
'limit',
|
||||
'offset',
|
||||
'lock',
|
||||
);
|
||||
|
||||
/**
|
||||
* Compile a select query into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder
|
||||
* @return string
|
||||
*/
|
||||
public function compileSelect(Builder $query)
|
||||
{
|
||||
$sql = parent::compileSelect($query);
|
||||
|
||||
if ($query->unions)
|
||||
{
|
||||
$sql = '('.$sql.') '.$this->compileUnions($query);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a single union statement.
|
||||
*
|
||||
* @param array $union
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUnion(array $union)
|
||||
{
|
||||
$joiner = $union['all'] ? ' union all ' : ' union ';
|
||||
|
||||
return $joiner.'('.$union['query']->toSql().')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the lock into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param bool|string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileLock(Builder $query, $value)
|
||||
{
|
||||
if (is_string($value)) return $value;
|
||||
|
||||
return $value ? 'for update' : 'lock in share mode';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an update statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function compileUpdate(Builder $query, $values)
|
||||
{
|
||||
$sql = parent::compileUpdate($query, $values);
|
||||
|
||||
if (isset($query->orders))
|
||||
{
|
||||
$sql .= ' '.$this->compileOrders($query, $query->orders);
|
||||
}
|
||||
|
||||
if (isset($query->limit))
|
||||
{
|
||||
$sql .= ' '.$this->compileLimit($query, $query->limit);
|
||||
}
|
||||
|
||||
return rtrim($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a delete statement into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
public function compileDelete(Builder $query)
|
||||
{
|
||||
$table = $this->wrapTable($query->from);
|
||||
|
||||
$where = is_array($query->wheres) ? $this->compileWheres($query) : '';
|
||||
|
||||
if (isset($query->joins))
|
||||
{
|
||||
$joins = ' '.$this->compileJoins($query, $query->joins);
|
||||
|
||||
$sql = trim("delete $table from {$table}{$joins} $where");
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = trim("delete from $table $where");
|
||||
}
|
||||
|
||||
if (isset($query->orders))
|
||||
{
|
||||
$sql .= ' '.$this->compileOrders($query, $query->orders);
|
||||
}
|
||||
|
||||
if (isset($query->limit))
|
||||
{
|
||||
$sql .= ' '.$this->compileLimit($query, $query->limit);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a single string in keyword identifiers.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function wrapValue($value)
|
||||
{
|
||||
if ($value === '*') return $value;
|
||||
|
||||
return '`'.str_replace('`', '``', $value).'`';
|
||||
}
|
||||
|
||||
}
|
174
vendor/illuminate/database/Query/Grammars/PostgresGrammar.php
vendored
Executable file
174
vendor/illuminate/database/Query/Grammars/PostgresGrammar.php
vendored
Executable file
@ -0,0 +1,174 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class PostgresGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* All of the available clause operators.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $operators = array(
|
||||
'=', '<', '>', '<=', '>=', '<>', '!=',
|
||||
'like', 'not like', 'between', 'ilike',
|
||||
'&', '|', '#', '<<', '>>',
|
||||
);
|
||||
|
||||
/**
|
||||
* Compile the lock into SQL.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param bool|string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileLock(Builder $query, $value)
|
||||
{
|
||||
if (is_string($value)) return $value;
|
||||
|
||||
return $value ? 'for update' : 'for share';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
130
vendor/illuminate/database/Query/Grammars/SQLiteGrammar.php
vendored
Executable file
130
vendor/illuminate/database/Query/Grammars/SQLiteGrammar.php
vendored
Executable file
@ -0,0 +1,130 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class SQLiteGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* All of the available clause operators.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $operators = array(
|
||||
'=', '<', '>', '<=', '>=', '<>', '!=',
|
||||
'like', 'not like', 'between', 'ilike',
|
||||
'&', '|', '<<', '>>',
|
||||
);
|
||||
|
||||
/**
|
||||
* 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, reset($values));
|
||||
}
|
||||
|
||||
$names = $this->columnize(array_keys(reset($values)));
|
||||
|
||||
$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(reset($values)) as $column)
|
||||
{
|
||||
$columns[] = '? as '.$this->wrap($column);
|
||||
}
|
||||
|
||||
$columns = array_fill(0, count($values), implode(', ', $columns));
|
||||
|
||||
return "insert into $table ($names) select ".implode(' union all 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where day" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereDay(Builder $query, $where)
|
||||
{
|
||||
return $this->dateBasedWhere('%d', $query, $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where month" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereMonth(Builder $query, $where)
|
||||
{
|
||||
return $this->dateBasedWhere('%m', $query, $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a "where year" clause.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereYear(Builder $query, $where)
|
||||
{
|
||||
return $this->dateBasedWhere('%Y', $query, $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a date based where clause.
|
||||
*
|
||||
* @param string $type
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function dateBasedWhere($type, Builder $query, $where)
|
||||
{
|
||||
$value = str_pad($where['value'], 2, '0', STR_PAD_LEFT);
|
||||
|
||||
$value = $this->parameter($value);
|
||||
|
||||
return 'strftime(\''.$type.'\', '.$this->wrap($where['column']).') '.$where['operator'].' '.$value;
|
||||
}
|
||||
|
||||
}
|
224
vendor/illuminate/database/Query/Grammars/SqlServerGrammar.php
vendored
Executable file
224
vendor/illuminate/database/Query/Grammars/SqlServerGrammar.php
vendored
Executable file
@ -0,0 +1,224 @@
|
||||
<?php namespace Illuminate\Database\Query\Grammars;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class SqlServerGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* All of the available clause operators.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $operators = array(
|
||||
'=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=',
|
||||
'like', 'not like', 'between', 'ilike',
|
||||
'&', '&=', '|', '|=', '^', '^=',
|
||||
);
|
||||
|
||||
/**
|
||||
* 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 && $query->offset <= 0)
|
||||
{
|
||||
$select .= 'top '.$query->limit.' ';
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$from = parent::compileFrom($query, $table);
|
||||
|
||||
if (is_string($query->lock)) return $from.' '.$query->lock;
|
||||
|
||||
if ( ! is_null($query->lock))
|
||||
{
|
||||
return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)';
|
||||
}
|
||||
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
$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';
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a single string in keyword identifiers.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function wrapValue($value)
|
||||
{
|
||||
if ($value === '*') return $value;
|
||||
|
||||
return '['.str_replace(']', ']]', $value).']';
|
||||
}
|
||||
|
||||
}
|
151
vendor/illuminate/database/Query/JoinClause.php
vendored
Executable file
151
vendor/illuminate/database/Query/JoinClause.php
vendored
Executable file
@ -0,0 +1,151 @@
|
||||
<?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();
|
||||
|
||||
/**
|
||||
* The "on" bindings for the join.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $bindings = 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
|
||||
* @param bool $where
|
||||
* @return $this
|
||||
*/
|
||||
public function on($first, $operator, $second, $boolean = 'and', $where = false)
|
||||
{
|
||||
$this->clauses[] = compact('first', 'operator', 'second', 'boolean', 'where');
|
||||
|
||||
if ($where) $this->bindings[] = $second;
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an "on where" clause to the join.
|
||||
*
|
||||
* @param string $first
|
||||
* @param string $operator
|
||||
* @param string $second
|
||||
* @param string $boolean
|
||||
* @return \Illuminate\Database\Query\JoinClause
|
||||
*/
|
||||
public function where($first, $operator, $second, $boolean = 'and')
|
||||
{
|
||||
return $this->on($first, $operator, $second, $boolean, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an "or on where" clause to the join.
|
||||
*
|
||||
* @param string $first
|
||||
* @param string $operator
|
||||
* @param string $second
|
||||
* @return \Illuminate\Database\Query\JoinClause
|
||||
*/
|
||||
public function orWhere($first, $operator, $second)
|
||||
{
|
||||
return $this->on($first, $operator, $second, 'or', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an "on where is null" clause to the join.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $boolean
|
||||
* @return \Illuminate\Database\Query\JoinClause
|
||||
*/
|
||||
public function whereNull($column, $boolean = 'and')
|
||||
{
|
||||
return $this->on($column, 'is', new Expression('null'), $boolean, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an "or on where is null" clause to the join.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Database\Query\JoinClause
|
||||
*/
|
||||
public function orWhereNull($column)
|
||||
{
|
||||
return $this->whereNull($column, 'or');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an "on where is not null" clause to the join.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $boolean
|
||||
* @return \Illuminate\Database\Query\JoinClause
|
||||
*/
|
||||
public function whereNotNull($column, $boolean = 'and')
|
||||
{
|
||||
return $this->on($column, 'is', new Expression('not null'), $boolean, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an "or on where is not null" clause to the join.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Database\Query\JoinClause
|
||||
*/
|
||||
public function orWhereNotNull($column)
|
||||
{
|
||||
return $this->whereNotNull($column, 'or');
|
||||
}
|
||||
|
||||
}
|
23
vendor/illuminate/database/Query/Processors/MySqlProcessor.php
vendored
Executable file
23
vendor/illuminate/database/Query/Processors/MySqlProcessor.php
vendored
Executable file
@ -0,0 +1,23 @@
|
||||
<?php namespace Illuminate\Database\Query\Processors;
|
||||
|
||||
class MySqlProcessor extends Processor {
|
||||
|
||||
/**
|
||||
* Process the results of a column listing query.
|
||||
*
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
public function processColumnListing($results)
|
||||
{
|
||||
$mapping = function($r)
|
||||
{
|
||||
$r = (object) $r;
|
||||
|
||||
return $r->column_name;
|
||||
};
|
||||
|
||||
return array_map($mapping, $results);
|
||||
}
|
||||
|
||||
}
|
47
vendor/illuminate/database/Query/Processors/PostgresProcessor.php
vendored
Executable file
47
vendor/illuminate/database/Query/Processors/PostgresProcessor.php
vendored
Executable file
@ -0,0 +1,47 @@
|
||||
<?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()->selectFromWriteConnection($sql, $values);
|
||||
|
||||
$sequence = $sequence ?: 'id';
|
||||
|
||||
$result = (array) $results[0];
|
||||
|
||||
$id = $result[$sequence];
|
||||
|
||||
return is_numeric($id) ? (int) $id : $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the results of a column listing query.
|
||||
*
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
public function processColumnListing($results)
|
||||
{
|
||||
$mapping = function($r)
|
||||
{
|
||||
$r = (object) $r;
|
||||
|
||||
return $r->column_name;
|
||||
};
|
||||
|
||||
return array_map($mapping, $results);
|
||||
}
|
||||
|
||||
}
|
48
vendor/illuminate/database/Query/Processors/Processor.php
vendored
Executable file
48
vendor/illuminate/database/Query/Processors/Processor.php
vendored
Executable file
@ -0,0 +1,48 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the results of a column listing query.
|
||||
*
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
public function processColumnListing($results)
|
||||
{
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
23
vendor/illuminate/database/Query/Processors/SQLiteProcessor.php
vendored
Executable file
23
vendor/illuminate/database/Query/Processors/SQLiteProcessor.php
vendored
Executable file
@ -0,0 +1,23 @@
|
||||
<?php namespace Illuminate\Database\Query\Processors;
|
||||
|
||||
class SQLiteProcessor extends Processor {
|
||||
|
||||
/**
|
||||
* Process the results of a column listing query.
|
||||
*
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
public function processColumnListing($results)
|
||||
{
|
||||
$mapping = function($r)
|
||||
{
|
||||
$r = (object) $r;
|
||||
|
||||
return $r->name;
|
||||
};
|
||||
|
||||
return array_map($mapping, $results);
|
||||
}
|
||||
|
||||
}
|
41
vendor/illuminate/database/Query/Processors/SqlServerProcessor.php
vendored
Executable file
41
vendor/illuminate/database/Query/Processors/SqlServerProcessor.php
vendored
Executable file
@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the results of a column listing query.
|
||||
*
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
public function processColumnListing($results)
|
||||
{
|
||||
$mapping = function($r)
|
||||
{
|
||||
return $r->name;
|
||||
};
|
||||
|
||||
return array_map($mapping, $results);
|
||||
}
|
||||
|
||||
}
|
78
vendor/illuminate/database/QueryException.php
vendored
Executable file
78
vendor/illuminate/database/QueryException.php
vendored
Executable file
@ -0,0 +1,78 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use PDOException;
|
||||
|
||||
class QueryException extends PDOException {
|
||||
|
||||
/**
|
||||
* The SQL for the query.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $sql;
|
||||
|
||||
/**
|
||||
* The bindings for the query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $bindings;
|
||||
|
||||
/**
|
||||
* Create a new query exception instance.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param array $bindings
|
||||
* @param \Exception $previous
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($sql, array $bindings, $previous)
|
||||
{
|
||||
parent::__construct('', 0, $previous);
|
||||
|
||||
$this->sql = $sql;
|
||||
$this->bindings = $bindings;
|
||||
$this->previous = $previous;
|
||||
$this->code = $previous->getCode();
|
||||
$this->message = $this->formatMessage($sql, $bindings, $previous);
|
||||
|
||||
if ($previous instanceof PDOException)
|
||||
{
|
||||
$this->errorInfo = $previous->errorInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the SQL error message.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param array $bindings
|
||||
* @param \Exception $previous
|
||||
* @return string
|
||||
*/
|
||||
protected function formatMessage($sql, $bindings, $previous)
|
||||
{
|
||||
return $previous->getMessage().' (SQL: '.str_replace_array('\?', $bindings, $sql).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for the query.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSql()
|
||||
{
|
||||
return $this->sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bindings for the query.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBindings()
|
||||
{
|
||||
return $this->bindings;
|
||||
}
|
||||
|
||||
}
|
70
vendor/illuminate/database/README.md
vendored
Executable file
70
vendor/illuminate/database/README.md
vendored
Executable file
@ -0,0 +1,70 @@
|
||||
## 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.
|
||||
|
||||
```PHP
|
||||
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' => '',
|
||||
]);
|
||||
|
||||
// Set the event dispatcher used by Eloquent models... (optional)
|
||||
use Illuminate\Events\Dispatcher;
|
||||
use Illuminate\Container\Container;
|
||||
$capsule->setEventDispatcher(new Dispatcher(new Container));
|
||||
|
||||
// Make this Capsule instance available globally via static methods... (optional)
|
||||
$capsule->setAsGlobal();
|
||||
|
||||
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
|
||||
$capsule->bootEloquent();
|
||||
```
|
||||
|
||||
> `composer require "illuminate/events=5.0.*"` required when you need to use observers with Eloquent.
|
||||
|
||||
Once the Capsule instance has been registered. You may use it like so:
|
||||
|
||||
**Using The Query Builder**
|
||||
|
||||
```PHP
|
||||
$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:
|
||||
```PHP
|
||||
$results = Capsule::select('select * from users where id = ?', array(1));
|
||||
```
|
||||
|
||||
**Using The Schema Builder**
|
||||
|
||||
```PHP
|
||||
Capsule::schema()->create('users', function($table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
```
|
||||
|
||||
**Using The Eloquent ORM**
|
||||
|
||||
```PHP
|
||||
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).
|
50
vendor/illuminate/database/SQLiteConnection.php
vendored
Executable file
50
vendor/illuminate/database/SQLiteConnection.php
vendored
Executable file
@ -0,0 +1,50 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Database\Query\Processors\SQLiteProcessor;
|
||||
use Doctrine\DBAL\Driver\PDOSqlite\Driver as DoctrineDriver;
|
||||
use Illuminate\Database\Query\Grammars\SQLiteGrammar as QueryGrammar;
|
||||
use Illuminate\Database\Schema\Grammars\SQLiteGrammar as SchemaGrammar;
|
||||
|
||||
class SQLiteConnection extends Connection {
|
||||
|
||||
/**
|
||||
* Get the default query grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Grammars\SQLiteGrammar
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new QueryGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default schema grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Grammars\SQLiteGrammar
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new SchemaGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default post processor instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Processors\Processor
|
||||
*/
|
||||
protected function getDefaultPostProcessor()
|
||||
{
|
||||
return new SQLiteProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL driver.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Driver\PDOSqlite\Driver
|
||||
*/
|
||||
protected function getDoctrineDriver()
|
||||
{
|
||||
return new DoctrineDriver;
|
||||
}
|
||||
|
||||
}
|
923
vendor/illuminate/database/Schema/Blueprint.php
vendored
Executable file
923
vendor/illuminate/database/Schema/Blueprint.php
vendored
Executable file
@ -0,0 +1,923 @@
|
||||
<?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|null $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->getAddedColumns()) > 0 && ! $this->creating())
|
||||
{
|
||||
array_unshift($this->commands, $this->createCommand('add'));
|
||||
}
|
||||
|
||||
if (count($this->getChangedColumns()) > 0 && ! $this->creating())
|
||||
{
|
||||
array_unshift($this->commands, $this->createCommand('change'));
|
||||
}
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the soft delete column should be dropped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropSoftDeletes()
|
||||
{
|
||||
$this->dropColumn('deleted_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 char column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $length
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function char($column, $length = 255)
|
||||
{
|
||||
return $this->addColumn('char', $column, compact('length'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function mediumInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('mediumInteger', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new tiny integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function tinyInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('tinyInteger', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new small integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function smallInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('smallInteger', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new unsigned integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @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
|
||||
* @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 double column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int|null $total
|
||||
* @param int|null $places
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function double($column, $total = null, $places = null)
|
||||
{
|
||||
return $this->addColumn('double', $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 json column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function json($column)
|
||||
{
|
||||
return $this->addColumn('json', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new jsonb column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function jsonb($column)
|
||||
{
|
||||
return $this->addColumn('jsonb', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 date-time column (with time zone) on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dateTimeTz($column)
|
||||
{
|
||||
return $this->addColumn('dateTimeTz', $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 time column (with time zone) on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function timeTz($column)
|
||||
{
|
||||
return $this->addColumn('timeTz', $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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new timestamp (with time zone) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function timestampTz($column)
|
||||
{
|
||||
return $this->addColumn('timestampTz', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add nullable creation and update timestamps to the table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function nullableTimestamps()
|
||||
{
|
||||
$this->timestamp('created_at')->nullable();
|
||||
|
||||
$this->timestamp('updated_at')->nullable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function softDeletes()
|
||||
{
|
||||
return $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
|
||||
* @param string|null $indexName
|
||||
* @return void
|
||||
*/
|
||||
public function morphs($name, $indexName = null)
|
||||
{
|
||||
$this->unsignedInteger("{$name}_id");
|
||||
|
||||
$this->string("{$name}_type");
|
||||
|
||||
$this->index(array("{$name}_id", "{$name}_type"), $indexName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the `remember_token` column to the table.
|
||||
*
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function rememberToken()
|
||||
{
|
||||
return $this->string('remember_token', 100)->nullable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 build 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)
|
||||
{
|
||||
$index = strtolower($this->table.'_'.implode('_', $columns).'_'.$type);
|
||||
|
||||
return str_replace(array('-', '.'), '_', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a column from the schema blueprint.
|
||||
*
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function removeColumn($name)
|
||||
{
|
||||
$this->columns = array_values(array_filter($this->columns, function($c) use ($name)
|
||||
{
|
||||
return $c['attributes']['name'] != $name;
|
||||
}));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 on the blueprint.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the commands on the blueprint.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCommands()
|
||||
{
|
||||
return $this->commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columns on the blueprint that should be added.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddedColumns()
|
||||
{
|
||||
return array_filter($this->columns, function($column)
|
||||
{
|
||||
return !$column->change;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columns on the blueprint that should be changed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getChangedColumns()
|
||||
{
|
||||
return array_filter($this->columns, function($column)
|
||||
{
|
||||
return !!$column->change;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
242
vendor/illuminate/database/Schema/Builder.php
vendored
Executable file
242
vendor/illuminate/database/Schema/Builder.php
vendored
Executable file
@ -0,0 +1,242 @@
|
||||
<?php namespace Illuminate\Database\Schema;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Connection;
|
||||
|
||||
class Builder {
|
||||
|
||||
/**
|
||||
* The database connection instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The schema grammar instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Schema\Grammars\Grammar
|
||||
*/
|
||||
protected $grammar;
|
||||
|
||||
/**
|
||||
* The Blueprint resolver callback.
|
||||
*
|
||||
* @var \Closure
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$column = strtolower($column);
|
||||
|
||||
return in_array($column, array_map('strtolower', $this->getColumnListing($table)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given table has given columns.
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $columns
|
||||
* @return bool
|
||||
*/
|
||||
public function hasColumns($table, array $columns)
|
||||
{
|
||||
$tableColumns = array_map('strtolower', $this->getColumnListing($table));
|
||||
|
||||
foreach ($columns as $column)
|
||||
{
|
||||
if ( ! in_array(strtolower($column), $tableColumns)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column listing for a given table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function getColumnListing($table)
|
||||
{
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
|
||||
$results = $this->connection->select($this->grammar->compileColumnExists($table));
|
||||
|
||||
return $this->connection->getPostProcessor()->processColumnListing($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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|null $callback
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
protected function createBlueprint($table, Closure $callback = null)
|
||||
{
|
||||
if (isset($this->resolver))
|
||||
{
|
||||
return call_user_func($this->resolver, $table, $callback);
|
||||
}
|
||||
|
||||
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 $this
|
||||
*/
|
||||
public function setConnection(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Schema Blueprint resolver callback.
|
||||
*
|
||||
* @param \Closure $resolver
|
||||
* @return void
|
||||
*/
|
||||
public function blueprintResolver(Closure $resolver)
|
||||
{
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
}
|
458
vendor/illuminate/database/Schema/Grammars/Grammar.php
vendored
Executable file
458
vendor/illuminate/database/Schema/Grammars/Grammar.php
vendored
Executable file
@ -0,0 +1,458 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Illuminate\Support\Fluent;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\TableDiff;
|
||||
use Illuminate\Database\Connection;
|
||||
use Doctrine\DBAL\Schema\Comparator;
|
||||
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();
|
||||
|
||||
$table = $this->getTablePrefix().$blueprint->getTable();
|
||||
|
||||
$column = $connection->getDoctrineColumn($table, $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->getAddedColumns() 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
|
||||
* @param string $name
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function wrap($value, $prefixAlias = false)
|
||||
{
|
||||
if ($value instanceof Fluent) $value = $value->name;
|
||||
|
||||
return parent::wrap($value, $prefixAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 "'".(int) $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)
|
||||
{
|
||||
$table = $this->getTablePrefix().$blueprint->getTable();
|
||||
|
||||
$tableDiff = new TableDiff($table);
|
||||
|
||||
$tableDiff->fromTable = $schema->listTableDetails($table);
|
||||
|
||||
return $tableDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a change column command into a series of SQL statements.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return array
|
||||
*/
|
||||
public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
{
|
||||
$schema = $connection->getDoctrineSchemaManager();
|
||||
|
||||
$tableDiff = $this->getChangedDiff($blueprint, $schema);
|
||||
|
||||
if ($tableDiff !== false)
|
||||
{
|
||||
return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine table difference for the given changes.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff|bool
|
||||
*/
|
||||
protected function getChangedDiff(Blueprint $blueprint, SchemaManager $schema)
|
||||
{
|
||||
$table = $schema->listTableDetails($this->getTablePrefix().$blueprint->getTable());
|
||||
|
||||
return (new Comparator)->diffTable($table, $this->getTableWithColumnChanges($blueprint, $table));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a copy of the given Doctrine table after making the column changes.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
protected function getTableWithColumnChanges(Blueprint $blueprint, Table $table)
|
||||
{
|
||||
$table = clone $table;
|
||||
|
||||
foreach($blueprint->getChangedColumns() as $fluent)
|
||||
{
|
||||
$column = $this->getDoctrineColumnForChange($table, $fluent);
|
||||
|
||||
// Here we will spin through each fluent column definition and map it to the proper
|
||||
// Doctrine column definitions, which is necessasry because Laravel and Doctrine
|
||||
// use some different terminology for various column attributes on the tables.
|
||||
foreach ($fluent->getAttributes() as $key => $value)
|
||||
{
|
||||
if ( ! is_null($option = $this->mapFluentOptionToDoctrine($key)))
|
||||
{
|
||||
if (method_exists($column, $method = 'set'.ucfirst($option)))
|
||||
{
|
||||
$column->{$method}($this->mapFluentValueToDoctrine($option, $value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine column instance for a column change.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @param \Illuminate\Support\Fluent $fluent
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
protected function getDoctrineColumnForChange(Table $table, Fluent $fluent)
|
||||
{
|
||||
return $table->changeColumn(
|
||||
$fluent['name'], $this->getDoctrineColumnChangeOptions($fluent)
|
||||
)->getColumn($fluent['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine column change options.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $fluent
|
||||
* @return array
|
||||
*/
|
||||
protected function getDoctrineColumnChangeOptions(Fluent $fluent)
|
||||
{
|
||||
$options = ['type' => $this->getDoctrineColumnType($fluent['type'])];
|
||||
|
||||
if (in_array($fluent['type'], ['text', 'mediumText', 'longText']))
|
||||
{
|
||||
$options['length'] = $this->calculateDoctrineTextLength($fluent['type']);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the doctrine column type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return \Doctrine\DBAL\Types\Type
|
||||
*/
|
||||
protected function getDoctrineColumnType($type)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
|
||||
switch ($type) {
|
||||
case 'biginteger':
|
||||
$type = 'bigint';
|
||||
break;
|
||||
case 'smallinteger':
|
||||
$type = 'smallint';
|
||||
break;
|
||||
case 'mediumtext':
|
||||
case 'longtext':
|
||||
$type = 'text';
|
||||
break;
|
||||
}
|
||||
|
||||
return Type::getType($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the proper column length to force the Doctrine text type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return int
|
||||
*/
|
||||
protected function calculateDoctrineTextLength($type)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case 'mediumText':
|
||||
return 65535 + 1;
|
||||
|
||||
case 'longText':
|
||||
return 16777215 + 1;
|
||||
|
||||
default:
|
||||
return 255 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the matching Doctrine option for a given Fluent attribute name.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @return string
|
||||
*/
|
||||
protected function mapFluentOptionToDoctrine($attribute)
|
||||
{
|
||||
switch($attribute)
|
||||
{
|
||||
case 'type':
|
||||
case 'name':
|
||||
return;
|
||||
|
||||
case 'nullable':
|
||||
return 'notnull';
|
||||
|
||||
case 'total':
|
||||
return 'precision';
|
||||
|
||||
case 'places':
|
||||
return 'scale';
|
||||
|
||||
default:
|
||||
return $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the matching Doctrine value for a given Fluent attribute.
|
||||
*
|
||||
* @param string $option
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
protected function mapFluentValueToDoctrine($option, $value)
|
||||
{
|
||||
return $option == 'notnull' ? ! $value : $value;
|
||||
}
|
||||
|
||||
}
|
652
vendor/illuminate/database/Schema/Grammars/MySqlGrammar.php
vendored
Executable file
652
vendor/illuminate/database/Schema/Grammars/MySqlGrammar.php
vendored
Executable file
@ -0,0 +1,652 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class MySqlGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Unsigned', 'Nullable', 'Default', 'Increment', 'Comment', 'After');
|
||||
|
||||
/**
|
||||
* The possible column serials.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger');
|
||||
|
||||
/**
|
||||
* Compile the query to determine the list of tables.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return 'select * from information_schema.tables where table_schema = ? and table_name = ?';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the query to determine the list of columns.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileColumnExists()
|
||||
{
|
||||
return "select column_name from information_schema.columns 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 an add column 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 char type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeChar(Fluent $column)
|
||||
{
|
||||
return "char({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $this->typeDouble($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a double type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDouble(Fluent $column)
|
||||
{
|
||||
if ($column->total && $column->places)
|
||||
{
|
||||
return "double({$column->total}, {$column->places})";
|
||||
}
|
||||
|
||||
return 'double';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 an 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 json type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJson(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a jsonb type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJsonb(Fluent $column)
|
||||
{
|
||||
return "text";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTimeTz(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 time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimeTz(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 timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestampTz(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) && $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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an "comment" column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyComment(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->comment))
|
||||
{
|
||||
return ' comment "'.$column->comment.'"';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a single string in keyword identifiers.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function wrapValue($value)
|
||||
{
|
||||
if ($value === '*') return $value;
|
||||
|
||||
return '`'.str_replace('`', '``', $value).'`';
|
||||
}
|
||||
|
||||
}
|
544
vendor/illuminate/database/Schema/Grammars/PostgresGrammar.php
vendored
Executable file
544
vendor/illuminate/database/Schema/Grammars/PostgresGrammar.php
vendored
Executable file
@ -0,0 +1,544 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class PostgresGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Increment', 'Nullable', 'Default');
|
||||
|
||||
/**
|
||||
* The columns available as serials.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger');
|
||||
|
||||
/**
|
||||
* Compile the query to determine if a table exists.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return 'select * from information_schema.tables where table_name = ?';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the query to determine the list of columns.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function compileColumnExists($table)
|
||||
{
|
||||
return "select column_name from information_schema.columns where table_name = '$table'";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 char type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeChar(Fluent $column)
|
||||
{
|
||||
return "char({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $column->autoIncrement ? 'serial' : 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
{
|
||||
return $column->autoIncrement ? 'smallserial' : 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
{
|
||||
return $column->autoIncrement ? 'smallserial' : 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
{
|
||||
return $this->typeDouble($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a double type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDouble(Fluent $column)
|
||||
{
|
||||
return 'double precision';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 json type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJson(Fluent $column)
|
||||
{
|
||||
return "json";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a jsonb type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJsonb(Fluent $column)
|
||||
{
|
||||
return "jsonb";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(0) without time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTimeTz(Fluent $column)
|
||||
{
|
||||
return 'timestamp(0) with time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
{
|
||||
return 'time(0) without time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimeTz(Fluent $column)
|
||||
{
|
||||
return 'time(0) with time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
{
|
||||
return 'timestamp(0) without time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestampTz(Fluent $column)
|
||||
{
|
||||
return 'timestamp(0) with time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) && $column->autoIncrement)
|
||||
{
|
||||
return ' primary key';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
611
vendor/illuminate/database/Schema/Grammars/SQLiteGrammar.php
vendored
Executable file
611
vendor/illuminate/database/Schema/Grammars/SQLiteGrammar.php
vendored
Executable file
@ -0,0 +1,611 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class SQLiteGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* 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 the query to determine the list of columns.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function compileColumnExists($table)
|
||||
{
|
||||
return 'pragma table_info('.str_replace('.', '__', $table).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
|
||||
$statements = array();
|
||||
|
||||
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 char type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeChar(Fluent $column)
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 double type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDouble(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 'numeric';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 an enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a json type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJson(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a jsonb type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJsonb(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 date-time type.
|
||||
*
|
||||
* Note: "SQLite does not have a storage class set aside for storing dates and/or times."
|
||||
* @link https://www.sqlite.org/datatype3.html
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTimeTz(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 time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimeTz(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 timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestampTz(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 $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) && $column->autoIncrement)
|
||||
{
|
||||
return ' primary key autoincrement';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
552
vendor/illuminate/database/Schema/Grammars/SqlServerGrammar.php
vendored
Executable file
552
vendor/illuminate/database/Schema/Grammars/SqlServerGrammar.php
vendored
Executable file
@ -0,0 +1,552 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class SqlServerGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* 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 the query to determine the list of columns.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function compileColumnExists($table)
|
||||
{
|
||||
return "select col.name from sys.columns as col
|
||||
join sys.objects as obj on col.object_id = obj.object_id
|
||||
where obj.type = 'U' and obj.name = '$table'";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = \''.$blueprint->getTable().'\') drop table '.$blueprint->getTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = $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 char type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeChar(Fluent $column)
|
||||
{
|
||||
return "nchar({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 double type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDouble(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 'bit';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for an enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(255)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a json type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJson(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a jsonb type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJsonb(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTimeTz(Fluent $column)
|
||||
{
|
||||
return 'datetimeoffset(0)';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimeTz(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 timestamp type.
|
||||
*
|
||||
* @link https://msdn.microsoft.com/en-us/library/bb630289(v=sql.120).aspx
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestampTz(Fluent $column)
|
||||
{
|
||||
return 'datetimeoffset(0)';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) && $column->autoIncrement)
|
||||
{
|
||||
return ' identity primary key';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
41
vendor/illuminate/database/Schema/MySqlBuilder.php
vendored
Executable file
41
vendor/illuminate/database/Schema/MySqlBuilder.php
vendored
Executable file
@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column listing for a given table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function getColumnListing($table)
|
||||
{
|
||||
$sql = $this->grammar->compileColumnExists();
|
||||
|
||||
$database = $this->connection->getDatabaseName();
|
||||
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
|
||||
$results = $this->connection->select($sql, array($database, $table));
|
||||
|
||||
return $this->connection->getPostProcessor()->processColumnListing($results);
|
||||
}
|
||||
|
||||
}
|
55
vendor/illuminate/database/SeedServiceProvider.php
vendored
Executable file
55
vendor/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->singleton('seeder', function()
|
||||
{
|
||||
return new Seeder;
|
||||
});
|
||||
|
||||
$this->commands('command.seed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the seed console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerSeedCommand()
|
||||
{
|
||||
$this->app->singleton('command.seed', function($app)
|
||||
{
|
||||
return new SeedCommand($app['db']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('seeder', 'command.seed');
|
||||
}
|
||||
|
||||
}
|
101
vendor/illuminate/database/Seeder.php
vendored
Executable file
101
vendor/illuminate/database/Seeder.php
vendored
Executable file
@ -0,0 +1,101 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Container\Container;
|
||||
|
||||
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();
|
||||
|
||||
if (isset($this->command))
|
||||
{
|
||||
$this->command->getOutput()->writeln("<info>Seeded:</info> $class");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
$instance->setContainer($this->container);
|
||||
}
|
||||
else
|
||||
{
|
||||
$instance = new $class;
|
||||
}
|
||||
|
||||
if (isset($this->command))
|
||||
{
|
||||
$instance->setCommand($this->command);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IoC container instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @return $this
|
||||
*/
|
||||
public function setContainer(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the console command instance.
|
||||
*
|
||||
* @param \Illuminate\Console\Command $command
|
||||
* @return $this
|
||||
*/
|
||||
public function setCommand(Command $command)
|
||||
{
|
||||
$this->command = $command;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
92
vendor/illuminate/database/SqlServerConnection.php
vendored
Executable file
92
vendor/illuminate/database/SqlServerConnection.php
vendored
Executable file
@ -0,0 +1,92 @@
|
||||
<?php namespace Illuminate\Database;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as DoctrineDriver;
|
||||
use Illuminate\Database\Query\Processors\SqlServerProcessor;
|
||||
use Illuminate\Database\Query\Grammars\SqlServerGrammar as QueryGrammar;
|
||||
use Illuminate\Database\Schema\Grammars\SqlServerGrammar as SchemaGrammar;
|
||||
|
||||
class SqlServerConnection extends Connection {
|
||||
|
||||
/**
|
||||
* Execute a Closure within a transaction.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function transaction(Closure $callback)
|
||||
{
|
||||
if ($this->getDriverName() == 'sqlsrv')
|
||||
{
|
||||
return parent::transaction($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\SqlServerGrammar
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new QueryGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default schema grammar instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Schema\Grammars\SqlServerGrammar
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new SchemaGrammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default post processor instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Processors\Processor
|
||||
*/
|
||||
protected function getDefaultPostProcessor()
|
||||
{
|
||||
return new SqlServerProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine DBAL Driver.
|
||||
*
|
||||
* @return \Doctrine\DBAL\Driver\PDOSqlsrv\Driver
|
||||
*/
|
||||
protected function getDoctrineDriver()
|
||||
{
|
||||
return new DoctrineDriver;
|
||||
}
|
||||
|
||||
}
|
41
vendor/illuminate/database/composer.json
vendored
Executable file
41
vendor/illuminate/database/composer.json
vendored
Executable file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "illuminate/database",
|
||||
"description": "The Illuminate Database package.",
|
||||
"license": "MIT",
|
||||
"homepage": "http://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"keywords": ["laravel", "database", "sql", "orm"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/container": "5.0.*",
|
||||
"illuminate/contracts": "5.0.*",
|
||||
"illuminate/support": "5.0.*",
|
||||
"nesbot/carbon": "~1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Database\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.0-dev"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).",
|
||||
"illuminate/console": "Required to use the database commands (5.0.*).",
|
||||
"illuminate/events": "Required to use the observers with Eloquent (5.0.*).",
|
||||
"illuminate/filesystem": "Required to use the migrations (5.0.*)."
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
Reference in New Issue
Block a user