code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function setCommand(Command $command) { $this->command = $command; return $this; }
Set the console command instance. @param \Illuminate\Console\Command $command @return $this
setCommand
php
illuminate/database
Seeder.php
https://github.com/illuminate/database/blob/master/Seeder.php
MIT
public function __invoke(array $parameters = []) { if (! method_exists($this, 'run')) { throw new InvalidArgumentException('Method [run] missing from '.get_class($this)); } $callback = fn () => isset($this->container) ? $this->container->call([$this, 'run'], $parameters) : $this->run(...$parameters); $uses = array_flip(class_uses_recursive(static::class)); if (isset($uses[WithoutModelEvents::class])) { $callback = $this->withoutModelEvents($callback); } return $callback(); }
Run the database seeds. @param array $parameters @return mixed @throws \InvalidArgumentException
__invoke
php
illuminate/database
Seeder.php
https://github.com/illuminate/database/blob/master/Seeder.php
MIT
protected function escapeBinary($value) { $hex = bin2hex($value); return "x'{$hex}'"; }
Escape a binary value for safe SQL embedding. @param string $value @return string
escapeBinary
php
illuminate/database
SQLiteConnection.php
https://github.com/illuminate/database/blob/master/SQLiteConnection.php
MIT
protected function isUniqueConstraintError(Exception $exception) { return boolval(preg_match('#(column(s)? .* (is|are) not unique|UNIQUE constraint failed: .*)#i', $exception->getMessage())); }
Determine if the given database exception was caused by a unique constraint violation. @param \Exception $exception @return bool
isUniqueConstraintError
php
illuminate/database
SQLiteConnection.php
https://github.com/illuminate/database/blob/master/SQLiteConnection.php
MIT
protected function getDefaultQueryGrammar() { return new QueryGrammar($this); }
Get the default query grammar instance. @return \Illuminate\Database\Query\Grammars\SQLiteGrammar
getDefaultQueryGrammar
php
illuminate/database
SQLiteConnection.php
https://github.com/illuminate/database/blob/master/SQLiteConnection.php
MIT
public function getSchemaBuilder() { if (is_null($this->schemaGrammar)) { $this->useDefaultSchemaGrammar(); } return new SQLiteBuilder($this); }
Get a schema builder instance for the connection. @return \Illuminate\Database\Schema\SQLiteBuilder
getSchemaBuilder
php
illuminate/database
SQLiteConnection.php
https://github.com/illuminate/database/blob/master/SQLiteConnection.php
MIT
protected function getDefaultSchemaGrammar() { return new SchemaGrammar($this); }
Get the default schema grammar instance. @return \Illuminate\Database\Schema\Grammars\SQLiteGrammar
getDefaultSchemaGrammar
php
illuminate/database
SQLiteConnection.php
https://github.com/illuminate/database/blob/master/SQLiteConnection.php
MIT
public function getSchemaState(?Filesystem $files = null, ?callable $processFactory = null) { return new SqliteSchemaState($this, $files, $processFactory); }
Get the schema state for the connection. @param \Illuminate\Filesystem\Filesystem|null $files @param callable|null $processFactory @throws \RuntimeException
getSchemaState
php
illuminate/database
SQLiteConnection.php
https://github.com/illuminate/database/blob/master/SQLiteConnection.php
MIT
protected function getDefaultPostProcessor() { return new SQLiteProcessor; }
Get the default post processor instance. @return \Illuminate\Database\Query\Processors\SQLiteProcessor
getDefaultPostProcessor
php
illuminate/database
SQLiteConnection.php
https://github.com/illuminate/database/blob/master/SQLiteConnection.php
MIT
public function __construct($path) { parent::__construct("Database file at path [{$path}] does not exist. Ensure this is an absolute path to the database."); $this->path = $path; }
Create a new exception instance. @param string $path
__construct
php
illuminate/database
SQLiteDatabaseDoesNotExistException.php
https://github.com/illuminate/database/blob/master/SQLiteDatabaseDoesNotExistException.php
MIT
public function transaction(Closure $callback, $attempts = 1) { for ($a = 1; $a <= $attempts; $a++) { if ($this->getDriverName() === 'sqlsrv') { return parent::transaction($callback, $attempts); } $this->getPdo()->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->getPdo()->exec('COMMIT TRAN'); } // If we catch an exception, we will rollback 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 (Throwable $e) { $this->getPdo()->exec('ROLLBACK TRAN'); throw $e; } return $result; } }
Execute a Closure within a transaction. @param \Closure $callback @param int $attempts @return mixed @throws \Throwable
transaction
php
illuminate/database
SqlServerConnection.php
https://github.com/illuminate/database/blob/master/SqlServerConnection.php
MIT
protected function escapeBinary($value) { $hex = bin2hex($value); return "0x{$hex}"; }
Escape a binary value for safe SQL embedding. @param string $value @return string
escapeBinary
php
illuminate/database
SqlServerConnection.php
https://github.com/illuminate/database/blob/master/SqlServerConnection.php
MIT
protected function isUniqueConstraintError(Exception $exception) { return boolval(preg_match('#Cannot insert duplicate key row in object#i', $exception->getMessage())); }
Determine if the given database exception was caused by a unique constraint violation. @param \Exception $exception @return bool
isUniqueConstraintError
php
illuminate/database
SqlServerConnection.php
https://github.com/illuminate/database/blob/master/SqlServerConnection.php
MIT
protected function getDefaultQueryGrammar() { return new QueryGrammar($this); }
Get the default query grammar instance. @return \Illuminate\Database\Query\Grammars\SqlServerGrammar
getDefaultQueryGrammar
php
illuminate/database
SqlServerConnection.php
https://github.com/illuminate/database/blob/master/SqlServerConnection.php
MIT
public function getSchemaBuilder() { if (is_null($this->schemaGrammar)) { $this->useDefaultSchemaGrammar(); } return new SqlServerBuilder($this); }
Get a schema builder instance for the connection. @return \Illuminate\Database\Schema\SqlServerBuilder
getSchemaBuilder
php
illuminate/database
SqlServerConnection.php
https://github.com/illuminate/database/blob/master/SqlServerConnection.php
MIT
protected function getDefaultSchemaGrammar() { return new SchemaGrammar($this); }
Get the default schema grammar instance. @return \Illuminate\Database\Schema\Grammars\SqlServerGrammar
getDefaultSchemaGrammar
php
illuminate/database
SqlServerConnection.php
https://github.com/illuminate/database/blob/master/SqlServerConnection.php
MIT
public function getSchemaState(?Filesystem $files = null, ?callable $processFactory = null) { throw new RuntimeException('Schema dumping is not supported when using SQL Server.'); }
Get the schema state for the connection. @param \Illuminate\Filesystem\Filesystem|null $files @param callable|null $processFactory @throws \RuntimeException
getSchemaState
php
illuminate/database
SqlServerConnection.php
https://github.com/illuminate/database/blob/master/SqlServerConnection.php
MIT
protected function getDefaultPostProcessor() { return new SqlServerProcessor; }
Get the default post processor instance. @return \Illuminate\Database\Query\Processors\SqlServerProcessor
getDefaultPostProcessor
php
illuminate/database
SqlServerConnection.php
https://github.com/illuminate/database/blob/master/SqlServerConnection.php
MIT
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 work correctly out of the box without extreme configuration. $this->setupDefaultConfiguration(); $this->setupManager(); }
Create a new database capsule manager. @param \Illuminate\Container\Container|null $container
__construct
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
protected function setupDefaultConfiguration() { $this->container['config']['database.fetch'] = PDO::FETCH_OBJ; $this->container['config']['database.default'] = 'default'; }
Setup the default database configuration options. @return void
setupDefaultConfiguration
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
protected function setupManager() { $factory = new ConnectionFactory($this->container); $this->manager = new DatabaseManager($this->container, $factory); }
Build the database manager instance. @return void
setupManager
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public static function connection($connection = null) { return static::$instance->getConnection($connection); }
Get a connection instance from the global manager. @param string|null $connection @return \Illuminate\Database\Connection
connection
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public static function table($table, $as = null, $connection = null) { return static::$instance->connection($connection)->table($table, $as); }
Get a fluent query builder instance. @param \Closure|\Illuminate\Database\Query\Builder|string $table @param string|null $as @param string|null $connection @return \Illuminate\Database\Query\Builder
table
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public static function schema($connection = null) { return static::$instance->connection($connection)->getSchemaBuilder(); }
Get a schema builder instance. @param string|null $connection @return \Illuminate\Database\Schema\Builder
schema
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public function getConnection($name = null) { return $this->manager->connection($name); }
Get a registered connection instance. @param string|null $name @return \Illuminate\Database\Connection
getConnection
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public function addConnection(array $config, $name = 'default') { $connections = $this->container['config']['database.connections']; $connections[$name] = $config; $this->container['config']['database.connections'] = $connections; }
Register a connection with the manager. @param array $config @param string $name @return void
addConnection
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
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, it is not necessary to operate. if ($dispatcher = $this->getEventDispatcher()) { Eloquent::setEventDispatcher($dispatcher); } }
Bootstrap Eloquent so it is ready for usage. @return void
bootEloquent
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public function setFetchMode($fetchMode) { $this->container['config']['database.fetch'] = $fetchMode; return $this; }
Set the fetch mode for the database connections. @param int $fetchMode @return $this
setFetchMode
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public function getDatabaseManager() { return $this->manager; }
Get the database manager instance. @return \Illuminate\Database\DatabaseManager
getDatabaseManager
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public function getEventDispatcher() { if ($this->container->bound('events')) { return $this->container['events']; } }
Get the current event dispatcher instance. @return \Illuminate\Contracts\Events\Dispatcher|null
getEventDispatcher
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public function setEventDispatcher(Dispatcher $dispatcher) { $this->container->instance('events', $dispatcher); }
Set the event dispatcher instance to be used by connections. @param \Illuminate\Contracts\Events\Dispatcher $dispatcher @return void
setEventDispatcher
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public static function __callStatic($method, $parameters) { return static::connection()->$method(...$parameters); }
Dynamically pass methods to the default connection. @param string $method @param array $parameters @return mixed
__callStatic
php
illuminate/database
Capsule/Manager.php
https://github.com/illuminate/database/blob/master/Capsule/Manager.php
MIT
public function chunk($count, callable $callback) { $this->enforceOrderBy(); $skip = $this->getOffset(); $remaining = $this->getLimit(); $page = 1; do { $offset = (($page - 1) * $count) + intval($skip); $limit = is_null($remaining) ? $count : min($count, $remaining); if ($limit == 0) { break; } $results = $this->offset($offset)->limit($limit)->get(); $countResults = $results->count(); if ($countResults == 0) { break; } if (! is_null($remaining)) { $remaining = max($remaining - $countResults, 0); } if ($callback($results, $page) === false) { return false; } unset($results); $page++; } while ($countResults == $count); return true; }
Chunk the results of the query. @param int $count @param callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback @return bool
chunk
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function chunkMap(callable $callback, $count = 1000) { $collection = new Collection; $this->chunk($count, function ($items) use ($collection, $callback) { $items->each(function ($item) use ($collection, $callback) { $collection->push($callback($item)); }); }); return $collection; }
Run a map over each item while chunking. @template TReturn @param callable(TValue): TReturn $callback @param int $count @return \Illuminate\Support\Collection<int, TReturn>
chunkMap
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function each(callable $callback, $count = 1000) { return $this->chunk($count, function ($results) use ($callback) { foreach ($results as $key => $value) { if ($callback($value, $key) === false) { return false; } } }); }
Execute a callback over each item while chunking. @param callable(TValue, int): mixed $callback @param int $count @return bool @throws \RuntimeException
each
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function chunkById($count, callable $callback, $column = null, $alias = null) { return $this->orderedChunkById($count, $callback, $column, $alias); }
Chunk the results of a query by comparing IDs. @param int $count @param callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback @param string|null $column @param string|null $alias @return bool
chunkById
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function chunkByIdDesc($count, callable $callback, $column = null, $alias = null) { return $this->orderedChunkById($count, $callback, $column, $alias, descending: true); }
Chunk the results of a query by comparing IDs in descending order. @param int $count @param callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback @param string|null $column @param string|null $alias @return bool
chunkByIdDesc
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function orderedChunkById($count, callable $callback, $column = null, $alias = null, $descending = false) { $column ??= $this->defaultKeyName(); $alias ??= $column; $lastId = null; $skip = $this->getOffset(); $remaining = $this->getLimit(); $page = 1; do { $clone = clone $this; if ($skip && $page > 1) { $clone->offset(0); } $limit = is_null($remaining) ? $count : min($count, $remaining); if ($limit == 0) { break; } // We'll execute the query for the given page and get the results. If there are // no results we can just break and return from here. When there are results // we will call the callback with the current chunk of these results here. if ($descending) { $results = $clone->forPageBeforeId($limit, $lastId, $column)->get(); } else { $results = $clone->forPageAfterId($limit, $lastId, $column)->get(); } $countResults = $results->count(); if ($countResults == 0) { break; } if (! is_null($remaining)) { $remaining = max($remaining - $countResults, 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. if ($callback($results, $page) === false) { return false; } $lastId = data_get($results->last(), $alias); if ($lastId === null) { throw new RuntimeException("The chunkById operation was aborted because the [{$alias}] column is not present in the query result."); } unset($results); $page++; } while ($countResults == $count); return true; }
Chunk the results of a query by comparing IDs in a given order. @param int $count @param callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback @param string|null $column @param string|null $alias @param bool $descending @return bool @throws \RuntimeException
orderedChunkById
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function eachById(callable $callback, $count = 1000, $column = null, $alias = null) { return $this->chunkById($count, function ($results, $page) use ($callback, $count) { foreach ($results as $key => $value) { if ($callback($value, (($page - 1) * $count) + $key) === false) { return false; } } }, $column, $alias); }
Execute a callback over each item while chunking by ID. @param callable(TValue, int): mixed $callback @param int $count @param string|null $column @param string|null $alias @return bool
eachById
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function lazy($chunkSize = 1000) { if ($chunkSize < 1) { throw new InvalidArgumentException('The chunk size should be at least 1'); } $this->enforceOrderBy(); return new LazyCollection(function () use ($chunkSize) { $page = 1; while (true) { $results = $this->forPage($page++, $chunkSize)->get(); foreach ($results as $result) { yield $result; } if ($results->count() < $chunkSize) { return; } } }); }
Query lazily, by chunks of the given size. @param int $chunkSize @return \Illuminate\Support\LazyCollection<int, TValue> @throws \InvalidArgumentException
lazy
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function lazyById($chunkSize = 1000, $column = null, $alias = null) { return $this->orderedLazyById($chunkSize, $column, $alias); }
Query lazily, by chunking the results of a query by comparing IDs. @param int $chunkSize @param string|null $column @param string|null $alias @return \Illuminate\Support\LazyCollection<int, TValue> @throws \InvalidArgumentException
lazyById
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function lazyByIdDesc($chunkSize = 1000, $column = null, $alias = null) { return $this->orderedLazyById($chunkSize, $column, $alias, true); }
Query lazily, by chunking the results of a query by comparing IDs in descending order. @param int $chunkSize @param string|null $column @param string|null $alias @return \Illuminate\Support\LazyCollection<int, TValue> @throws \InvalidArgumentException
lazyByIdDesc
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
protected function orderedLazyById($chunkSize = 1000, $column = null, $alias = null, $descending = false) { if ($chunkSize < 1) { throw new InvalidArgumentException('The chunk size should be at least 1'); } $column ??= $this->defaultKeyName(); $alias ??= $column; return new LazyCollection(function () use ($chunkSize, $column, $alias, $descending) { $lastId = null; while (true) { $clone = clone $this; if ($descending) { $results = $clone->forPageBeforeId($chunkSize, $lastId, $column)->get(); } else { $results = $clone->forPageAfterId($chunkSize, $lastId, $column)->get(); } foreach ($results as $result) { yield $result; } if ($results->count() < $chunkSize) { return; } $lastId = $results->last()->{$alias}; if ($lastId === null) { throw new RuntimeException("The lazyById operation was aborted because the [{$alias}] column is not present in the query result."); } } }); }
Query lazily, by chunking the results of a query by comparing IDs in a given order. @param int $chunkSize @param string|null $column @param string|null $alias @param bool $descending @return \Illuminate\Support\LazyCollection @throws \InvalidArgumentException
orderedLazyById
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function first($columns = ['*']) { return $this->take(1)->get($columns)->first(); }
Execute the query and get the first result. @param array|string $columns @return TValue|null
first
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function firstOrFail($columns = ['*'], $message = null) { if (! is_null($result = $this->first($columns))) { return $result; } throw new RecordNotFoundException($message ?: 'No record found for the given query.'); }
Execute the query and get the first result or throw an exception. @param array|string $columns @param string|null $message @return TValue @throws \Illuminate\Database\RecordNotFoundException
firstOrFail
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function sole($columns = ['*']) { $result = $this->take(2)->get($columns); $count = $result->count(); if ($count === 0) { throw new RecordsNotFoundException; } if ($count > 1) { throw new MultipleRecordsFoundException($count); } return $result->first(); }
Execute the query and get the first result if it's the sole matching record. @param array|string $columns @return TValue @throws \Illuminate\Database\RecordsNotFoundException @throws \Illuminate\Database\MultipleRecordsFoundException
sole
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
protected function paginateUsingCursor($perPage, $columns = ['*'], $cursorName = 'cursor', $cursor = null) { if (! $cursor instanceof Cursor) { $cursor = is_string($cursor) ? Cursor::fromEncoded($cursor) : CursorPaginator::resolveCurrentCursor($cursorName, $cursor); } $orders = $this->ensureOrderForCursorPagination(! is_null($cursor) && $cursor->pointsToPreviousItems()); if (! is_null($cursor)) { // Reset the union bindings so we can add the cursor where in the correct position... $this->setBindings([], 'union'); $addCursorConditions = function (self $builder, $previousColumn, $originalColumn, $i) use (&$addCursorConditions, $cursor, $orders) { $unionBuilders = $builder->getUnionBuilders(); if (! is_null($previousColumn)) { $originalColumn ??= $this->getOriginalColumnNameForCursorPagination($this, $previousColumn); $builder->where( Str::contains($originalColumn, ['(', ')']) ? new Expression($originalColumn) : $originalColumn, '=', $cursor->parameter($previousColumn) ); $unionBuilders->each(function ($unionBuilder) use ($previousColumn, $cursor) { $unionBuilder->where( $this->getOriginalColumnNameForCursorPagination($unionBuilder, $previousColumn), '=', $cursor->parameter($previousColumn) ); $this->addBinding($unionBuilder->getRawBindings()['where'], 'union'); }); } $builder->where(function (self $secondBuilder) use ($addCursorConditions, $cursor, $orders, $i, $unionBuilders) { ['column' => $column, 'direction' => $direction] = $orders[$i]; $originalColumn = $this->getOriginalColumnNameForCursorPagination($this, $column); $secondBuilder->where( Str::contains($originalColumn, ['(', ')']) ? new Expression($originalColumn) : $originalColumn, $direction === 'asc' ? '>' : '<', $cursor->parameter($column) ); if ($i < $orders->count() - 1) { $secondBuilder->orWhere(function (self $thirdBuilder) use ($addCursorConditions, $column, $originalColumn, $i) { $addCursorConditions($thirdBuilder, $column, $originalColumn, $i + 1); }); } $unionBuilders->each(function ($unionBuilder) use ($column, $direction, $cursor, $i, $orders, $addCursorConditions) { $unionWheres = $unionBuilder->getRawBindings()['where']; $originalColumn = $this->getOriginalColumnNameForCursorPagination($unionBuilder, $column); $unionBuilder->where(function ($unionBuilder) use ($column, $direction, $cursor, $i, $orders, $addCursorConditions, $originalColumn, $unionWheres) { $unionBuilder->where( $originalColumn, $direction === 'asc' ? '>' : '<', $cursor->parameter($column) ); if ($i < $orders->count() - 1) { $unionBuilder->orWhere(function (self $fourthBuilder) use ($addCursorConditions, $column, $originalColumn, $i) { $addCursorConditions($fourthBuilder, $column, $originalColumn, $i + 1); }); } $this->addBinding($unionWheres, 'union'); $this->addBinding($unionBuilder->getRawBindings()['where'], 'union'); }); }); }); }; $addCursorConditions($this, null, null, 0); } $this->limit($perPage + 1); return $this->cursorPaginator($this->get($columns), $perPage, $cursor, [ 'path' => Paginator::resolveCurrentPath(), 'cursorName' => $cursorName, 'parameters' => $orders->pluck('column')->toArray(), ]); }
Paginate the given query using a cursor paginator. @param int $perPage @param array|string $columns @param string $cursorName @param \Illuminate\Pagination\Cursor|string|null $cursor @return \Illuminate\Contracts\Pagination\CursorPaginator
paginateUsingCursor
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
protected function getOriginalColumnNameForCursorPagination($builder, string $parameter) { $columns = $builder instanceof Builder ? $builder->getQuery()->getColumns() : $builder->getColumns(); if (! is_null($columns)) { foreach ($columns as $column) { if (($position = strripos($column, ' as ')) !== false) { $original = substr($column, 0, $position); $alias = substr($column, $position + 4); if ($parameter === $alias || $builder->getGrammar()->wrap($parameter) === $alias) { return $original; } } } } return $parameter; }
Get the original column name of the given column, without any aliasing. @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*> $builder @param string $parameter @return string
getOriginalColumnNameForCursorPagination
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
protected function paginator($items, $total, $perPage, $currentPage, $options) { return Container::getInstance()->makeWith(LengthAwarePaginator::class, compact( 'items', 'total', 'perPage', 'currentPage', 'options' )); }
Create a new length-aware paginator instance. @param \Illuminate\Support\Collection $items @param int $total @param int $perPage @param int $currentPage @param array $options @return \Illuminate\Pagination\LengthAwarePaginator
paginator
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
protected function simplePaginator($items, $perPage, $currentPage, $options) { return Container::getInstance()->makeWith(Paginator::class, compact( 'items', 'perPage', 'currentPage', 'options' )); }
Create a new simple paginator instance. @param \Illuminate\Support\Collection $items @param int $perPage @param int $currentPage @param array $options @return \Illuminate\Pagination\Paginator
simplePaginator
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
protected function cursorPaginator($items, $perPage, $cursor, $options) { return Container::getInstance()->makeWith(CursorPaginator::class, compact( 'items', 'perPage', 'cursor', 'options' )); }
Create a new cursor paginator instance. @param \Illuminate\Support\Collection $items @param int $perPage @param \Illuminate\Pagination\Cursor $cursor @param array $options @return \Illuminate\Pagination\CursorPaginator
cursorPaginator
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function tap($callback) { $callback($this); return $this; }
Pass the query to a given callback and then return it. @param callable($this): mixed $callback @return $this
tap
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function pipe($callback) { return $callback($this) ?? $this; }
Pass the query to a given callback and return the result. @template TReturn @param (callable($this): TReturn) $callback @return (TReturn is null|void ? $this : TReturn)
pipe
php
illuminate/database
Concerns/BuildsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsQueries.php
MIT
public function wherePast($columns) { return $this->wherePastOrFuture($columns, '<', 'and'); }
Add a where clause to determine if a "date" column is in the past to the query. @param array|string $columns @return $this
wherePast
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function whereNowOrPast($columns) { return $this->wherePastOrFuture($columns, '<=', 'and'); }
Add a where clause to determine if a "date" column is in the past or now to the query. @param array|string $columns @return $this
whereNowOrPast
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function orWherePast($columns) { return $this->wherePastOrFuture($columns, '<', 'or'); }
Add an "or where" clause to determine if a "date" column is in the past to the query. @param array|string $columns @return $this
orWherePast
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function orWhereNowOrPast($columns) { return $this->wherePastOrFuture($columns, '<=', 'or'); }
Add a where clause to determine if a "date" column is in the past or now to the query. @param array|string $columns @return $this
orWhereNowOrPast
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function whereFuture($columns) { return $this->wherePastOrFuture($columns, '>', 'and'); }
Add a where clause to determine if a "date" column is in the future to the query. @param array|string $columns @return $this
whereFuture
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function whereNowOrFuture($columns) { return $this->wherePastOrFuture($columns, '>=', 'and'); }
Add a where clause to determine if a "date" column is in the future or now to the query. @param array|string $columns @return $this
whereNowOrFuture
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function orWhereFuture($columns) { return $this->wherePastOrFuture($columns, '>', 'or'); }
Add an "or where" clause to determine if a "date" column is in the future to the query. @param array|string $columns @return $this
orWhereFuture
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function orWhereNowOrFuture($columns) { return $this->wherePastOrFuture($columns, '>=', 'or'); }
Add an "or where" clause to determine if a "date" column is in the future or now to the query. @param array|string $columns @return $this
orWhereNowOrFuture
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
protected function wherePastOrFuture($columns, $operator, $boolean) { $type = 'Basic'; $value = Carbon::now(); foreach (Arr::wrap($columns) as $column) { $this->wheres[] = compact('type', 'column', 'boolean', 'operator', 'value'); $this->addBinding($value); } return $this; }
Add an "where" clause to determine if a "date" column is in the past or future. @param array|string $columns @param string $operator @param string $boolean @return $this
wherePastOrFuture
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function whereToday($columns, $boolean = 'and') { return $this->whereTodayBeforeOrAfter($columns, '=', $boolean); }
Add a "where date" clause to determine if a "date" column is today to the query. @param array|string $columns @param string $boolean @return $this
whereToday
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function whereBeforeToday($columns) { return $this->whereTodayBeforeOrAfter($columns, '<', 'and'); }
Add a "where date" clause to determine if a "date" column is before today. @param array|string $columns @return $this
whereBeforeToday
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function whereTodayOrBefore($columns) { return $this->whereTodayBeforeOrAfter($columns, '<=', 'and'); }
Add a "where date" clause to determine if a "date" column is today or before to the query. @param array|string $columns @return $this
whereTodayOrBefore
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function whereAfterToday($columns) { return $this->whereTodayBeforeOrAfter($columns, '>', 'and'); }
Add a "where date" clause to determine if a "date" column is after today. @param array|string $columns @return $this
whereAfterToday
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function whereTodayOrAfter($columns) { return $this->whereTodayBeforeOrAfter($columns, '>=', 'and'); }
Add a "where date" clause to determine if a "date" column is today or after to the query. @param array|string $columns @return $this
whereTodayOrAfter
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function orWhereToday($columns) { return $this->whereToday($columns, 'or'); }
Add an "or where date" clause to determine if a "date" column is today to the query. @param array|string $columns @return $this
orWhereToday
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function orWhereBeforeToday($columns) { return $this->whereTodayBeforeOrAfter($columns, '<', 'or'); }
Add an "or where date" clause to determine if a "date" column is before today. @param array|string $columns @return $this
orWhereBeforeToday
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function orWhereTodayOrBefore($columns) { return $this->whereTodayBeforeOrAfter($columns, '<=', 'or'); }
Add an "or where date" clause to determine if a "date" column is today or before to the query. @param array|string $columns @return $this
orWhereTodayOrBefore
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function orWhereAfterToday($columns) { return $this->whereTodayBeforeOrAfter($columns, '>', 'or'); }
Add an "or where date" clause to determine if a "date" column is after today. @param array|string $columns @return $this
orWhereAfterToday
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
public function orWhereTodayOrAfter($columns) { return $this->whereTodayBeforeOrAfter($columns, '>=', 'or'); }
Add an "or where date" clause to determine if a "date" column is today or after to the query. @param array|string $columns @return $this
orWhereTodayOrAfter
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
protected function whereTodayBeforeOrAfter($columns, $operator, $boolean) { $value = Carbon::today()->format('Y-m-d'); foreach (Arr::wrap($columns) as $column) { $this->addDateBasedWhere('Date', $column, $operator, $value, $boolean); } return $this; }
Add a "where date" clause to determine if a "date" column is today or after to the query. @param array|string $columns @param string $operator @param string $boolean @return $this
whereTodayBeforeOrAfter
php
illuminate/database
Concerns/BuildsWhereDateClauses.php
https://github.com/illuminate/database/blob/master/Concerns/BuildsWhereDateClauses.php
MIT
protected function wrapJsonFieldAndPath($column) { $parts = explode('->', $column, 2); $field = $this->wrap($parts[0]); $path = count($parts) > 1 ? ', '.$this->wrapJsonPath($parts[1], '->') : ''; return [$field, $path]; }
Split the given JSON selector into the field and the optional path and wrap them separately. @param string $column @return array
wrapJsonFieldAndPath
php
illuminate/database
Concerns/CompilesJsonPaths.php
https://github.com/illuminate/database/blob/master/Concerns/CompilesJsonPaths.php
MIT
protected function wrapJsonPathSegment($segment) { if (preg_match('/(\[[^\]]+\])+$/', $segment, $parts)) { $key = Str::beforeLast($segment, $parts[0]); if (! empty($key)) { return '"'.$key.'"'.$parts[0]; } return $parts[0]; } return '"'.$segment.'"'; }
Wrap the given JSON path segment. @param string $segment @return string
wrapJsonPathSegment
php
illuminate/database
Concerns/CompilesJsonPaths.php
https://github.com/illuminate/database/blob/master/Concerns/CompilesJsonPaths.php
MIT
public function explain() { $sql = $this->toSql(); $bindings = $this->getBindings(); $explanation = $this->getConnection()->select('EXPLAIN '.$sql, $bindings); return new Collection($explanation); }
Explains the query. @return \Illuminate\Support\Collection
explain
php
illuminate/database
Concerns/ExplainsQueries.php
https://github.com/illuminate/database/blob/master/Concerns/ExplainsQueries.php
MIT
public function transaction(Closure $callback, $attempts = 1) { for ($currentAttempt = 1; $currentAttempt <= $attempts; $currentAttempt++) { $this->beginTransaction(); // We'll simply execute the given callback within a try / catch block and if we // catch any exception we can rollback this transaction so that none of this // gets actually persisted to a database or stored in a permanent fashion. try { $callbackResult = $callback($this); } // If we catch an exception we'll rollback this transaction and try again if we // are not out of attempts. If we are out of attempts we will just throw the // exception back out, and let the developer handle an uncaught exception. catch (Throwable $e) { $this->handleTransactionException( $e, $currentAttempt, $attempts ); continue; } $levelBeingCommitted = $this->transactions; try { if ($this->transactions == 1) { $this->fireConnectionEvent('committing'); $this->getPdo()->commit(); } $this->transactions = max(0, $this->transactions - 1); } catch (Throwable $e) { $this->handleCommitTransactionException( $e, $currentAttempt, $attempts ); continue; } $this->transactionsManager?->commit( $this->getName(), $levelBeingCommitted, $this->transactions ); $this->fireConnectionEvent('committed'); return $callbackResult; } }
@template TReturn of mixed Execute a Closure within a transaction. @param (\Closure(static): TReturn) $callback @param int $attempts @return TReturn @throws \Throwable
transaction
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
protected function handleTransactionException(Throwable $e, $currentAttempt, $maxAttempts) { // On a deadlock, MySQL rolls back the entire transaction so we can't just // retry the query. We have to throw this exception all the way out and // let the developer handle it in another way. We will decrement too. if ($this->causedByConcurrencyError($e) && $this->transactions > 1) { $this->transactions--; $this->transactionsManager?->rollback( $this->getName(), $this->transactions ); throw new DeadlockException($e->getMessage(), is_int($e->getCode()) ? $e->getCode() : 0, $e); } // If there was an exception we will rollback this transaction and then we // can check if we have exceeded the maximum attempt count for this and // if we haven't we will return and try this query again in our loop. $this->rollBack(); if ($this->causedByConcurrencyError($e) && $currentAttempt < $maxAttempts) { return; } throw $e; }
Handle an exception encountered when running a transacted statement. @param \Throwable $e @param int $currentAttempt @param int $maxAttempts @return void @throws \Throwable
handleTransactionException
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
public function beginTransaction() { foreach ($this->beforeStartingTransaction as $callback) { $callback($this); } $this->createTransaction(); $this->transactions++; $this->transactionsManager?->begin( $this->getName(), $this->transactions ); $this->fireConnectionEvent('beganTransaction'); }
Start a new database transaction. @return void @throws \Throwable
beginTransaction
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
protected function createTransaction() { if ($this->transactions == 0) { $this->reconnectIfMissingConnection(); try { $this->getPdo()->beginTransaction(); } catch (Throwable $e) { $this->handleBeginTransactionException($e); } } elseif ($this->transactions >= 1 && $this->queryGrammar->supportsSavepoints()) { $this->createSavepoint(); } }
Create a transaction within the database. @return void @throws \Throwable
createTransaction
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
protected function createSavepoint() { $this->getPdo()->exec( $this->queryGrammar->compileSavepoint('trans'.($this->transactions + 1)) ); }
Create a save point within the database. @return void @throws \Throwable
createSavepoint
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
protected function handleBeginTransactionException(Throwable $e) { if ($this->causedByLostConnection($e)) { $this->reconnect(); $this->getPdo()->beginTransaction(); } else { throw $e; } }
Handle an exception from a transaction beginning. @param \Throwable $e @return void @throws \Throwable
handleBeginTransactionException
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
public function rollBack($toLevel = null) { // We allow developers to rollback to a certain transaction level. We will verify // that this given transaction level is valid before attempting to rollback to // that level. If it's not we will just return out and not attempt anything. $toLevel = is_null($toLevel) ? $this->transactions - 1 : $toLevel; if ($toLevel < 0 || $toLevel >= $this->transactions) { return; } // Next, we will actually perform this rollback within this database and fire the // rollback event. We will also set the current transaction level to the given // level that was passed into this method so it will be right from here out. try { $this->performRollBack($toLevel); } catch (Throwable $e) { $this->handleRollBackException($e); } $this->transactions = $toLevel; $this->transactionsManager?->rollback( $this->getName(), $this->transactions ); $this->fireConnectionEvent('rollingBack'); }
Rollback the active database transaction. @param int|null $toLevel @return void @throws \Throwable
rollBack
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
protected function performRollBack($toLevel) { if ($toLevel == 0) { $pdo = $this->getPdo(); if ($pdo->inTransaction()) { $pdo->rollBack(); } } elseif ($this->queryGrammar->supportsSavepoints()) { $this->getPdo()->exec( $this->queryGrammar->compileSavepointRollBack('trans'.($toLevel + 1)) ); } }
Perform a rollback within the database. @param int $toLevel @return void @throws \Throwable
performRollBack
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
protected function handleRollBackException(Throwable $e) { if ($this->causedByLostConnection($e)) { $this->transactions = 0; $this->transactionsManager?->rollback( $this->getName(), $this->transactions ); } throw $e; }
Handle an exception from a rollback. @param \Throwable $e @return void @throws \Throwable
handleRollBackException
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
public function transactionLevel() { return $this->transactions; }
Get the number of active transactions. @return int
transactionLevel
php
illuminate/database
Concerns/ManagesTransactions.php
https://github.com/illuminate/database/blob/master/Concerns/ManagesTransactions.php
MIT
protected function parseSearchPath($searchPath) { if (is_string($searchPath)) { preg_match_all('/[^\s,"\']+/', $searchPath, $matches); $searchPath = $matches[0]; } return array_map(function ($schema) { return trim($schema, '\'"'); }, $searchPath ?? []); }
Parse the Postgres "search_path" configuration value into an array. @param string|array|null $searchPath @return array
parseSearchPath
php
illuminate/database
Concerns/ParsesSearchPath.php
https://github.com/illuminate/database/blob/master/Concerns/ParsesSearchPath.php
MIT
public function __construct(Container $container) { $this->container = $container; }
Create a new connection factory instance. @param \Illuminate\Contracts\Container\Container $container
__construct
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
public function make(array $config, $name = null) { $config = $this->parseConfig($config, $name); if (isset($config['read'])) { return $this->createReadWriteConnection($config); } return $this->createSingleConnection($config); }
Establish a PDO connection based on the configuration. @param array $config @param string|null $name @return \Illuminate\Database\Connection
make
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function parseConfig(array $config, $name) { return Arr::add(Arr::add($config, 'prefix', ''), 'name', $name); }
Parse and prepare the database configuration. @param array $config @param string $name @return array
parseConfig
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function createSingleConnection(array $config) { $pdo = $this->createPdoResolver($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
createSingleConnection
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function createReadWriteConnection(array $config) { $connection = $this->createSingleConnection($this->getWriteConfig($config)); return $connection->setReadPdo($this->createReadPdo($config)); }
Create a read / write database connection instance. @param array $config @return \Illuminate\Database\Connection
createReadWriteConnection
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function createReadPdo(array $config) { return $this->createPdoResolver($this->getReadConfig($config)); }
Create a new PDO instance for reading. @param array $config @return \Closure
createReadPdo
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function getReadConfig(array $config) { return $this->mergeReadWriteConfig( $config, $this->getReadWriteConfig($config, 'read') ); }
Get the read configuration for a read / write connection. @param array $config @return array
getReadConfig
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function getWriteConfig(array $config) { return $this->mergeReadWriteConfig( $config, $this->getReadWriteConfig($config, 'write') ); }
Get the write configuration for a read / write connection. @param array $config @return array
getWriteConfig
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function getReadWriteConfig(array $config, $type) { return isset($config[$type][0]) ? Arr::random($config[$type]) : $config[$type]; }
Get a read / write level configuration. @param array $config @param string $type @return array
getReadWriteConfig
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function mergeReadWriteConfig(array $config, array $merge) { return Arr::except(array_merge($config, $merge), ['read', 'write']); }
Merge a configuration for a read / write connection. @param array $config @param array $merge @return array
mergeReadWriteConfig
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function createPdoResolver(array $config) { return array_key_exists('host', $config) ? $this->createPdoResolverWithHosts($config) : $this->createPdoResolverWithoutHosts($config); }
Create a new Closure that resolves to a PDO instance. @param array $config @return \Closure
createPdoResolver
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function createPdoResolverWithHosts(array $config) { return function () use ($config) { foreach (Arr::shuffle($this->parseHosts($config)) as $host) { $config['host'] = $host; try { return $this->createConnector($config)->connect($config); } catch (PDOException $e) { continue; } } if (isset($e)) { throw $e; } }; }
Create a new Closure that resolves to a PDO instance with a specific host or an array of hosts. @param array $config @return \Closure @throws \PDOException
createPdoResolverWithHosts
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT
protected function parseHosts(array $config) { $hosts = Arr::wrap($config['host']); if (empty($hosts)) { throw new InvalidArgumentException('Database hosts array is empty.'); } return $hosts; }
Parse the hosts configuration item into an array. @param array $config @return array @throws \InvalidArgumentException
parseHosts
php
illuminate/database
Connectors/ConnectionFactory.php
https://github.com/illuminate/database/blob/master/Connectors/ConnectionFactory.php
MIT