mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-03 20:27:59 +08:00
Merge branch 'master' of github.com:hyperf-cloud/hyperf
This commit is contained in:
commit
ad8013654c
@ -16,6 +16,7 @@
|
||||
"psr/http-message": "^1.0.1",
|
||||
"psr/http-server-middleware": "^1.0",
|
||||
"psr/event-dispatcher": "^0.7",
|
||||
"psr/simple-cache": "^1.0",
|
||||
"fig/http-message-util": "^1.1.2",
|
||||
"nikic/fast-route": "^1.3",
|
||||
"nikic/php-parser": "^4.1",
|
||||
|
@ -24,7 +24,8 @@
|
||||
"friendsofphp/php-cs-fixer": "^2.9"
|
||||
},
|
||||
"suggest": {
|
||||
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6)."
|
||||
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).",
|
||||
"nikic/php-parser": "Required to use ModelCommand (^4.1)."
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
|
58
src/database/src/Commands/Ast/ModelUpdateVistor.php
Normal file
58
src/database/src/Commands/Ast/ModelUpdateVistor.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://hyperf.org
|
||||
* @document https://wiki.hyperf.org
|
||||
* @contact group@hyperf.org
|
||||
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Hyperf\Database\Commands\Ast;
|
||||
|
||||
use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
class ModelUpdateVistor extends NodeVisitorAbstract
|
||||
{
|
||||
protected $columns = [];
|
||||
|
||||
public function __construct($columns = [])
|
||||
{
|
||||
$this->columns = $columns;
|
||||
}
|
||||
|
||||
public function leaveNode(Node $node)
|
||||
{
|
||||
switch ($node) {
|
||||
case $node instanceof Node\Stmt\PropertyProperty:
|
||||
if ('fillable' == $node->name) {
|
||||
$node = $this->rewriteFillable($node);
|
||||
}
|
||||
|
||||
return $node;
|
||||
case $node instanceof StaticPropertyFetch && $this->extends:
|
||||
// Rewrite parent::$staticProperty to ParentClass::$staticProperty.
|
||||
if ($node->class && 'parent' === $node->class->toString()) {
|
||||
$node->class = new Name($this->extends->toCodeString());
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function rewriteFillable(Node\Stmt\PropertyProperty $node)
|
||||
{
|
||||
$items = [];
|
||||
foreach ($this->columns as $column) {
|
||||
$items[] = new Node\Expr\ArrayItem(new Node\Scalar\String_($column));
|
||||
}
|
||||
|
||||
$node->default = new Node\Expr\Array_($items);
|
||||
return $node;
|
||||
}
|
||||
}
|
174
src/database/src/Commands/ModelCommand.php
Normal file
174
src/database/src/Commands/ModelCommand.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://hyperf.org
|
||||
* @document https://wiki.hyperf.org
|
||||
* @contact group@hyperf.org
|
||||
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Hyperf\Database\Commands;
|
||||
|
||||
use Hyperf\Database\Commands\Ast\ModelUpdateVistor;
|
||||
use Hyperf\Database\Connection;
|
||||
use Hyperf\Database\Schema\MySqlBuilder;
|
||||
use Hyperf\DbConnection\Pool\PoolFactory;
|
||||
use Hyperf\Utils\Str;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\ParserFactory;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ModelCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @var PoolFactory
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
/**
|
||||
* @var \PhpParser\Parser
|
||||
*/
|
||||
protected $astParser;
|
||||
|
||||
/**
|
||||
* @var Standard
|
||||
*/
|
||||
protected $printer;
|
||||
|
||||
/**
|
||||
* @var OutputInterface
|
||||
*/
|
||||
protected $output;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
parent::__construct('db:model');
|
||||
$this->container = $container;
|
||||
$this->factory = $container->get(PoolFactory::class);
|
||||
|
||||
$parserFactory = new ParserFactory();
|
||||
$this->astParser = $parserFactory->create(ParserFactory::ONLY_PHP7);
|
||||
$this->printer = new Standard();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->addArgument('table', InputArgument::OPTIONAL, 'Which table you want create.')
|
||||
->addOption('pool', 'p', InputOption::VALUE_OPTIONAL, 'Which pool you want use.', 'default')
|
||||
->addOption('path', 'path', InputOption::VALUE_OPTIONAL, 'Which pool you want use.', 'app/Models');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
|
||||
$table = $input->getArgument('table');
|
||||
$pool = $input->getOption('pool');
|
||||
$path = $input->getOption('path');
|
||||
$path = BASE_PATH . '/' . $path;
|
||||
if ($table) {
|
||||
$this->createModel($table, $pool, $path);
|
||||
} else {
|
||||
$this->createModels($pool, $path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MySqlBuilder
|
||||
*/
|
||||
protected function getSchemaBuilder($poolName)
|
||||
{
|
||||
$pool = $this->factory->getDbPool($poolName);
|
||||
/** @var Connection $connection */
|
||||
$connection = $pool->get()->getConnection();
|
||||
return $connection->getSchemaBuilder();
|
||||
}
|
||||
|
||||
protected function createModels($pool, $path)
|
||||
{
|
||||
$builder = $this->getSchemaBuilder($pool);
|
||||
$tables = [];
|
||||
|
||||
foreach ($builder->getAllTables() as $row) {
|
||||
$row = (array) $row;
|
||||
$tables[] = reset($row);
|
||||
}
|
||||
|
||||
foreach ($tables as $table) {
|
||||
$this->createModel($table, $pool, $path);
|
||||
}
|
||||
}
|
||||
|
||||
protected function createModel($table, $poolName, $path)
|
||||
{
|
||||
$builder = $this->getSchemaBuilder($poolName);
|
||||
|
||||
$columns = $builder->getColumnListing($table);
|
||||
|
||||
$class = Str::studly($table);
|
||||
$path = $path . '/' . $class . '.php';
|
||||
if (! file_exists($path)) {
|
||||
$code = $this->getOriginCode($table);
|
||||
file_put_contents($path, $code);
|
||||
}
|
||||
|
||||
$stms = $this->astParser->parse(file_get_contents($path));
|
||||
$traverser = new NodeTraverser();
|
||||
$traverser->addVisitor(new ModelUpdateVistor($columns));
|
||||
$stms = $traverser->traverse($stms);
|
||||
$code = $this->printer->prettyPrintFile($stms);
|
||||
|
||||
file_put_contents($path, $code);
|
||||
$this->output->writeln(sprintf('<info>Model %s is Created!</info>', $class));
|
||||
}
|
||||
|
||||
protected function getOriginCode($table)
|
||||
{
|
||||
$code = '<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://hyperf.org
|
||||
* @document https://wiki.hyperf.org
|
||||
* @contact group@hyperf.org
|
||||
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
class %s extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = \'%s\';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [];
|
||||
}';
|
||||
|
||||
return sprintf($code, Str::studly($table), $table);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -18,8 +19,7 @@ trait BuildsQueries
|
||||
/**
|
||||
* Chunk the results of the query.
|
||||
*
|
||||
* @param int $count
|
||||
* @param callable $callback
|
||||
* @param int $count
|
||||
* @return bool
|
||||
*/
|
||||
public function chunk($count, callable $callback)
|
||||
@ -36,20 +36,20 @@ trait BuildsQueries
|
||||
|
||||
$countResults = $results->count();
|
||||
|
||||
if ($countResults == 0) {
|
||||
if (0 == $countResults) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if (false === $callback($results, $page)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unset($results);
|
||||
|
||||
$page++;
|
||||
++$page;
|
||||
} while ($countResults == $count);
|
||||
|
||||
return true;
|
||||
@ -58,15 +58,14 @@ trait BuildsQueries
|
||||
/**
|
||||
* Execute a callback over each item while chunking.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param int $count
|
||||
* @param int $count
|
||||
* @return bool
|
||||
*/
|
||||
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) {
|
||||
if (false === $callback($value, $key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -76,7 +75,7 @@ trait BuildsQueries
|
||||
/**
|
||||
* Execute the query and get the first result.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return Model|object|static|null
|
||||
*/
|
||||
public function first($columns = ['*'])
|
||||
@ -87,9 +86,8 @@ trait BuildsQueries
|
||||
/**
|
||||
* Apply the callback's query changes if the given "value" is true.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param callable $callback
|
||||
* @param callable $default
|
||||
* @param callable $callback
|
||||
* @param callable $default
|
||||
* @return mixed|$this
|
||||
*/
|
||||
public function when($value, $callback, $default = null)
|
||||
@ -106,7 +104,7 @@ trait BuildsQueries
|
||||
/**
|
||||
* Pass the query to a given callback.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @param \Closure $callback
|
||||
* @return mixed|$this
|
||||
*/
|
||||
public function tap($callback)
|
||||
@ -117,14 +115,13 @@ trait BuildsQueries
|
||||
/**
|
||||
* Apply the callback's query changes if the given "value" is false.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param callable $callback
|
||||
* @param callable $default
|
||||
* @param callable $callback
|
||||
* @param callable $default
|
||||
* @return mixed|$this
|
||||
*/
|
||||
public function unless($value, $callback, $default = null)
|
||||
{
|
||||
if (!$value) {
|
||||
if (! $value) {
|
||||
return $callback($this, $value) ?: $this;
|
||||
} elseif ($default) {
|
||||
return $default($this, $value) ?: $this;
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -20,13 +21,12 @@ trait ManagesTransactions
|
||||
/**
|
||||
* Execute a Closure within a transaction.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception|\Throwable
|
||||
*/
|
||||
public function transaction(Closure $callback, int $attempts = 1)
|
||||
{
|
||||
for ($currentAttempt = 1; $currentAttempt <= $attempts; $currentAttempt++) {
|
||||
for ($currentAttempt = 1; $currentAttempt <= $attempts; ++$currentAttempt) {
|
||||
$this->beginTransaction();
|
||||
|
||||
// We'll simply execute the given callback within a try / catch block and if we
|
||||
@ -63,7 +63,7 @@ trait ManagesTransactions
|
||||
{
|
||||
$this->createTransaction();
|
||||
|
||||
$this->transactions++;
|
||||
++$this->transactions;
|
||||
|
||||
$this->fireConnectionEvent('beganTransaction');
|
||||
}
|
||||
@ -73,7 +73,7 @@ trait ManagesTransactions
|
||||
*/
|
||||
public function commit(): void
|
||||
{
|
||||
if ($this->transactions == 1) {
|
||||
if (1 == $this->transactions) {
|
||||
$this->getPdo()->commit();
|
||||
}
|
||||
|
||||
@ -85,8 +85,7 @@ trait ManagesTransactions
|
||||
/**
|
||||
* Rollback the active database transaction.
|
||||
*
|
||||
* @param int|null $toLevel
|
||||
* @return void
|
||||
* @param int|null $toLevel
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
@ -119,8 +118,6 @@ trait ManagesTransactions
|
||||
|
||||
/**
|
||||
* Get the number of active transactions.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function transactionLevel(): int
|
||||
{
|
||||
@ -130,10 +127,9 @@ trait ManagesTransactions
|
||||
/**
|
||||
* Handle an exception encountered when running a transacted statement.
|
||||
*
|
||||
* @param \Exception $e
|
||||
* @param int $currentAttempt
|
||||
* @param int $maxAttempts
|
||||
* @return void
|
||||
* @param \Exception $e
|
||||
* @param int $currentAttempt
|
||||
* @param int $maxAttempts
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
@ -144,7 +140,7 @@ trait ManagesTransactions
|
||||
// let the developer handle it in another way. We will decrement too.
|
||||
if ($this->causedByDeadlock($e) &&
|
||||
$this->transactions > 1) {
|
||||
$this->transactions--;
|
||||
--$this->transactions;
|
||||
|
||||
throw $e;
|
||||
}
|
||||
@ -164,12 +160,10 @@ trait ManagesTransactions
|
||||
|
||||
/**
|
||||
* Create a transaction within the database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function createTransaction()
|
||||
{
|
||||
if ($this->transactions == 0) {
|
||||
if (0 == $this->transactions) {
|
||||
try {
|
||||
$this->getPdo()->beginTransaction();
|
||||
} catch (Exception $e) {
|
||||
@ -182,8 +176,6 @@ trait ManagesTransactions
|
||||
|
||||
/**
|
||||
* Create a save point within the database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function createSavepoint()
|
||||
{
|
||||
@ -195,8 +187,7 @@ trait ManagesTransactions
|
||||
/**
|
||||
* Handle an exception from a transaction beginning.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
* @param \Throwable $e
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
@ -214,12 +205,11 @@ trait ManagesTransactions
|
||||
/**
|
||||
* Perform a rollback within the database.
|
||||
*
|
||||
* @param int $toLevel
|
||||
* @return void
|
||||
* @param int $toLevel
|
||||
*/
|
||||
protected function performRollBack($toLevel)
|
||||
{
|
||||
if ($toLevel == 0) {
|
||||
if (0 == $toLevel) {
|
||||
$this->getPdo()->rollBack();
|
||||
} elseif ($this->queryGrammar->supportsSavepoints()) {
|
||||
$this->getPdo()->exec(
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -164,11 +165,9 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Create a new database connection instance.
|
||||
*
|
||||
* @param \PDO|\Closure $pdo
|
||||
* @param string $database
|
||||
* @param string $tablePrefix
|
||||
* @param array $config
|
||||
* @return void
|
||||
* @param \PDO|\Closure $pdo
|
||||
* @param string $database
|
||||
* @param string $tablePrefix
|
||||
*/
|
||||
public function __construct($pdo, $database = '', $tablePrefix = '', array $config = [])
|
||||
{
|
||||
@ -194,7 +193,7 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Set the query grammar to the default implementation.
|
||||
*/
|
||||
public function useDefaultQueryGrammar():void
|
||||
public function useDefaultQueryGrammar(): void
|
||||
{
|
||||
$this->queryGrammar = $this->getDefaultQueryGrammar();
|
||||
}
|
||||
@ -202,7 +201,7 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Set the schema grammar to the default implementation.
|
||||
*/
|
||||
public function useDefaultSchemaGrammar():void
|
||||
public function useDefaultSchemaGrammar(): void
|
||||
{
|
||||
$this->schemaGrammar = $this->getDefaultSchemaGrammar();
|
||||
}
|
||||
@ -210,7 +209,7 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Set the query post processor to the default implementation.
|
||||
*/
|
||||
public function useDefaultPostProcessor():void
|
||||
public function useDefaultPostProcessor(): void
|
||||
{
|
||||
$this->postProcessor = $this->getDefaultPostProcessor();
|
||||
}
|
||||
@ -250,7 +249,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Run a select statement and return a single result.
|
||||
* @return mixed
|
||||
*/
|
||||
public function selectOne(string $query, array $bindings = [], bool $useReadPdo = true)
|
||||
{
|
||||
@ -262,7 +260,7 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Run a select statement against the database.
|
||||
*/
|
||||
public function selectFromWriteConnection(string $query, array $bindings = []):array
|
||||
public function selectFromWriteConnection(string $query, array $bindings = []): array
|
||||
{
|
||||
return $this->select($query, $bindings, false);
|
||||
}
|
||||
@ -407,7 +405,7 @@ class Connection implements ConnectionInterface
|
||||
}
|
||||
|
||||
$this->recordsHaveBeenModified(
|
||||
$change = $this->getPdo()->exec($query) !== false
|
||||
$change = false !== $this->getPdo()->exec($query)
|
||||
);
|
||||
|
||||
return $change;
|
||||
@ -461,7 +459,7 @@ class Connection implements ConnectionInterface
|
||||
if ($value instanceof DateTimeInterface) {
|
||||
$bindings[$key] = $value->format($grammar->getDateFormat());
|
||||
} elseif (is_bool($value)) {
|
||||
$bindings[$key] = (int)$value;
|
||||
$bindings[$key] = (int) $value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,10 +469,9 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Log a query in the connection's query log.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @param float|null $time
|
||||
* @return void
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @param float|null $time
|
||||
*/
|
||||
public function logQuery($query, $bindings, $time = null)
|
||||
{
|
||||
@ -488,7 +485,6 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Reconnect to the database.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
@ -503,8 +499,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Disconnect from the underlying PDO connection.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
@ -513,9 +507,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Register a database query listener with the connection.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return void
|
||||
*/
|
||||
public function listen(Closure $callback)
|
||||
{
|
||||
@ -526,9 +517,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Get a new raw query expression.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return \Hyperf\Database\Query\Expression
|
||||
*/
|
||||
public function raw($value): Expression
|
||||
{
|
||||
@ -538,12 +526,11 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Indicate if any records have been modified.
|
||||
*
|
||||
* @param bool $value
|
||||
* @return void
|
||||
* @param bool $value
|
||||
*/
|
||||
public function recordsHaveBeenModified($value = true)
|
||||
{
|
||||
if (!$this->recordsModified) {
|
||||
if (! $this->recordsModified) {
|
||||
$this->recordsModified = $value;
|
||||
}
|
||||
}
|
||||
@ -561,8 +548,8 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Get a Doctrine Schema Column instance.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
public function getDoctrineColumn($table, $column)
|
||||
@ -669,7 +656,6 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Set the reconnect instance on the connection.
|
||||
*
|
||||
* @param callable $reconnector
|
||||
* @return $this
|
||||
*/
|
||||
public function setReconnector(callable $reconnector)
|
||||
@ -692,8 +678,7 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Get an option from the configuration options.
|
||||
*
|
||||
* @param string|null $option
|
||||
* @return mixed
|
||||
* @param string|null $option
|
||||
*/
|
||||
public function getConfig($option = null)
|
||||
{
|
||||
@ -769,7 +754,6 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Set the query post processor used by the connection.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Processors\Processor $processor
|
||||
* @return $this
|
||||
*/
|
||||
public function setPostProcessor(Processor $processor)
|
||||
@ -792,7 +776,6 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Set the event dispatcher instance on the connection.
|
||||
*
|
||||
* @param \Hyperf\Contracts\Events\Dispatcher $events
|
||||
* @return $this
|
||||
*/
|
||||
public function setEventDispatcher(Dispatcher $events)
|
||||
@ -804,8 +787,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Unset the event dispatcher for this connection.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetEventDispatcher()
|
||||
{
|
||||
@ -819,7 +800,7 @@ class Connection implements ConnectionInterface
|
||||
*/
|
||||
public function pretending()
|
||||
{
|
||||
return $this->pretending === true;
|
||||
return true === $this->pretending;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -834,8 +815,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Clear the query log.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flushQueryLog()
|
||||
{
|
||||
@ -844,8 +823,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Enable the query log on the connection.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enableQueryLog()
|
||||
{
|
||||
@ -854,8 +831,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Disable the query log on the connection.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disableQueryLog()
|
||||
{
|
||||
@ -936,9 +911,7 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Register a connection resolver.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param \Closure $callback
|
||||
* @return void
|
||||
* @param string $driver
|
||||
*/
|
||||
public static function resolverFor($driver, Closure $callback)
|
||||
{
|
||||
@ -948,8 +921,7 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Get the connection resolver for the given driver.
|
||||
*
|
||||
* @param string $driver
|
||||
* @return mixed
|
||||
* @param string $driver
|
||||
*/
|
||||
public static function getResolver($driver)
|
||||
{
|
||||
@ -963,7 +935,7 @@ class Connection implements ConnectionInterface
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return new QueryGrammar;
|
||||
return new QueryGrammar();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -973,7 +945,6 @@ class Connection implements ConnectionInterface
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
@ -983,13 +954,12 @@ class Connection implements ConnectionInterface
|
||||
*/
|
||||
protected function getDefaultPostProcessor()
|
||||
{
|
||||
return new Processor;
|
||||
return new Processor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the PDO prepared statement.
|
||||
*
|
||||
* @param \PDOStatement $statement
|
||||
* @return \PDOStatement
|
||||
*/
|
||||
protected function prepared(PDOStatement $statement)
|
||||
@ -1045,10 +1015,8 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Run a SQL statement and log its execution context.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @throws QueryException
|
||||
*/
|
||||
protected function run($query, $bindings, Closure $callback)
|
||||
@ -1086,10 +1054,8 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Run a SQL statement.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @throws QueryException
|
||||
*/
|
||||
protected function runQueryCallback($query, $bindings, Closure $callback)
|
||||
@ -1118,7 +1084,7 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Get the elapsed time since a given starting point.
|
||||
*
|
||||
* @param int $start
|
||||
* @param int $start
|
||||
* @return float
|
||||
*/
|
||||
protected function getElapsedTime($start)
|
||||
@ -1129,11 +1095,9 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Handle a query exception.
|
||||
*
|
||||
* @param \Exception $e
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
* @param \Exception $e
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
@ -1154,11 +1118,8 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Handle a query exception that occurred during query execution.
|
||||
*
|
||||
* @param QueryException $e
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @throws QueryException
|
||||
*/
|
||||
protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, Closure $callback)
|
||||
@ -1174,8 +1135,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Reconnect to the database if a PDO connection is missing.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function reconnectIfMissingConnection()
|
||||
{
|
||||
@ -1187,12 +1146,12 @@ class Connection implements ConnectionInterface
|
||||
/**
|
||||
* Fire an event for this connection.
|
||||
*
|
||||
* @param string $event
|
||||
* @param string $event
|
||||
* @return array|null
|
||||
*/
|
||||
protected function fireConnectionEvent($event)
|
||||
{
|
||||
if (!isset($this->events)) {
|
||||
if (! isset($this->events)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1208,9 +1167,6 @@ class Connection implements ConnectionInterface
|
||||
|
||||
/**
|
||||
* Fire the given event if possible.
|
||||
*
|
||||
* @param mixed $event
|
||||
* @return void
|
||||
*/
|
||||
protected function event($event)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -30,8 +31,6 @@ interface ConnectionInterface
|
||||
|
||||
/**
|
||||
* Run a select statement and return a single result.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function selectOne(string $query, array $bindings = [], bool $useReadPdo = true);
|
||||
|
||||
@ -83,7 +82,6 @@ interface ConnectionInterface
|
||||
/**
|
||||
* Execute a Closure within a transaction.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function transaction(Closure $callback, int $attempts = 1);
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -29,9 +30,6 @@ class ConnectionResolver implements ConnectionResolverInterface
|
||||
|
||||
/**
|
||||
* Create a new connection resolver instance.
|
||||
*
|
||||
* @param array $connections
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $connections = [])
|
||||
{
|
||||
@ -43,7 +41,7 @@ class ConnectionResolver implements ConnectionResolverInterface
|
||||
/**
|
||||
* Get a database connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return \Hyperf\Database\ConnectionInterface
|
||||
*/
|
||||
public function connection($name = null)
|
||||
@ -58,9 +56,8 @@ class ConnectionResolver implements ConnectionResolverInterface
|
||||
/**
|
||||
* Add a connection to the resolver.
|
||||
*
|
||||
* @param string $name
|
||||
* @param \Hyperf\Database\ConnectionInterface $connection
|
||||
* @return void
|
||||
* @param string $name
|
||||
* @param \Hyperf\Database\ConnectionInterface $connection
|
||||
*/
|
||||
public function addConnection($name, ConnectionInterface $connection)
|
||||
{
|
||||
@ -70,7 +67,7 @@ class ConnectionResolver implements ConnectionResolverInterface
|
||||
/**
|
||||
* Check if a connection has been registered.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasConnection($name)
|
||||
@ -91,8 +88,7 @@ class ConnectionResolver implements ConnectionResolverInterface
|
||||
/**
|
||||
* Set the default connection name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
* @param string $name
|
||||
*/
|
||||
public function setDefaultConnection($name)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -16,7 +17,7 @@ interface ConnectionResolverInterface
|
||||
/**
|
||||
* Get a database connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return ConnectionInterface
|
||||
*/
|
||||
public function connection($name = null);
|
||||
@ -31,8 +32,7 @@ interface ConnectionResolverInterface
|
||||
/**
|
||||
* Set the default connection name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
* @param string $name
|
||||
*/
|
||||
public function setDefaultConnection($name);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -33,9 +34,6 @@ class ConnectionFactory
|
||||
|
||||
/**
|
||||
* Create a new connection factory instance.
|
||||
*
|
||||
* @param ContainerInterface $container
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
@ -45,8 +43,7 @@ class ConnectionFactory
|
||||
/**
|
||||
* Establish a PDO connection based on the configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return ConnectionInterface
|
||||
*/
|
||||
public function make(array $config, $name = null)
|
||||
@ -63,14 +60,13 @@ class ConnectionFactory
|
||||
/**
|
||||
* Create a connector instance based on the configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return ConnectorInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function createConnector(array $config)
|
||||
{
|
||||
if (!isset($config['driver'])) {
|
||||
if (! isset($config['driver'])) {
|
||||
throw new InvalidArgumentException('A driver must be specified.');
|
||||
}
|
||||
|
||||
@ -80,13 +76,13 @@ class ConnectionFactory
|
||||
|
||||
switch ($config['driver']) {
|
||||
case 'mysql':
|
||||
return new MySqlConnector;
|
||||
return new MySqlConnector();
|
||||
case 'pgsql':
|
||||
return new PostgresConnector;
|
||||
return new PostgresConnector();
|
||||
case 'sqlite':
|
||||
return new SQLiteConnector;
|
||||
return new SQLiteConnector();
|
||||
case 'sqlsrv':
|
||||
return new SqlServerConnector;
|
||||
return new SqlServerConnector();
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]");
|
||||
@ -95,7 +91,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Parse and prepare the database configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
@ -107,7 +102,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Create a single database connection instance.
|
||||
*
|
||||
* @param array $config
|
||||
* @return Connection
|
||||
*/
|
||||
protected function createSingleConnection(array $config)
|
||||
@ -126,7 +120,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Create a single database connection instance.
|
||||
*
|
||||
* @param array $config
|
||||
* @return Connection
|
||||
*/
|
||||
protected function createReadWriteConnection(array $config)
|
||||
@ -139,7 +132,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Create a new PDO instance for reading.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function createReadPdo(array $config)
|
||||
@ -150,7 +142,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Get the read configuration for a read / write connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function getReadConfig(array $config)
|
||||
@ -164,7 +155,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Get the read configuration for a read / write connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function getWriteConfig(array $config)
|
||||
@ -178,7 +168,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Get a read / write level configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
@ -192,8 +181,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Merge a configuration for a read / write connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @param array $merge
|
||||
* @return array
|
||||
*/
|
||||
protected function mergeReadWriteConfig(array $config, array $merge)
|
||||
@ -204,7 +191,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Create a new Closure that resolves to a PDO instance.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function createPdoResolver(array $config)
|
||||
@ -217,7 +203,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Create a new Closure that resolves to a PDO instance with a specific host or an array of hosts.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function createPdoResolverWithHosts(array $config)
|
||||
@ -240,7 +225,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Parse the hosts configuration item into an array.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function parseHosts(array $config)
|
||||
@ -257,7 +241,6 @@ class ConnectionFactory
|
||||
/**
|
||||
* Create a new Closure that resolves to a PDO instance where there is no configured host.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function createPdoResolverWithoutHosts(array $config)
|
||||
@ -270,11 +253,10 @@ class ConnectionFactory
|
||||
/**
|
||||
* Create a new connection instance.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param \PDO|\Closure $connection
|
||||
* @param string $database
|
||||
* @param string $prefix
|
||||
* @param array $config
|
||||
* @param string $driver
|
||||
* @param \PDO|\Closure $connection
|
||||
* @param string $database
|
||||
* @param string $prefix
|
||||
* @return \Hyperf\Database\Connection
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -38,8 +39,6 @@ class Connector
|
||||
* Create a new PDO connection.
|
||||
*
|
||||
* @param string $dsn
|
||||
* @param array $config
|
||||
* @param array $options
|
||||
* @return \PDO
|
||||
*
|
||||
* @throws \Exception
|
||||
@ -71,7 +70,6 @@ class Connector
|
||||
/**
|
||||
* Get the PDO options based on the configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(array $config)
|
||||
@ -93,9 +91,6 @@ class Connector
|
||||
|
||||
/**
|
||||
* Set the default PDO connection options.
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultOptions(array $options)
|
||||
{
|
||||
@ -108,12 +103,12 @@ class Connector
|
||||
* @param string $dsn
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
* @return \PDO
|
||||
*/
|
||||
protected function createPdoConnection($dsn, $username, $password, $options)
|
||||
{
|
||||
if (class_exists(PDOConnection::class) && !$this->isPersistentConnection($options)) {
|
||||
if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
|
||||
return new PDOConnection($dsn, $username, $password, $options);
|
||||
}
|
||||
|
||||
@ -135,11 +130,10 @@ class Connector
|
||||
/**
|
||||
* Handle an exception that occurred during connect execution.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @param string $dsn
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
* @return \PDO
|
||||
*
|
||||
* @throws \Exception
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -16,7 +17,6 @@ interface ConnectorInterface
|
||||
/**
|
||||
* Establish a database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \PDO
|
||||
*/
|
||||
public function connect(array $config);
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -18,7 +19,6 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
/**
|
||||
* Establish a database connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \PDO
|
||||
*/
|
||||
public function connect(array $config)
|
||||
@ -32,7 +32,7 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
// connection's behavior, and some might be specified by the developers.
|
||||
$connection = $this->createConnection($dsn, $config, $options);
|
||||
|
||||
if (!empty($config['database'])) {
|
||||
if (! empty($config['database'])) {
|
||||
$connection->exec("use `{$config['database']}`;");
|
||||
}
|
||||
|
||||
@ -51,13 +51,11 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
/**
|
||||
* Set the connection character set and collation.
|
||||
*
|
||||
* @param \PDO $connection
|
||||
* @param array $config
|
||||
* @return void
|
||||
* @param \PDO $connection
|
||||
*/
|
||||
protected function configureEncoding($connection, array $config)
|
||||
{
|
||||
if (!isset($config['charset'])) {
|
||||
if (! isset($config['charset'])) {
|
||||
return $connection;
|
||||
}
|
||||
|
||||
@ -69,7 +67,6 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
/**
|
||||
* Get the collation for the configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getCollation(array $config)
|
||||
@ -80,9 +77,7 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
/**
|
||||
* Set the timezone on the connection.
|
||||
*
|
||||
* @param \PDO $connection
|
||||
* @param array $config
|
||||
* @return void
|
||||
* @param \PDO $connection
|
||||
*/
|
||||
protected function configureTimezone($connection, array $config)
|
||||
{
|
||||
@ -96,7 +91,6 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
*
|
||||
* Chooses socket or host/port based on the 'unix_socket' config value.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getDsn(array $config)
|
||||
@ -109,18 +103,16 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
/**
|
||||
* Determine if the given configuration array has a UNIX socket value.
|
||||
*
|
||||
* @param array $config
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasSocket(array $config)
|
||||
{
|
||||
return isset($config['unix_socket']) && !empty($config['unix_socket']);
|
||||
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)
|
||||
@ -131,7 +123,6 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
/**
|
||||
* Get the DSN string for a host / port configuration.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getHostDsn(array $config)
|
||||
@ -147,10 +138,6 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
|
||||
/**
|
||||
* Set the modes for the connection.
|
||||
*
|
||||
* @param \PDO $connection
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
protected function setModes(PDO $connection, array $config)
|
||||
{
|
||||
@ -167,10 +154,6 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
|
||||
/**
|
||||
* Set the custom modes on the connection.
|
||||
*
|
||||
* @param \PDO $connection
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
protected function setCustomModes(PDO $connection, array $config)
|
||||
{
|
||||
@ -182,7 +165,6 @@ class MySqlConnector extends Connector implements ConnectorInterface
|
||||
/**
|
||||
* Get the query to enable strict mode.
|
||||
*
|
||||
* @param \PDO $connection
|
||||
* @return string
|
||||
*/
|
||||
protected function strictMode(PDO $connection)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -53,9 +54,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Create a new database manager instance.
|
||||
*
|
||||
* @param \Hyperf\Contracts\Foundation\Application $app
|
||||
* @param \Hyperf\Database\Connectors\ConnectionFactory $factory
|
||||
* @return void
|
||||
* @param \Hyperf\Contracts\Foundation\Application $app
|
||||
*/
|
||||
public function __construct($app, ConnectionFactory $factory)
|
||||
{
|
||||
@ -66,9 +65,8 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Dynamically pass methods to the default connection.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
@ -78,7 +76,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Get a database connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return \Hyperf\Database\Connection
|
||||
*/
|
||||
public function connection($name = null)
|
||||
@ -90,7 +88,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
// 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])) {
|
||||
if (! isset($this->connections[$name])) {
|
||||
$this->connections[$name] = $this->configure(
|
||||
$this->makeConnection($database),
|
||||
$type
|
||||
@ -103,8 +101,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Disconnect from the given database and remove from local cache.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
* @param string $name
|
||||
*/
|
||||
public function purge($name = null)
|
||||
{
|
||||
@ -118,8 +115,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Disconnect from the given database.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
* @param string $name
|
||||
*/
|
||||
public function disconnect($name = null)
|
||||
{
|
||||
@ -131,14 +127,14 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Reconnect to the given database.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return \Hyperf\Database\Connection
|
||||
*/
|
||||
public function reconnect($name = null)
|
||||
{
|
||||
$this->disconnect($name = $name ?: $this->getDefaultConnection());
|
||||
|
||||
if (!isset($this->connections[$name])) {
|
||||
if (! isset($this->connections[$name])) {
|
||||
return $this->connection($name);
|
||||
}
|
||||
|
||||
@ -158,8 +154,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Set the default connection name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
* @param string $name
|
||||
*/
|
||||
public function setDefaultConnection($name)
|
||||
{
|
||||
@ -192,9 +187,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Register an extension connection resolver.
|
||||
*
|
||||
* @param string $name
|
||||
* @param callable $resolver
|
||||
* @return void
|
||||
* @param string $name
|
||||
*/
|
||||
public function extend($name, callable $resolver)
|
||||
{
|
||||
@ -228,7 +221,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Make the database connection instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return \Hyperf\Database\Connection
|
||||
*/
|
||||
protected function makeConnection($name)
|
||||
@ -280,7 +273,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
* Prepare the database connection instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
* @return \Hyperf\Database\Connection
|
||||
*/
|
||||
protected function configure(Connection $connection, $type)
|
||||
@ -308,14 +301,14 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
* Prepare the read / write mode for database connection instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
* @return \Hyperf\Database\Connection
|
||||
*/
|
||||
protected function setPdoForType(Connection $connection, $type = null)
|
||||
{
|
||||
if ($type === 'read') {
|
||||
if ('read' === $type) {
|
||||
$connection->setPdo($connection->getReadPdo());
|
||||
} elseif ($type === 'write') {
|
||||
} elseif ('write' === $type) {
|
||||
$connection->setReadPdo($connection->getPdo());
|
||||
}
|
||||
|
||||
@ -325,7 +318,7 @@ class DatabaseManager implements ConnectionResolverInterface
|
||||
/**
|
||||
* Refresh the PDO connections on a given connection.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return \Hyperf\Database\Connection
|
||||
*/
|
||||
protected function refreshPdoConnections($name)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -19,7 +20,6 @@ trait DetectsDeadlocks
|
||||
/**
|
||||
* Determine if the given exception was caused by a deadlock.
|
||||
*
|
||||
* @param \Exception $e
|
||||
* @return bool
|
||||
*/
|
||||
protected function causedByDeadlock(Exception $e)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -19,7 +20,6 @@ trait DetectsLostConnections
|
||||
/**
|
||||
* Determine if the given exception was caused by a lost connection.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return bool
|
||||
*/
|
||||
protected function causedByLostConnection(Throwable $e)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -30,8 +31,7 @@ abstract class ConnectionEvent
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
*/
|
||||
public function __construct($connection)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -53,11 +54,10 @@ class QueryExecuted
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param array $bindings
|
||||
* @param float|null $time
|
||||
* @param ConnectionInterface $connection
|
||||
* @return void
|
||||
* @param string $sql
|
||||
* @param array $bindings
|
||||
* @param float|null $time
|
||||
* @param ConnectionInterface $connection
|
||||
*/
|
||||
public function __construct($sql, $bindings, $time, $connection)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -30,9 +31,8 @@ class StatementPrepared
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param \PDOStatement $statement
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param \PDOStatement $statement
|
||||
*/
|
||||
public function __construct($connection, $statement)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -13,5 +14,4 @@ namespace Hyperf\Database\Events;
|
||||
|
||||
class TransactionBeginning extends ConnectionEvent
|
||||
{
|
||||
//
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -13,5 +14,4 @@ namespace Hyperf\Database\Events;
|
||||
|
||||
class TransactionCommitted extends ConnectionEvent
|
||||
{
|
||||
//
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -13,5 +14,4 @@ namespace Hyperf\Database\Events;
|
||||
|
||||
class TransactionRolledBack extends ConnectionEvent
|
||||
{
|
||||
//
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -71,8 +72,8 @@ class QueryException extends PDOException
|
||||
/**
|
||||
* Format the SQL error message.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param array $bindings
|
||||
* @param string $sql
|
||||
* @param array $bindings
|
||||
* @param \Exception $previous
|
||||
* @return string
|
||||
*/
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -28,7 +29,6 @@ abstract class Grammar
|
||||
/**
|
||||
* Wrap an array of values.
|
||||
*
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function wrapArray(array $values)
|
||||
@ -44,7 +44,7 @@ abstract class Grammar
|
||||
*/
|
||||
public function wrapTable($table)
|
||||
{
|
||||
if (!$this->isExpression($table)) {
|
||||
if (! $this->isExpression($table)) {
|
||||
return $this->wrap($this->tablePrefix . $table, true);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ abstract class Grammar
|
||||
* Wrap a value in keyword identifiers.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Expression|string $value
|
||||
* @param bool $prefixAlias
|
||||
* @param bool $prefixAlias
|
||||
* @return string
|
||||
*/
|
||||
public function wrap($value, $prefixAlias = false)
|
||||
@ -67,7 +67,7 @@ abstract class Grammar
|
||||
// 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 its
|
||||
// own, and then join these both back together using the "as" connector.
|
||||
if (stripos($value, ' as ') !== false) {
|
||||
if (false !== stripos($value, ' as ')) {
|
||||
return $this->wrapAliasedValue($value, $prefixAlias);
|
||||
}
|
||||
|
||||
@ -77,7 +77,6 @@ abstract class Grammar
|
||||
/**
|
||||
* Convert an array of column names into a delimited string.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return string
|
||||
*/
|
||||
public function columnize(array $columns)
|
||||
@ -88,7 +87,6 @@ abstract class Grammar
|
||||
/**
|
||||
* Create query parameter place-holders for an array.
|
||||
*
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function parameterize(array $values)
|
||||
@ -99,7 +97,6 @@ abstract class Grammar
|
||||
/**
|
||||
* Get the appropriate query parameter place-holder for a value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
public function parameter($value)
|
||||
@ -125,7 +122,6 @@ abstract class Grammar
|
||||
/**
|
||||
* Determine if the given value is a raw expression.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpression($value)
|
||||
@ -181,7 +177,7 @@ abstract class Grammar
|
||||
* Wrap a value that has an alias.
|
||||
*
|
||||
* @param string $value
|
||||
* @param bool $prefixAlias
|
||||
* @param bool $prefixAlias
|
||||
* @return string
|
||||
*/
|
||||
protected function wrapAliasedValue($value, $prefixAlias = false)
|
||||
@ -205,13 +201,13 @@ abstract class Grammar
|
||||
/**
|
||||
* Wrap the given value segments.
|
||||
*
|
||||
* @param array $segments
|
||||
* @param array $segments
|
||||
* @return string
|
||||
*/
|
||||
protected function wrapSegments($segments)
|
||||
{
|
||||
return collect($segments)->map(function ($segment, $key) use ($segments) {
|
||||
return $key == 0 && count($segments) > 1
|
||||
return 0 == $key && count($segments) > 1
|
||||
? $this->wrapTable($segment)
|
||||
: $this->wrapValue($segment);
|
||||
})->implode('.');
|
||||
@ -225,7 +221,7 @@ abstract class Grammar
|
||||
*/
|
||||
protected function wrapValue($value)
|
||||
{
|
||||
if ($value !== '*') {
|
||||
if ('*' !== $value) {
|
||||
return '"' . str_replace('"', '""', $value) . '"';
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -97,9 +98,6 @@ class Builder
|
||||
|
||||
/**
|
||||
* Create a new Model query builder instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(QueryBuilder $query)
|
||||
{
|
||||
@ -109,13 +107,12 @@ class Builder
|
||||
/**
|
||||
* Dynamically handle calls into the query instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if ($method === 'macro') {
|
||||
if ('macro' === $method) {
|
||||
$this->localMacros[$parameters[0]] = $parameters[1];
|
||||
|
||||
return;
|
||||
@ -151,21 +148,20 @@ class Builder
|
||||
/**
|
||||
* Dynamically handle calls into the query instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
if ($method === 'macro') {
|
||||
if ('macro' === $method) {
|
||||
static::$macros[$parameters[0]] = $parameters[1];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset(static::$macros[$method])) {
|
||||
if (! isset(static::$macros[$method])) {
|
||||
static::throwBadMethodCallException($method);
|
||||
}
|
||||
|
||||
@ -178,8 +174,6 @@ class Builder
|
||||
|
||||
/**
|
||||
* Force a clone of the underlying query builder when cloning.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
@ -189,7 +183,6 @@ class Builder
|
||||
/**
|
||||
* Create and return an un-saved model instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function make(array $attributes = [])
|
||||
@ -200,7 +193,7 @@ class Builder
|
||||
/**
|
||||
* Register a new global scope.
|
||||
*
|
||||
* @param string $identifier
|
||||
* @param string $identifier
|
||||
* @param \Hyperf\Database\Model\Scope|\Closure $scope
|
||||
* @return $this
|
||||
*/
|
||||
@ -223,7 +216,7 @@ class Builder
|
||||
*/
|
||||
public function withoutGlobalScope($scope)
|
||||
{
|
||||
if (!is_string($scope)) {
|
||||
if (! is_string($scope)) {
|
||||
$scope = get_class($scope);
|
||||
}
|
||||
|
||||
@ -237,12 +230,11 @@ class Builder
|
||||
/**
|
||||
* Remove all or passed registered global scopes.
|
||||
*
|
||||
* @param array|null $scopes
|
||||
* @return $this
|
||||
*/
|
||||
public function withoutGlobalScopes(array $scopes = null)
|
||||
{
|
||||
if (!is_array($scopes)) {
|
||||
if (! is_array($scopes)) {
|
||||
$scopes = array_keys($this->scopes);
|
||||
}
|
||||
|
||||
@ -266,7 +258,6 @@ class Builder
|
||||
/**
|
||||
* Add a where clause on the primary key to the query.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return $this
|
||||
*/
|
||||
public function whereKey($id)
|
||||
@ -283,7 +274,6 @@ class Builder
|
||||
/**
|
||||
* Add a where clause on the primary key to the query.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return $this
|
||||
*/
|
||||
public function whereKeyNot($id)
|
||||
@ -301,9 +291,7 @@ class Builder
|
||||
* Add a basic where clause to the query.
|
||||
*
|
||||
* @param string|array|\Closure $column
|
||||
* @param mixed $operator
|
||||
* @param mixed $value
|
||||
* @param string $boolean
|
||||
* @param string $boolean
|
||||
* @return $this
|
||||
*/
|
||||
public function where($column, $operator = null, $value = null, $boolean = 'and')
|
||||
@ -322,9 +310,7 @@ class Builder
|
||||
/**
|
||||
* Add an "or where" clause to the query.
|
||||
*
|
||||
* @param \Closure|array|string $column
|
||||
* @param mixed $operator
|
||||
* @param mixed $value
|
||||
* @param \Closure|array|string $column
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function orWhere($column, $operator = null, $value = null)
|
||||
@ -332,7 +318,7 @@ class Builder
|
||||
[$value, $operator] = $this->query->prepareValueAndOperator(
|
||||
$value,
|
||||
$operator,
|
||||
func_num_args() === 2
|
||||
2 === func_num_args()
|
||||
);
|
||||
|
||||
return $this->where($column, $operator, $value, 'or');
|
||||
@ -375,7 +361,6 @@ class Builder
|
||||
/**
|
||||
* Create a collection of models from plain arrays.
|
||||
*
|
||||
* @param array $items
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function hydrate(array $items)
|
||||
@ -390,8 +375,8 @@ class Builder
|
||||
/**
|
||||
* Create a collection of models from a raw query.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @param string $query
|
||||
* @param array $bindings
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function fromQuery($query, $bindings = [])
|
||||
@ -404,8 +389,7 @@ class Builder
|
||||
/**
|
||||
* Find a model by its primary key.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection|static[]|static|null
|
||||
*/
|
||||
public function find($id, $columns = ['*'])
|
||||
@ -421,7 +405,7 @@ class Builder
|
||||
* Find multiple models by their primary keys.
|
||||
*
|
||||
* @param \Hyperf\Contracts\Support\Arrayable|array $ids
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function findMany($ids, $columns = ['*'])
|
||||
@ -436,8 +420,7 @@ class Builder
|
||||
/**
|
||||
* Find a model by its primary key or throw an exception.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection|static|static[]
|
||||
*
|
||||
* @throws \Hyperf\Database\Model\ModelNotFoundException
|
||||
@ -450,11 +433,11 @@ class Builder
|
||||
if (count($result) === count(array_unique($id))) {
|
||||
return $result;
|
||||
}
|
||||
} elseif (!is_null($result)) {
|
||||
} elseif (! is_null($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
throw (new ModelNotFoundException)->setModel(
|
||||
throw (new ModelNotFoundException())->setModel(
|
||||
get_class($this->model),
|
||||
$id
|
||||
);
|
||||
@ -463,13 +446,12 @@ class Builder
|
||||
/**
|
||||
* Find a model by its primary key or return fresh model instance.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|static
|
||||
*/
|
||||
public function findOrNew($id, $columns = ['*'])
|
||||
{
|
||||
if (!is_null($model = $this->find($id, $columns))) {
|
||||
if (! is_null($model = $this->find($id, $columns))) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
@ -479,13 +461,11 @@ class Builder
|
||||
/**
|
||||
* Get the first record matching the attributes or instantiate it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return \Hyperf\Database\Model\Model|static
|
||||
*/
|
||||
public function firstOrNew(array $attributes, array $values = [])
|
||||
{
|
||||
if (!is_null($instance = $this->where($attributes)->first())) {
|
||||
if (! is_null($instance = $this->where($attributes)->first())) {
|
||||
return $instance;
|
||||
}
|
||||
|
||||
@ -495,13 +475,11 @@ class Builder
|
||||
/**
|
||||
* Get the first record matching the attributes or create it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return \Hyperf\Database\Model\Model|static
|
||||
*/
|
||||
public function firstOrCreate(array $attributes, array $values = [])
|
||||
{
|
||||
if (!is_null($instance = $this->where($attributes)->first())) {
|
||||
if (! is_null($instance = $this->where($attributes)->first())) {
|
||||
return $instance;
|
||||
}
|
||||
|
||||
@ -513,8 +491,6 @@ class Builder
|
||||
/**
|
||||
* Create or update a record matching the attributes, and fill it with values.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return \Hyperf\Database\Model\Model|static
|
||||
*/
|
||||
public function updateOrCreate(array $attributes, array $values = [])
|
||||
@ -527,25 +503,24 @@ class Builder
|
||||
/**
|
||||
* Execute the query and get the first result or throw an exception.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|static
|
||||
*
|
||||
* @throws \Hyperf\Database\Model\ModelNotFoundException
|
||||
*/
|
||||
public function firstOrFail($columns = ['*'])
|
||||
{
|
||||
if (!is_null($model = $this->first($columns))) {
|
||||
if (! is_null($model = $this->first($columns))) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw (new ModelNotFoundException)->setModel(get_class($this->model));
|
||||
throw (new ModelNotFoundException())->setModel(get_class($this->model));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query and get the first result or call a callback.
|
||||
*
|
||||
* @param \Closure|array $columns
|
||||
* @param \Closure|null $callback
|
||||
* @param \Closure|array $columns
|
||||
* @return \Hyperf\Database\Model\Model|static|mixed
|
||||
*/
|
||||
public function firstOr($columns = ['*'], Closure $callback = null)
|
||||
@ -556,7 +531,7 @@ class Builder
|
||||
$columns = ['*'];
|
||||
}
|
||||
|
||||
if (!is_null($model = $this->first($columns))) {
|
||||
if (! is_null($model = $this->first($columns))) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
@ -566,8 +541,7 @@ class Builder
|
||||
/**
|
||||
* Get a single column's value from the first result of a query.
|
||||
*
|
||||
* @param string $column
|
||||
* @return mixed
|
||||
* @param string $column
|
||||
*/
|
||||
public function value($column)
|
||||
{
|
||||
@ -579,7 +553,7 @@ class Builder
|
||||
/**
|
||||
* Execute the query as a "select" statement.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Collection|static[]
|
||||
*/
|
||||
public function get($columns = ['*'])
|
||||
@ -599,7 +573,7 @@ class Builder
|
||||
/**
|
||||
* Get the hydrated models without eager loading.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model[]|static[]
|
||||
*/
|
||||
public function getModels($columns = ['*'])
|
||||
@ -612,7 +586,6 @@ class Builder
|
||||
/**
|
||||
* Eager load the relationships for the models.
|
||||
*
|
||||
* @param array $models
|
||||
* @return array
|
||||
*/
|
||||
public function eagerLoadRelations(array $models)
|
||||
@ -621,7 +594,7 @@ class Builder
|
||||
// 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) {
|
||||
if (false === strpos($name, '.')) {
|
||||
$models = $this->eagerLoadRelation($models, $name, $constraints);
|
||||
}
|
||||
}
|
||||
@ -632,7 +605,7 @@ class Builder
|
||||
/**
|
||||
* Get the relation instance for the given relation name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return \Hyperf\Database\Model\Relations\Relation
|
||||
*/
|
||||
public function getRelation($name)
|
||||
@ -675,8 +648,7 @@ class Builder
|
||||
/**
|
||||
* Chunk the results of a query by comparing numeric IDs.
|
||||
*
|
||||
* @param int $count
|
||||
* @param callable $callback
|
||||
* @param int $count
|
||||
* @param string|null $column
|
||||
* @param string|null $alias
|
||||
* @return bool
|
||||
@ -699,14 +671,14 @@ class Builder
|
||||
|
||||
$countResults = $results->count();
|
||||
|
||||
if ($countResults == 0) {
|
||||
if (0 == $countResults) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 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) === false) {
|
||||
if (false === $callback($results)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -721,8 +693,8 @@ class Builder
|
||||
/**
|
||||
* Get an array with the values of a given column.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string|null $key
|
||||
* @param string $column
|
||||
* @param string|null $key
|
||||
* @return \Hyperf\Utils\Collection
|
||||
*/
|
||||
public function pluck($column, $key = null)
|
||||
@ -732,9 +704,9 @@ class Builder
|
||||
// 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 Model models.
|
||||
if (!$this->model->hasGetMutator($column) &&
|
||||
!$this->model->hasCast($column) &&
|
||||
!in_array($column, $this->model->getDates())) {
|
||||
if (! $this->model->hasGetMutator($column) &&
|
||||
! $this->model->hasCast($column) &&
|
||||
! in_array($column, $this->model->getDates())) {
|
||||
return $results;
|
||||
}
|
||||
|
||||
@ -746,10 +718,10 @@ class Builder
|
||||
/**
|
||||
* Paginate the given query.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @return \Hyperf\Contracts\Pagination\LengthAwarePaginator
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
@ -773,10 +745,10 @@ class Builder
|
||||
/**
|
||||
* Paginate the given query into a simple paginator.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @return \Hyperf\Contracts\Pagination\Paginator
|
||||
*/
|
||||
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
|
||||
@ -799,7 +771,6 @@ class Builder
|
||||
/**
|
||||
* Save a new model and return the instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Model|$this
|
||||
*/
|
||||
public function create(array $attributes = [])
|
||||
@ -812,7 +783,6 @@ class Builder
|
||||
/**
|
||||
* Save a new model and return the instance. Allow mass-assignment.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Model|$this
|
||||
*/
|
||||
public function forceCreate(array $attributes)
|
||||
@ -825,7 +795,6 @@ class Builder
|
||||
/**
|
||||
* Update a record in the database.
|
||||
*
|
||||
* @param array $values
|
||||
* @return int
|
||||
*/
|
||||
public function update(array $values)
|
||||
@ -836,9 +805,8 @@ class Builder
|
||||
/**
|
||||
* Increment a column's value by a given amount.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @param float|int $amount
|
||||
* @param array $extra
|
||||
* @return int
|
||||
*/
|
||||
public function increment($column, $amount = 1, array $extra = [])
|
||||
@ -853,9 +821,8 @@ class Builder
|
||||
/**
|
||||
* Decrement a column's value by a given amount.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @param float|int $amount
|
||||
* @param array $extra
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($column, $amount = 1, array $extra = [])
|
||||
@ -869,8 +836,6 @@ class Builder
|
||||
|
||||
/**
|
||||
* Delete a record from the database.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
@ -885,8 +850,6 @@ class Builder
|
||||
* Run the default delete function on the builder.
|
||||
*
|
||||
* Since we do not apply scopes here, the row will actually be deleted.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function forceDelete()
|
||||
{
|
||||
@ -895,9 +858,6 @@ class Builder
|
||||
|
||||
/**
|
||||
* Register a replacement for the default delete function.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return void
|
||||
*/
|
||||
public function onDelete(Closure $callback)
|
||||
{
|
||||
@ -906,9 +866,6 @@ class Builder
|
||||
|
||||
/**
|
||||
* Call the given local model scopes.
|
||||
*
|
||||
* @param array $scopes
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopes(array $scopes)
|
||||
{
|
||||
@ -927,7 +884,7 @@ class Builder
|
||||
// messed up when adding scopes. Then we'll return back out the builder.
|
||||
$builder = $builder->callScope(
|
||||
[$this->model, 'scope' . ucfirst($scope)],
|
||||
(array)$parameters
|
||||
(array) $parameters
|
||||
);
|
||||
}
|
||||
|
||||
@ -941,14 +898,14 @@ class Builder
|
||||
*/
|
||||
public function applyScopes()
|
||||
{
|
||||
if (!$this->scopes) {
|
||||
if (! $this->scopes) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$builder = clone $this;
|
||||
|
||||
foreach ($this->scopes as $identifier => $scope) {
|
||||
if (!isset($builder->scopes[$identifier])) {
|
||||
if (! isset($builder->scopes[$identifier])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -975,7 +932,6 @@ class Builder
|
||||
/**
|
||||
* Set the relationships that should be eager loaded.
|
||||
*
|
||||
* @param mixed $relations
|
||||
* @return $this
|
||||
*/
|
||||
public function with($relations)
|
||||
@ -990,7 +946,6 @@ class Builder
|
||||
/**
|
||||
* Prevent the specified relations from being eager loaded.
|
||||
*
|
||||
* @param mixed $relations
|
||||
* @return $this
|
||||
*/
|
||||
public function without($relations)
|
||||
@ -1005,7 +960,7 @@ class Builder
|
||||
/**
|
||||
* Create a new instance of the model being queried.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Model|static
|
||||
*/
|
||||
public function newModelInstance($attributes = [])
|
||||
@ -1061,7 +1016,6 @@ class Builder
|
||||
/**
|
||||
* Set the relationships being eagerly loaded.
|
||||
*
|
||||
* @param array $eagerLoad
|
||||
* @return $this
|
||||
*/
|
||||
public function setEagerLoads(array $eagerLoad)
|
||||
@ -1110,7 +1064,7 @@ class Builder
|
||||
/**
|
||||
* Get the given macro by name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return \Closure
|
||||
*/
|
||||
public function getMacro($name)
|
||||
@ -1121,9 +1075,7 @@ class Builder
|
||||
/**
|
||||
* Eagerly load the relationship on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $name
|
||||
* @param \Closure $constraints
|
||||
* @return array
|
||||
*/
|
||||
protected function eagerLoadRelation(array $models, $name, Closure $constraints)
|
||||
@ -1183,8 +1135,6 @@ class Builder
|
||||
|
||||
/**
|
||||
* Add a generic "order by" clause if the query doesn't already have one.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function enforceOrderBy()
|
||||
{
|
||||
@ -1196,12 +1146,11 @@ class Builder
|
||||
/**
|
||||
* Add the "updated at" column to an array of values.
|
||||
*
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
protected function addUpdatedAtColumn(array $values)
|
||||
{
|
||||
if (!$this->model->usesTimestamps()) {
|
||||
if (! $this->model->usesTimestamps()) {
|
||||
return $values;
|
||||
}
|
||||
|
||||
@ -1216,9 +1165,7 @@ class Builder
|
||||
/**
|
||||
* Apply the given scope on the current builder instance.
|
||||
*
|
||||
* @param callable $scope
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @param array $parameters
|
||||
*/
|
||||
protected function callScope(callable $scope, $parameters = [])
|
||||
{
|
||||
@ -1234,7 +1181,7 @@ class Builder
|
||||
|
||||
$result = $scope(...array_values($parameters)) ?? $this;
|
||||
|
||||
if (count((array)$query->wheres) > $originalWhereCount) {
|
||||
if (count((array) $query->wheres) > $originalWhereCount) {
|
||||
$this->addNewWheresWithinGroup($query, $originalWhereCount);
|
||||
}
|
||||
|
||||
@ -1244,9 +1191,7 @@ class Builder
|
||||
/**
|
||||
* Nest where conditions by slicing them at the given where count.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param int $originalWhereCount
|
||||
* @return void
|
||||
* @param int $originalWhereCount
|
||||
*/
|
||||
protected function addNewWheresWithinGroup(QueryBuilder $query, $originalWhereCount)
|
||||
{
|
||||
@ -1271,9 +1216,7 @@ class Builder
|
||||
/**
|
||||
* Slice where conditions at the given offset and add them to the query as a nested condition.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $whereSlice
|
||||
* @return void
|
||||
* @param array $whereSlice
|
||||
*/
|
||||
protected function groupWhereSliceForScope(QueryBuilder $query, $whereSlice)
|
||||
{
|
||||
@ -1295,7 +1238,7 @@ class Builder
|
||||
/**
|
||||
* Create a where array with nested where conditions.
|
||||
*
|
||||
* @param array $whereSlice
|
||||
* @param array $whereSlice
|
||||
* @param string $boolean
|
||||
* @return array
|
||||
*/
|
||||
@ -1311,7 +1254,6 @@ class Builder
|
||||
/**
|
||||
* Parse a list of relations into individuals.
|
||||
*
|
||||
* @param array $relations
|
||||
* @return array
|
||||
*/
|
||||
protected function parseWithRelations(array $relations)
|
||||
@ -1328,7 +1270,6 @@ class Builder
|
||||
[$name, $constraints] = Str::contains($name, ':')
|
||||
? $this->createSelectWithConstraint($name)
|
||||
: [$name, function () {
|
||||
//
|
||||
}];
|
||||
}
|
||||
|
||||
@ -1360,7 +1301,7 @@ class Builder
|
||||
* Parse the nested relationships in a relation.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $results
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
protected function addNestedWiths($name, $results)
|
||||
@ -1373,9 +1314,8 @@ class Builder
|
||||
foreach (explode('.', $name) as $segment) {
|
||||
$progress[] = $segment;
|
||||
|
||||
if (!isset($results[$last = implode('.', $progress)])) {
|
||||
if (! isset($results[$last = implode('.', $progress)])) {
|
||||
$results[$last] = function () {
|
||||
//
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -23,8 +24,6 @@ class Collection extends BaseCollection
|
||||
/**
|
||||
* Find a model in the collection by key.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $default
|
||||
* @return \Hyperf\Database\Model\Model|static
|
||||
*/
|
||||
public function find($key, $default = null)
|
||||
@ -39,7 +38,7 @@ class Collection extends BaseCollection
|
||||
|
||||
if (is_array($key)) {
|
||||
if ($this->isEmpty()) {
|
||||
return new static;
|
||||
return new static();
|
||||
}
|
||||
|
||||
return $this->whereIn($this->first()->getKeyName(), $key);
|
||||
@ -142,7 +141,7 @@ class Collection extends BaseCollection
|
||||
* Load a set of relationships onto the mixed relationship collection.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param array $relations
|
||||
* @param array $relations
|
||||
* @return $this
|
||||
*/
|
||||
public function loadMorph($relation, $relations)
|
||||
@ -166,7 +165,6 @@ class Collection extends BaseCollection
|
||||
/**
|
||||
* Add an item to the collection.
|
||||
*
|
||||
* @param mixed $item
|
||||
* @return $this
|
||||
*/
|
||||
public function add($item)
|
||||
@ -178,11 +176,6 @@ class Collection extends BaseCollection
|
||||
|
||||
/**
|
||||
* Determine if a key exists in the collection.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $operator
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function contains($key, $operator = null, $value = null): bool
|
||||
{
|
||||
@ -232,15 +225,13 @@ class Collection extends BaseCollection
|
||||
|
||||
/**
|
||||
* Run a map over each of the items.
|
||||
*
|
||||
* @param callable $callback
|
||||
*/
|
||||
public function map(callable $callback): BaseCollection
|
||||
{
|
||||
$result = parent::map($callback);
|
||||
|
||||
return $result->contains(function ($item) {
|
||||
return !$item instanceof Model;
|
||||
return ! $item instanceof Model;
|
||||
}) ? $result->toBase() : $result;
|
||||
}
|
||||
|
||||
@ -253,7 +244,7 @@ class Collection extends BaseCollection
|
||||
public function fresh($with = [])
|
||||
{
|
||||
if ($this->isEmpty()) {
|
||||
return new static;
|
||||
return new static();
|
||||
}
|
||||
|
||||
$model = $this->first();
|
||||
@ -278,12 +269,12 @@ class Collection extends BaseCollection
|
||||
*/
|
||||
public function diff($items): BaseCollection
|
||||
{
|
||||
$diff = new static;
|
||||
$diff = new static();
|
||||
|
||||
$dictionary = $this->getDictionary($items);
|
||||
|
||||
foreach ($this->items as $item) {
|
||||
if (!isset($dictionary[$item->getKey()])) {
|
||||
if (! isset($dictionary[$item->getKey()])) {
|
||||
$diff->add($item);
|
||||
}
|
||||
}
|
||||
@ -299,7 +290,7 @@ class Collection extends BaseCollection
|
||||
*/
|
||||
public function intersect($items): BaseCollection
|
||||
{
|
||||
$intersect = new static;
|
||||
$intersect = new static();
|
||||
|
||||
$dictionary = $this->getDictionary($items);
|
||||
|
||||
@ -315,12 +306,11 @@ class Collection extends BaseCollection
|
||||
/**
|
||||
* Return only unique items from the collection.
|
||||
*
|
||||
* @param string|callable|null $key
|
||||
* @param bool $strict
|
||||
* @param string|callable|null $key
|
||||
*/
|
||||
public function unique($key = null, bool $strict = false): BaseCollection
|
||||
{
|
||||
if (!is_null($key)) {
|
||||
if (! is_null($key)) {
|
||||
return parent::unique($key, $strict);
|
||||
}
|
||||
|
||||
@ -330,7 +320,6 @@ class Collection extends BaseCollection
|
||||
/**
|
||||
* Returns only the models from the collection with the specified keys.
|
||||
*
|
||||
* @param mixed $keys
|
||||
* @return static
|
||||
*/
|
||||
public function only($keys): BaseCollection
|
||||
@ -347,7 +336,6 @@ class Collection extends BaseCollection
|
||||
/**
|
||||
* Returns all models in the collection except the models with specified keys.
|
||||
*
|
||||
* @param mixed $keys
|
||||
* @return static
|
||||
*/
|
||||
public function except($keys): BaseCollection
|
||||
@ -405,8 +393,7 @@ class Collection extends BaseCollection
|
||||
/**
|
||||
* Get an array with the values of a given key.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string|null $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function pluck($value, ?string $key = null): BaseCollection
|
||||
{
|
||||
@ -415,7 +402,6 @@ class Collection extends BaseCollection
|
||||
|
||||
/**
|
||||
* Get the keys of the collection items.
|
||||
*
|
||||
*/
|
||||
public function keys(): BaseCollection
|
||||
{
|
||||
@ -425,7 +411,7 @@ class Collection extends BaseCollection
|
||||
/**
|
||||
* Zip the collection together with one or more arrays.
|
||||
*
|
||||
* @param mixed ...$items
|
||||
* @param mixed ...$items
|
||||
*/
|
||||
public function zip($items): BaseCollection
|
||||
{
|
||||
@ -434,7 +420,6 @@ class Collection extends BaseCollection
|
||||
|
||||
/**
|
||||
* Collapse the collection of items into a single array.
|
||||
*
|
||||
*/
|
||||
public function collapse(): BaseCollection
|
||||
{
|
||||
@ -451,7 +436,6 @@ class Collection extends BaseCollection
|
||||
|
||||
/**
|
||||
* Flip the items in the collection.
|
||||
*
|
||||
*/
|
||||
public function flip(): BaseCollection
|
||||
{
|
||||
@ -543,9 +527,7 @@ class Collection extends BaseCollection
|
||||
/**
|
||||
* Load a relationship path if it is not already eager loaded.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Collection $models
|
||||
* @param array $path
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Collection $models
|
||||
*/
|
||||
protected function loadMissingRelation(Collection $models, array $path)
|
||||
{
|
||||
@ -558,7 +540,7 @@ class Collection extends BaseCollection
|
||||
}
|
||||
|
||||
$models->filter(function ($model) use ($name) {
|
||||
return !is_null($model) && !$model->relationLoaded($name);
|
||||
return ! is_null($model) && ! $model->relationLoaded($name);
|
||||
})->load($relation);
|
||||
|
||||
if (empty($path)) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -49,7 +50,6 @@ trait GuardsAttributes
|
||||
/**
|
||||
* Set the fillable attributes for the model.
|
||||
*
|
||||
* @param array $fillable
|
||||
* @return $this
|
||||
*/
|
||||
public function fillable(array $fillable)
|
||||
@ -72,7 +72,6 @@ trait GuardsAttributes
|
||||
/**
|
||||
* Set the guarded attributes for the model.
|
||||
*
|
||||
* @param array $guarded
|
||||
* @return $this
|
||||
*/
|
||||
public function guard(array $guarded)
|
||||
@ -85,8 +84,7 @@ trait GuardsAttributes
|
||||
/**
|
||||
* Disable all mass assignable restrictions.
|
||||
*
|
||||
* @param bool $state
|
||||
* @return void
|
||||
* @param bool $state
|
||||
*/
|
||||
public static function unguard($state = true)
|
||||
{
|
||||
@ -95,8 +93,6 @@ trait GuardsAttributes
|
||||
|
||||
/**
|
||||
* Enable the mass assignment restrictions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function reguard()
|
||||
{
|
||||
@ -115,9 +111,6 @@ trait GuardsAttributes
|
||||
|
||||
/**
|
||||
* Run the given callable while being unguarded.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public static function unguarded(callable $callback)
|
||||
{
|
||||
@ -137,7 +130,7 @@ trait GuardsAttributes
|
||||
/**
|
||||
* Determine if the given attribute may be mass assigned.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function isFillable($key)
|
||||
@ -167,7 +160,7 @@ trait GuardsAttributes
|
||||
/**
|
||||
* Determine if the given key is guarded.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function isGuarded($key)
|
||||
@ -182,13 +175,12 @@ trait GuardsAttributes
|
||||
*/
|
||||
public function totallyGuarded()
|
||||
{
|
||||
return count($this->getFillable()) === 0 && $this->getGuarded() == ['*'];
|
||||
return 0 === count($this->getFillable()) && $this->getGuarded() == ['*'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fillable attributes of a given array.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return array
|
||||
*/
|
||||
protected function fillableFromArray(array $attributes)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -171,8 +172,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Get an attribute from the model.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
public function getAttribute($key)
|
||||
{
|
||||
@ -201,8 +201,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Get a plain attribute (not a relationship).
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
public function getAttributeValue($key)
|
||||
{
|
||||
@ -236,8 +235,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Get a relationship.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
public function getRelationValue($key)
|
||||
{
|
||||
@ -259,20 +257,18 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine if a get mutator exists for an attribute.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function hasGetMutator($key)
|
||||
{
|
||||
return method_exists($this, 'get'.Str::studly($key).'Attribute');
|
||||
return method_exists($this, 'get' . Str::studly($key) . 'Attribute');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a given attribute on the model.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
public function setAttribute($key, $value)
|
||||
{
|
||||
@ -309,19 +305,18 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine if a set mutator exists for an attribute.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSetMutator($key)
|
||||
{
|
||||
return method_exists($this, 'set'.Str::studly($key).'Attribute');
|
||||
return method_exists($this, 'set' . Str::studly($key) . 'Attribute');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a given JSON attribute on the model.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param string $key
|
||||
* @return $this
|
||||
*/
|
||||
public function fillJsonAttribute($key, $value)
|
||||
@ -340,9 +335,8 @@ trait HasAttributes
|
||||
/**
|
||||
* Decode the given JSON back into an array or object.
|
||||
*
|
||||
* @param string $value
|
||||
* @param bool $asObject
|
||||
* @return mixed
|
||||
* @param string $value
|
||||
* @param bool $asObject
|
||||
*/
|
||||
public function fromJson($value, $asObject = false)
|
||||
{
|
||||
@ -351,9 +345,6 @@ trait HasAttributes
|
||||
|
||||
/**
|
||||
* Decode the given float.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function fromFloat($value)
|
||||
{
|
||||
@ -372,7 +363,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Convert a DateTime to a storable string.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string|null
|
||||
*/
|
||||
public function fromDateTime($value)
|
||||
@ -409,7 +399,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Set the date format used by the model.
|
||||
*
|
||||
* @param string $format
|
||||
* @param string $format
|
||||
* @return $this
|
||||
*/
|
||||
public function setDateFormat($format)
|
||||
@ -422,8 +412,8 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine whether an attribute should be cast to a native type.
|
||||
*
|
||||
* @param string $key
|
||||
* @param array|string|null $types
|
||||
* @param string $key
|
||||
* @param array|string|null $types
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCast($key, $types = null)
|
||||
@ -462,7 +452,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Set the array of model attributes. No checking is done.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param bool $sync
|
||||
* @return $this
|
||||
*/
|
||||
@ -480,8 +469,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Get the model's original attribute values.
|
||||
*
|
||||
* @param string|null $key
|
||||
* @param mixed $default
|
||||
* @param string|null $key
|
||||
* @return mixed|array
|
||||
*/
|
||||
public function getOriginal($key = null, $default = null)
|
||||
@ -492,7 +480,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Get a subset of the model's attributes.
|
||||
*
|
||||
* @param array|mixed $attributes
|
||||
* @param array|mixed $attributes
|
||||
* @return array
|
||||
*/
|
||||
public function only($attributes)
|
||||
@ -521,7 +509,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Sync a single original attribute with its current value.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string $attribute
|
||||
* @return $this
|
||||
*/
|
||||
public function syncOriginalAttribute($attribute)
|
||||
@ -532,7 +520,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Sync multiple original attribute with their current values.
|
||||
*
|
||||
* @param array|string $attributes
|
||||
* @param array|string $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function syncOriginalAttributes($attributes)
|
||||
@ -561,7 +549,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine if the model or given attribute(s) have been modified.
|
||||
*
|
||||
* @param array|string|null $attributes
|
||||
* @param array|string|null $attributes
|
||||
* @return bool
|
||||
*/
|
||||
public function isDirty($attributes = null)
|
||||
@ -575,7 +563,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine if the model or given attribute(s) have remained the same.
|
||||
*
|
||||
* @param array|string|null $attributes
|
||||
* @param array|string|null $attributes
|
||||
* @return bool
|
||||
*/
|
||||
public function isClean($attributes = null)
|
||||
@ -586,7 +574,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine if the model or given attribute(s) have been modified.
|
||||
*
|
||||
* @param array|string|null $attributes
|
||||
* @param array|string|null $attributes
|
||||
* @return bool
|
||||
*/
|
||||
public function wasChanged($attributes = null)
|
||||
@ -629,7 +617,6 @@ trait HasAttributes
|
||||
* Determine if the new and old values for a given key are equivalent.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $current
|
||||
* @return bool
|
||||
*/
|
||||
public function originalIsEquivalent($key, $current)
|
||||
@ -653,13 +640,13 @@ trait HasAttributes
|
||||
}
|
||||
|
||||
return is_numeric($current) && is_numeric($original)
|
||||
&& strcmp((string) $current, (string) $original) === 0;
|
||||
&& 0 === strcmp((string) $current, (string) $original);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append attributes to query when building a query.
|
||||
*
|
||||
* @param array|string $attributes
|
||||
* @param array|string $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function append($attributes)
|
||||
@ -674,7 +661,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Set the accessors to append to model arrays.
|
||||
*
|
||||
* @param array $appends
|
||||
* @return $this
|
||||
*/
|
||||
public function setAppends(array $appends)
|
||||
@ -703,8 +689,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Extract and cache all the mutated attributes of a class.
|
||||
*
|
||||
* @param string $class
|
||||
* @return void
|
||||
* @param string $class
|
||||
*/
|
||||
public static function cacheMutatedAttributes($class)
|
||||
{
|
||||
@ -716,7 +701,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Add the date attributes to the attributes array.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return array
|
||||
*/
|
||||
protected function addDateAttributesToArray(array $attributes)
|
||||
@ -737,8 +721,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Add the mutated attributes to the attributes array.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $mutatedAttributes
|
||||
* @return array
|
||||
*/
|
||||
protected function addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)
|
||||
@ -766,8 +748,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Add the casted attributes to the attributes array.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $mutatedAttributes
|
||||
* @return array
|
||||
*/
|
||||
protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes)
|
||||
@ -789,7 +769,7 @@ trait HasAttributes
|
||||
// a string. This allows the developers to customize how dates are serialized
|
||||
// into an array without affecting how they are persisted into the storage.
|
||||
if ($attributes[$key] &&
|
||||
($value === 'date' || $value === 'datetime')) {
|
||||
('date' === $value || 'datetime' === $value)) {
|
||||
$attributes[$key] = $this->serializeDate($attributes[$key]);
|
||||
}
|
||||
|
||||
@ -840,7 +820,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Get an attribute array of all arrayable values.
|
||||
*
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
protected function getArrayableItems(array $values)
|
||||
@ -859,8 +838,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Get an attribute from the $attributes array.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
protected function getAttributeFromArray($key)
|
||||
{
|
||||
@ -872,8 +850,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Get a relationship value from a method.
|
||||
*
|
||||
* @param string $method
|
||||
* @return mixed
|
||||
* @param string $method
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
@ -897,21 +874,17 @@ trait HasAttributes
|
||||
/**
|
||||
* Get the value of an attribute using its mutator.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
protected function mutateAttribute($key, $value)
|
||||
{
|
||||
return $this->{'get'.Str::studly($key).'Attribute'}($value);
|
||||
return $this->{'get' . Str::studly($key) . 'Attribute'}($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of an attribute using its mutator for array conversion.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
protected function mutateAttributeForArray($key, $value)
|
||||
{
|
||||
@ -923,9 +896,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Cast an attribute to a native PHP type.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
protected function castAttribute($key, $value)
|
||||
{
|
||||
@ -970,7 +941,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Get the type of cast for a model attribute.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function getCastType($key)
|
||||
@ -989,42 +960,40 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine if the cast type is a custom date time cast.
|
||||
*
|
||||
* @param string $cast
|
||||
* @param string $cast
|
||||
* @return bool
|
||||
*/
|
||||
protected function isCustomDateTimeCast($cast)
|
||||
{
|
||||
return strncmp($cast, 'date:', 5) === 0 ||
|
||||
strncmp($cast, 'datetime:', 9) === 0;
|
||||
return 0 === strncmp($cast, 'date:', 5) ||
|
||||
0 === strncmp($cast, 'datetime:', 9);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the cast type is a decimal cast.
|
||||
*
|
||||
* @param string $cast
|
||||
* @param string $cast
|
||||
* @return bool
|
||||
*/
|
||||
protected function isDecimalCast($cast)
|
||||
{
|
||||
return strncmp($cast, 'decimal:', 8) === 0;
|
||||
return 0 === strncmp($cast, 'decimal:', 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of an attribute using its mutator.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
protected function setMutatedAttributeValue($key, $value)
|
||||
{
|
||||
return $this->{'set'.Str::studly($key).'Attribute'}($value);
|
||||
return $this->{'set' . Str::studly($key) . 'Attribute'}($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given attribute is a date or date castable.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
protected function isDateAttribute($key)
|
||||
@ -1036,9 +1005,8 @@ trait HasAttributes
|
||||
/**
|
||||
* Get an array attribute with the given key and value set.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param string $path
|
||||
* @param string $key
|
||||
* @return $this
|
||||
*/
|
||||
protected function getArrayAttributeWithValue($path, $key, $value)
|
||||
@ -1051,7 +1019,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Get an array attribute or return an empty array if it is not set.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
protected function getArrayAttributeByKey($key)
|
||||
@ -1063,15 +1031,14 @@ trait HasAttributes
|
||||
/**
|
||||
* Cast the given attribute to JSON.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function castAttributeAsJson($key, $value)
|
||||
{
|
||||
$value = $this->asJson($value);
|
||||
|
||||
if ($value === false) {
|
||||
if (false === $value) {
|
||||
throw JsonEncodingException::forAttribute(
|
||||
$this,
|
||||
$key,
|
||||
@ -1085,7 +1052,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Encode the given value as JSON.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
protected function asJson($value)
|
||||
@ -1097,7 +1063,7 @@ trait HasAttributes
|
||||
* Return a decimal as string.
|
||||
*
|
||||
* @param float $value
|
||||
* @param int $decimals
|
||||
* @param int $decimals
|
||||
* @return string
|
||||
*/
|
||||
protected function asDecimal($value, $decimals)
|
||||
@ -1108,7 +1074,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Return a timestamp as DateTime object with time set to 00:00:00.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return \Hyperf\Utils\Carbon
|
||||
*/
|
||||
protected function asDate($value)
|
||||
@ -1119,7 +1084,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Return a timestamp as DateTime object.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return \Hyperf\Utils\Carbon
|
||||
*/
|
||||
protected function asDateTime($value)
|
||||
@ -1167,7 +1131,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine if the given value is a standard date format.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function isStandardDateFormat($value)
|
||||
@ -1178,7 +1142,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Return a timestamp as unix timestamp.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
protected function asTimestamp($value)
|
||||
@ -1189,7 +1152,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Prepare a date for array / JSON serialization.
|
||||
*
|
||||
* @param \DateTimeInterface $date
|
||||
* @return string
|
||||
*/
|
||||
protected function serializeDate(DateTimeInterface $date)
|
||||
@ -1200,7 +1162,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine whether a value is Date / DateTime castable for inbound manipulation.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
protected function isDateCastable($key)
|
||||
@ -1211,7 +1173,7 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine whether a value is JSON castable for inbound manipulation.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
protected function isJsonCastable($key)
|
||||
@ -1222,8 +1184,8 @@ trait HasAttributes
|
||||
/**
|
||||
* Determine if the given attributes were changed.
|
||||
*
|
||||
* @param array $changes
|
||||
* @param array|string|null $attributes
|
||||
* @param array $changes
|
||||
* @param array|string|null $attributes
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasChanges($changes, $attributes = null)
|
||||
@ -1250,7 +1212,6 @@ trait HasAttributes
|
||||
/**
|
||||
* Get all of the attribute mutator methods.
|
||||
*
|
||||
* @param mixed $class
|
||||
* @return array
|
||||
*/
|
||||
protected static function getMutatorMethods($class)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -43,15 +44,11 @@ trait HasEvents
|
||||
|
||||
/**
|
||||
* Fire the given event for the model.
|
||||
*
|
||||
* @param string $event
|
||||
* @param bool $halt
|
||||
* @return mixed
|
||||
*/
|
||||
protected function fireModelEvent(string $event)
|
||||
{
|
||||
$dispatcher = $this->getEventDispatcher();
|
||||
if (!$dispatcher instanceof EventDispatcherInterface) {
|
||||
if (! $dispatcher instanceof EventDispatcherInterface) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -59,45 +56,42 @@ trait HasEvents
|
||||
$this->fireCustomModelEvent($event, 'dispatch')
|
||||
);
|
||||
|
||||
if ($result === false) {
|
||||
if (false === $result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$eventName = 'Hyperf\\Database\\Model\\Events\\' . Str::studly($event);
|
||||
return !empty($result) ? $result : $dispatcher->dispatch(new $eventName($this, $event));
|
||||
return ! empty($result) ? $result : $dispatcher->dispatch(new $eventName($this, $event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a custom model event for the given event.
|
||||
*
|
||||
* @param string $event
|
||||
* @param string $method
|
||||
* @param string $event
|
||||
* @param string $method
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function fireCustomModelEvent($event, $method)
|
||||
{
|
||||
if (!isset($this->dispatchesEvents[$event])) {
|
||||
if (! isset($this->dispatchesEvents[$event])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->getEventDispatcher()->$method(new $this->dispatchesEvents[$event]($this));
|
||||
|
||||
if (!is_null($result)) {
|
||||
if (! is_null($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the model event results.
|
||||
*
|
||||
* @param mixed $result
|
||||
* @return mixed
|
||||
*/
|
||||
protected function filterModelEventResults($result)
|
||||
{
|
||||
if (is_array($result)) {
|
||||
$result = array_filter($result, function ($response) {
|
||||
return !is_null($response);
|
||||
return ! is_null($response);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -22,15 +23,13 @@ trait HasGlobalScopes
|
||||
/**
|
||||
* Register a new global scope on the model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Scope|\Closure|string $scope
|
||||
* @param \Closure|null $implementation
|
||||
* @return mixed
|
||||
* @param \Hyperf\Database\Model\Scope|\Closure|string $scope
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function addGlobalScope($scope, Closure $implementation = null)
|
||||
{
|
||||
if (is_string($scope) && !is_null($implementation)) {
|
||||
if (is_string($scope) && ! is_null($implementation)) {
|
||||
return GlobalScope::$container[static::class][$scope] = $implementation;
|
||||
} elseif ($scope instanceof Closure) {
|
||||
return GlobalScope::$container[static::class][spl_object_hash($scope)] = $scope;
|
||||
@ -49,13 +48,13 @@ trait HasGlobalScopes
|
||||
*/
|
||||
public static function hasGlobalScope($scope)
|
||||
{
|
||||
return !is_null(static::getGlobalScope($scope));
|
||||
return ! is_null(static::getGlobalScope($scope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a global scope registered with the model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Scope|string $scope
|
||||
* @param \Hyperf\Database\Model\Scope|string $scope
|
||||
* @return \Hyperf\Database\Model\Scope|\Closure|null
|
||||
*/
|
||||
public static function getGlobalScope($scope)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -56,9 +57,9 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a one-to-one relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @param string $related
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @return \Hyperf\Database\Model\Relations\HasOne
|
||||
*/
|
||||
public function hasOne($related, $foreignKey = null, $localKey = null)
|
||||
@ -69,23 +70,23 @@ trait HasRelationships
|
||||
|
||||
$localKey = $localKey ?: $this->getKeyName();
|
||||
|
||||
return $this->newHasOne($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey);
|
||||
return $this->newHasOne($instance->newQuery(), $this, $instance->getTable() . '.' . $foreignKey, $localKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a has-one-through relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $through
|
||||
* @param string|null $firstKey
|
||||
* @param string|null $secondKey
|
||||
* @param string|null $localKey
|
||||
* @param string|null $secondLocalKey
|
||||
* @param string $related
|
||||
* @param string $through
|
||||
* @param string|null $firstKey
|
||||
* @param string|null $secondKey
|
||||
* @param string|null $localKey
|
||||
* @param string|null $secondLocalKey
|
||||
* @return \Hyperf\Database\Model\Relations\HasOneThrough
|
||||
*/
|
||||
public function hasOneThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null, $secondLocalKey = null)
|
||||
{
|
||||
$through = new $through;
|
||||
$through = new $through();
|
||||
|
||||
$firstKey = $firstKey ?: $this->getForeignKey();
|
||||
|
||||
@ -105,11 +106,11 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a polymorphic one-to-one relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @param string $related
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @return \Hyperf\Database\Model\Relations\MorphOne
|
||||
*/
|
||||
public function morphOne($related, $name, $type = null, $id = null, $localKey = null)
|
||||
@ -122,16 +123,16 @@ trait HasRelationships
|
||||
|
||||
$localKey = $localKey ?: $this->getKeyName();
|
||||
|
||||
return $this->newMorphOne($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey);
|
||||
return $this->newMorphOne($instance->newQuery(), $this, $table . '.' . $type, $table . '.' . $id, $localKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define an inverse one-to-one or many relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $relation
|
||||
* @param string $related
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $relation
|
||||
* @return \Hyperf\Database\Model\Relations\BelongsTo
|
||||
*/
|
||||
public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null)
|
||||
@ -149,7 +150,7 @@ trait HasRelationships
|
||||
// foreign key name by using the name of the relationship function, which
|
||||
// when combined with an "_id" should conventionally match the columns.
|
||||
if (is_null($foreignKey)) {
|
||||
$foreignKey = Str::snake($relation).'_'.$instance->getKeyName();
|
||||
$foreignKey = Str::snake($relation) . '_' . $instance->getKeyName();
|
||||
}
|
||||
|
||||
// Once we have the foreign key names, we'll just create a new Model query
|
||||
@ -169,10 +170,10 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a polymorphic, inverse one-to-one or many relationship.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $ownerKey
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $ownerKey
|
||||
* @return \Hyperf\Database\Model\Relations\MorphTo
|
||||
*/
|
||||
public function morphTo($name = null, $type = null, $id = null, $ownerKey = null)
|
||||
@ -199,7 +200,7 @@ trait HasRelationships
|
||||
/**
|
||||
* Retrieve the actual class name for a given morph class.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $class
|
||||
* @return string
|
||||
*/
|
||||
public static function getActualClassNameForMorph($class)
|
||||
@ -210,9 +211,9 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a one-to-many relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @param string $related
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @return \Hyperf\Database\Model\Relations\HasMany
|
||||
*/
|
||||
public function hasMany($related, $foreignKey = null, $localKey = null)
|
||||
@ -226,7 +227,7 @@ trait HasRelationships
|
||||
return $this->newHasMany(
|
||||
$instance->newQuery(),
|
||||
$this,
|
||||
$instance->getTable().'.'.$foreignKey,
|
||||
$instance->getTable() . '.' . $foreignKey,
|
||||
$localKey
|
||||
);
|
||||
}
|
||||
@ -234,17 +235,17 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a has-many-through relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $through
|
||||
* @param string|null $firstKey
|
||||
* @param string|null $secondKey
|
||||
* @param string|null $localKey
|
||||
* @param string|null $secondLocalKey
|
||||
* @param string $related
|
||||
* @param string $through
|
||||
* @param string|null $firstKey
|
||||
* @param string|null $secondKey
|
||||
* @param string|null $localKey
|
||||
* @param string|null $secondLocalKey
|
||||
* @return \Hyperf\Database\Model\Relations\HasManyThrough
|
||||
*/
|
||||
public function hasManyThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null, $secondLocalKey = null)
|
||||
{
|
||||
$through = new $through;
|
||||
$through = new $through();
|
||||
|
||||
$firstKey = $firstKey ?: $this->getForeignKey();
|
||||
|
||||
@ -264,11 +265,11 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a polymorphic one-to-many relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @param string $related
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @return \Hyperf\Database\Model\Relations\MorphMany
|
||||
*/
|
||||
public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
|
||||
@ -284,19 +285,19 @@ trait HasRelationships
|
||||
|
||||
$localKey = $localKey ?: $this->getKeyName();
|
||||
|
||||
return $this->newMorphMany($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey);
|
||||
return $this->newMorphMany($instance->newQuery(), $this, $table . '.' . $type, $table . '.' . $id, $localKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a many-to-many relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relation
|
||||
* @param string $related
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relation
|
||||
* @return \Hyperf\Database\Model\Relations\BelongsToMany
|
||||
*/
|
||||
public function belongsToMany(
|
||||
@ -346,14 +347,14 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a polymorphic many-to-many relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param bool $inverse
|
||||
* @param string $related
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param bool $inverse
|
||||
* @return \Hyperf\Database\Model\Relations\MorphToMany
|
||||
*/
|
||||
public function morphToMany(
|
||||
@ -373,7 +374,7 @@ trait HasRelationships
|
||||
// instances, as well as the relationship instances we need for these.
|
||||
$instance = $this->newRelatedInstance($related);
|
||||
|
||||
$foreignPivotKey = $foreignPivotKey ?: $name.'_id';
|
||||
$foreignPivotKey = $foreignPivotKey ?: $name . '_id';
|
||||
|
||||
$relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey();
|
||||
|
||||
@ -385,7 +386,7 @@ trait HasRelationships
|
||||
|
||||
$lastWord = array_pop($words);
|
||||
|
||||
$table = implode('', $words).Str::plural($lastWord);
|
||||
$table = implode('', $words) . Str::plural($lastWord);
|
||||
}
|
||||
|
||||
return $this->newMorphToMany(
|
||||
@ -405,13 +406,13 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a polymorphic, inverse many-to-many relationship.
|
||||
*
|
||||
* @param string $related
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $related
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @return \Hyperf\Database\Model\Relations\MorphToMany
|
||||
*/
|
||||
public function morphedByMany(
|
||||
@ -428,7 +429,7 @@ trait HasRelationships
|
||||
// For the inverse of the polymorphic many-to-many relations, we will change
|
||||
// the way we determine the foreign and other keys, as it is the opposite
|
||||
// of the morph-to-many method since we're figuring out these inverses.
|
||||
$relatedPivotKey = $relatedPivotKey ?: $name.'_id';
|
||||
$relatedPivotKey = $relatedPivotKey ?: $name . '_id';
|
||||
|
||||
return $this->morphToMany(
|
||||
$related,
|
||||
@ -445,8 +446,8 @@ trait HasRelationships
|
||||
/**
|
||||
* Get the joining table name for a many-to-many relation.
|
||||
*
|
||||
* @param string $related
|
||||
* @param \Hyperf\Database\Model\Model|null $instance
|
||||
* @param string $related
|
||||
* @param \Hyperf\Database\Model\Model|null $instance
|
||||
* @return string
|
||||
*/
|
||||
public function joiningTable($related, $instance = null)
|
||||
@ -481,7 +482,7 @@ trait HasRelationships
|
||||
/**
|
||||
* Determine if the model touches a given relation.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return bool
|
||||
*/
|
||||
public function touches($relation)
|
||||
@ -491,8 +492,6 @@ trait HasRelationships
|
||||
|
||||
/**
|
||||
* Touch the owning relations of the model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function touchOwners()
|
||||
{
|
||||
@ -540,8 +539,7 @@ trait HasRelationships
|
||||
/**
|
||||
* Get a specified relationship.
|
||||
*
|
||||
* @param string $relation
|
||||
* @return mixed
|
||||
* @param string $relation
|
||||
*/
|
||||
public function getRelation($relation)
|
||||
{
|
||||
@ -551,7 +549,7 @@ trait HasRelationships
|
||||
/**
|
||||
* Determine if the given relation is loaded.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function relationLoaded($key)
|
||||
@ -562,8 +560,7 @@ trait HasRelationships
|
||||
/**
|
||||
* Set the given relationship on the model.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param mixed $value
|
||||
* @param string $relation
|
||||
* @return $this
|
||||
*/
|
||||
public function setRelation($relation, $value)
|
||||
@ -576,7 +573,7 @@ trait HasRelationships
|
||||
/**
|
||||
* Unset a loaded relationship.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return $this
|
||||
*/
|
||||
public function unsetRelation($relation)
|
||||
@ -589,7 +586,6 @@ trait HasRelationships
|
||||
/**
|
||||
* Set the entire relations array on the model.
|
||||
*
|
||||
* @param array $relations
|
||||
* @return $this
|
||||
*/
|
||||
public function setRelations(array $relations)
|
||||
@ -612,7 +608,6 @@ trait HasRelationships
|
||||
/**
|
||||
* Set the relationships that are touched on save.
|
||||
*
|
||||
* @param array $touches
|
||||
* @return $this
|
||||
*/
|
||||
public function setTouchedRelations(array $touches)
|
||||
@ -625,10 +620,8 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new HasOne relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @return \Hyperf\Database\Model\Relations\HasOne
|
||||
*/
|
||||
protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey)
|
||||
@ -639,13 +632,10 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new HasOneThrough relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $farParent
|
||||
* @param \Hyperf\Database\Model\Model $throughParent
|
||||
* @param string $firstKey
|
||||
* @param string $secondKey
|
||||
* @param string $localKey
|
||||
* @param string $secondLocalKey
|
||||
* @param string $firstKey
|
||||
* @param string $secondKey
|
||||
* @param string $localKey
|
||||
* @param string $secondLocalKey
|
||||
* @return \Hyperf\Database\Model\Relations\HasOneThrough
|
||||
*/
|
||||
protected function newHasOneThrough(Builder $query, Model $farParent, Model $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey)
|
||||
@ -656,11 +646,9 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new MorphOne relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @return \Hyperf\Database\Model\Relations\MorphOne
|
||||
*/
|
||||
protected function newMorphOne(Builder $query, Model $parent, $type, $id, $localKey)
|
||||
@ -671,11 +659,9 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new BelongsTo relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $child
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $relation
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $relation
|
||||
* @return \Hyperf\Database\Model\Relations\BelongsTo
|
||||
*/
|
||||
protected function newBelongsTo(Builder $query, Model $child, $foreignKey, $ownerKey, $relation)
|
||||
@ -686,10 +672,10 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a polymorphic, inverse one-to-one or many relationship.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $ownerKey
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $ownerKey
|
||||
* @return \Hyperf\Database\Model\Relations\MorphTo
|
||||
*/
|
||||
protected function morphEagerTo($name, $type, $id, $ownerKey)
|
||||
@ -707,11 +693,11 @@ trait HasRelationships
|
||||
/**
|
||||
* Define a polymorphic, inverse one-to-one or many relationship.
|
||||
*
|
||||
* @param string $target
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $ownerKey
|
||||
* @param string $target
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $ownerKey
|
||||
* @return \Hyperf\Database\Model\Relations\MorphTo
|
||||
*/
|
||||
protected function morphInstanceTo($target, $name, $type, $id, $ownerKey)
|
||||
@ -733,12 +719,10 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new MorphTo relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $type
|
||||
* @param string $relation
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $type
|
||||
* @param string $relation
|
||||
* @return \Hyperf\Database\Model\Relations\MorphTo
|
||||
*/
|
||||
protected function newMorphTo(Builder $query, Model $parent, $foreignKey, $ownerKey, $type, $relation)
|
||||
@ -761,10 +745,8 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new HasMany relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @return \Hyperf\Database\Model\Relations\HasMany
|
||||
*/
|
||||
protected function newHasMany(Builder $query, Model $parent, $foreignKey, $localKey)
|
||||
@ -775,13 +757,10 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new HasManyThrough relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $farParent
|
||||
* @param \Hyperf\Database\Model\Model $throughParent
|
||||
* @param string $firstKey
|
||||
* @param string $secondKey
|
||||
* @param string $localKey
|
||||
* @param string $secondLocalKey
|
||||
* @param string $firstKey
|
||||
* @param string $secondKey
|
||||
* @param string $localKey
|
||||
* @param string $secondLocalKey
|
||||
* @return \Hyperf\Database\Model\Relations\HasManyThrough
|
||||
*/
|
||||
protected function newHasManyThrough(Builder $query, Model $farParent, Model $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey)
|
||||
@ -792,11 +771,9 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new MorphMany relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @return \Hyperf\Database\Model\Relations\MorphMany
|
||||
*/
|
||||
protected function newMorphMany(Builder $query, Model $parent, $type, $id, $localKey)
|
||||
@ -807,14 +784,12 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new BelongsToMany relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relationName
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relationName
|
||||
* @return \Hyperf\Database\Model\Relations\BelongsToMany
|
||||
*/
|
||||
protected function newBelongsToMany(
|
||||
@ -833,16 +808,14 @@ trait HasRelationships
|
||||
/**
|
||||
* Instantiate a new MorphToMany relationship.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relationName
|
||||
* @param bool $inverse
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relationName
|
||||
* @param bool $inverse
|
||||
* @return \Hyperf\Database\Model\Relations\MorphToMany
|
||||
*/
|
||||
protected function newMorphToMany(
|
||||
@ -891,25 +864,24 @@ trait HasRelationships
|
||||
/**
|
||||
* Get the polymorphic relationship columns.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
protected function getMorphs($name, $type, $id)
|
||||
{
|
||||
return [$type ?: $name.'_type', $id ?: $name.'_id'];
|
||||
return [$type ?: $name . '_type', $id ?: $name . '_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new model instance for a related model.
|
||||
*
|
||||
* @param string $class
|
||||
* @return mixed
|
||||
* @param string $class
|
||||
*/
|
||||
protected function newRelatedInstance($class)
|
||||
{
|
||||
return tap(new $class, function ($instance) {
|
||||
return tap(new $class(), function ($instance) {
|
||||
if (! $instance->getConnectionName()) {
|
||||
$instance->setConnection($this->connection);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -41,7 +42,6 @@ trait HasTimestamps
|
||||
/**
|
||||
* Set the value of the "created at" attribute.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setCreatedAt($value)
|
||||
@ -54,7 +54,6 @@ trait HasTimestamps
|
||||
/**
|
||||
* Set the value of the "updated at" attribute.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setUpdatedAt($value)
|
||||
@ -116,8 +115,6 @@ trait HasTimestamps
|
||||
|
||||
/**
|
||||
* Update the creation and update timestamps.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function updateTimestamps()
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -40,7 +41,6 @@ trait HidesAttributes
|
||||
/**
|
||||
* Set the hidden attributes for the model.
|
||||
*
|
||||
* @param array $hidden
|
||||
* @return $this
|
||||
*/
|
||||
public function setHidden(array $hidden)
|
||||
@ -53,8 +53,7 @@ trait HidesAttributes
|
||||
/**
|
||||
* Add hidden attributes for the model.
|
||||
*
|
||||
* @param array|string|null $attributes
|
||||
* @return void
|
||||
* @param array|string|null $attributes
|
||||
*/
|
||||
public function addHidden($attributes = null)
|
||||
{
|
||||
@ -77,7 +76,6 @@ trait HidesAttributes
|
||||
/**
|
||||
* Set the visible attributes for the model.
|
||||
*
|
||||
* @param array $visible
|
||||
* @return $this
|
||||
*/
|
||||
public function setVisible(array $visible)
|
||||
@ -90,8 +88,7 @@ trait HidesAttributes
|
||||
/**
|
||||
* Add visible attributes for the model.
|
||||
*
|
||||
* @param array|string|null $attributes
|
||||
* @return void
|
||||
* @param array|string|null $attributes
|
||||
*/
|
||||
public function addVisible($attributes = null)
|
||||
{
|
||||
@ -104,7 +101,7 @@ trait HidesAttributes
|
||||
/**
|
||||
* Make the given, typically hidden, attributes visible.
|
||||
*
|
||||
* @param array|string $attributes
|
||||
* @param array|string $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function makeVisible($attributes)
|
||||
@ -121,7 +118,7 @@ trait HidesAttributes
|
||||
/**
|
||||
* Make the given, typically visible, attributes hidden.
|
||||
*
|
||||
* @param array|string $attributes
|
||||
* @param array|string $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function makeHidden($attributes)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -25,16 +26,15 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add a relationship count / exists condition to the query.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @param \Closure|null $callback
|
||||
* @param string $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null)
|
||||
{
|
||||
if (strpos($relation, '.') !== false) {
|
||||
if (false !== strpos($relation, '.')) {
|
||||
return $this->hasNested($relation, $operator, $count, $boolean, $callback);
|
||||
}
|
||||
|
||||
@ -75,9 +75,9 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add a relationship count / exists condition to the query with an "or".
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function orHas($relation, $operator = '>=', $count = 1)
|
||||
@ -88,9 +88,8 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add a relationship count / exists condition to the query.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $boolean
|
||||
* @param \Closure|null $callback
|
||||
* @param string $relation
|
||||
* @param string $boolean
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function doesntHave($relation, $boolean = 'and', Closure $callback = null)
|
||||
@ -101,7 +100,7 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add a relationship count / exists condition to the query with an "or".
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function orDoesntHave($relation)
|
||||
@ -112,10 +111,9 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add a relationship count / exists condition to the query with where clauses.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param \Closure|null $callback
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function whereHas($relation, Closure $callback = null, $operator = '>=', $count = 1)
|
||||
@ -126,10 +124,10 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add a relationship count / exists condition to the query with where clauses and an "or".
|
||||
*
|
||||
* @param string $relation
|
||||
* @param \Closure $callback
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $relation
|
||||
* @param \Closure $callback
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function orWhereHas($relation, Closure $callback = null, $operator = '>=', $count = 1)
|
||||
@ -140,8 +138,7 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add a relationship count / exists condition to the query with where clauses.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param \Closure|null $callback
|
||||
* @param string $relation
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function whereDoesntHave($relation, Closure $callback = null)
|
||||
@ -152,8 +149,8 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add a relationship count / exists condition to the query with where clauses and an "or".
|
||||
*
|
||||
* @param string $relation
|
||||
* @param \Closure $callback
|
||||
* @param string $relation
|
||||
* @param \Closure $callback
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function orWhereDoesntHave($relation, Closure $callback = null)
|
||||
@ -164,7 +161,6 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add subselect queries to count the relations.
|
||||
*
|
||||
* @param mixed $relations
|
||||
* @return $this
|
||||
*/
|
||||
public function withCount($relations)
|
||||
@ -174,7 +170,7 @@ trait QueriesRelationships
|
||||
}
|
||||
|
||||
if (is_null($this->query->columns)) {
|
||||
$this->query->select([$this->query->from.'.*']);
|
||||
$this->query->select([$this->query->from . '.*']);
|
||||
}
|
||||
|
||||
$relations = is_array($relations) ? $relations : func_get_args();
|
||||
@ -187,7 +183,7 @@ trait QueriesRelationships
|
||||
|
||||
unset($alias);
|
||||
|
||||
if (count($segments) === 3 && Str::lower($segments[1]) === 'as') {
|
||||
if (3 === count($segments) && 'as' === Str::lower($segments[1])) {
|
||||
[$name, $alias] = [$segments[0], $segments[2]];
|
||||
}
|
||||
|
||||
@ -212,7 +208,7 @@ trait QueriesRelationships
|
||||
// Finally we will add the proper result column alias to the query and run the subselect
|
||||
// statement against the query builder. Then we will return the builder instance back
|
||||
// to the developer for further constraint chaining that needs to take place on it.
|
||||
$column = $alias ?? Str::snake($name.'_count');
|
||||
$column = $alias ?? Str::snake($name . '_count');
|
||||
|
||||
$this->selectSub($query, $column);
|
||||
}
|
||||
@ -223,7 +219,6 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Merge the where constraints from another query to the current query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $from
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function mergeConstraintsFrom(Builder $from)
|
||||
@ -246,18 +241,18 @@ trait QueriesRelationships
|
||||
*
|
||||
* Sets up recursive call to whereHas until we finish the nested relation.
|
||||
*
|
||||
* @param string $relations
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @param \Closure|null $callback
|
||||
* @param string $relations
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @param \Closure|null $callback
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
protected function hasNested($relations, $operator = '>=', $count = 1, $boolean = 'and', $callback = null)
|
||||
{
|
||||
$relations = explode('.', $relations);
|
||||
|
||||
$doesntHave = $operator === '<' && $count === 1;
|
||||
$doesntHave = '<' === $operator && 1 === $count;
|
||||
|
||||
if ($doesntHave) {
|
||||
$operator = '>=';
|
||||
@ -279,11 +274,9 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Add the "has" condition where clause to the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $hasQuery
|
||||
* @param \Hyperf\Database\Model\Relations\Relation $relation
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, $count, $boolean)
|
||||
@ -291,17 +284,16 @@ trait QueriesRelationships
|
||||
$hasQuery->mergeConstraintsFrom($relation->getQuery());
|
||||
|
||||
return $this->canUseExistsForExistenceCheck($operator, $count)
|
||||
? $this->addWhereExistsQuery($hasQuery->toBase(), $boolean, $operator === '<' && $count === 1)
|
||||
? $this->addWhereExistsQuery($hasQuery->toBase(), $boolean, '<' === $operator && 1 === $count)
|
||||
: $this->addWhereCountQuery($hasQuery->toBase(), $operator, $count, $boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a sub-query count clause to this query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $boolean
|
||||
* @return $this
|
||||
*/
|
||||
protected function addWhereCountQuery(QueryBuilder $query, $operator = '>=', $count = 1, $boolean = 'and')
|
||||
@ -309,7 +301,7 @@ trait QueriesRelationships
|
||||
$this->query->addBinding($query->getBindings(), 'where');
|
||||
|
||||
return $this->where(
|
||||
new Expression('('.$query->toSql().')'),
|
||||
new Expression('(' . $query->toSql() . ')'),
|
||||
$operator,
|
||||
is_numeric($count) ? new Expression($count) : $count,
|
||||
$boolean
|
||||
@ -319,7 +311,7 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Get the "has relation" base query instance.
|
||||
*
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return \Hyperf\Database\Model\Relations\Relation
|
||||
*/
|
||||
protected function getRelationWithoutConstraints($relation)
|
||||
@ -332,12 +324,12 @@ trait QueriesRelationships
|
||||
/**
|
||||
* Check if we can run an "exists" query to optimize performance.
|
||||
*
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @param string $operator
|
||||
* @param int $count
|
||||
* @return bool
|
||||
*/
|
||||
protected function canUseExistsForExistenceCheck($operator, $count)
|
||||
{
|
||||
return ($operator === '>=' || $operator === '<') && $count === 1;
|
||||
return ('>=' === $operator || '<' === $operator) && 1 === $count;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -30,9 +31,6 @@ abstract class Event
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod(): string
|
||||
{
|
||||
return $this->method;
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -54,9 +55,6 @@ class Factory implements ArrayAccess
|
||||
|
||||
/**
|
||||
* Create a new factory instance.
|
||||
*
|
||||
* @param \Faker\Generator $faker
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Faker $faker)
|
||||
{
|
||||
@ -66,8 +64,7 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Create a new factory container.
|
||||
*
|
||||
* @param \Faker\Generator $faker
|
||||
* @param string|null $pathToFactories
|
||||
* @param string|null $pathToFactories
|
||||
* @return static
|
||||
*/
|
||||
public static function construct(Faker $faker, $pathToFactories = null)
|
||||
@ -80,9 +77,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Define a class with a given short-name.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @param callable $attributes
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function defineAs($class, $name, callable $attributes)
|
||||
@ -93,9 +89,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Define a class with a given set of attributes.
|
||||
*
|
||||
* @param string $class
|
||||
* @param callable $attributes
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function define($class, callable $attributes, $name = 'default')
|
||||
@ -108,9 +103,9 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Define a state with a given set of attributes.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $state
|
||||
* @param callable|array $attributes
|
||||
* @param string $class
|
||||
* @param string $state
|
||||
* @param callable|array $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function state($class, $state, $attributes)
|
||||
@ -123,9 +118,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Define a callback to run after making a model.
|
||||
*
|
||||
* @param string $class
|
||||
* @param callable $callback
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function afterMaking($class, callable $callback, $name = 'default')
|
||||
@ -138,9 +132,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Define a callback to run after making a model with given state.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $state
|
||||
* @param callable $callback
|
||||
* @param string $class
|
||||
* @param string $state
|
||||
* @return $this
|
||||
*/
|
||||
public function afterMakingState($class, $state, callable $callback)
|
||||
@ -151,8 +144,7 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Define a callback to run after creating a model.
|
||||
*
|
||||
* @param string $class
|
||||
* @param callable $callback
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
@ -166,9 +158,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Define a callback to run after creating a model with given state.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $state
|
||||
* @param callable $callback
|
||||
* @param string $class
|
||||
* @param string $state
|
||||
* @return $this
|
||||
*/
|
||||
public function afterCreatingState($class, $state, callable $callback)
|
||||
@ -179,9 +170,7 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Create an instance of the given model and persist it to the database.
|
||||
*
|
||||
* @param string $class
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
* @param string $class
|
||||
*/
|
||||
public function create($class, array $attributes = [])
|
||||
{
|
||||
@ -191,10 +180,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Create an instance of the given model and type and persist it to the database.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
*/
|
||||
public function createAs($class, $name, array $attributes = [])
|
||||
{
|
||||
@ -204,9 +191,7 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Create an instance of the given model.
|
||||
*
|
||||
* @param string $class
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
* @param string $class
|
||||
*/
|
||||
public function make($class, array $attributes = [])
|
||||
{
|
||||
@ -216,10 +201,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Create an instance of the given model and type.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
*/
|
||||
public function makeAs($class, $name, array $attributes = [])
|
||||
{
|
||||
@ -229,9 +212,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Get the raw attribute array for a given named model.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @param array $attributes
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function rawOf($class, $name, array $attributes = [])
|
||||
@ -242,9 +224,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Get the raw attribute array for a given model.
|
||||
*
|
||||
* @param string $class
|
||||
* @param array $attributes
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function raw($class, array $attributes = [], $name = 'default')
|
||||
@ -258,8 +239,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Create a builder for the given model.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @return \Hyperf\Database\Model\FactoryBuilder
|
||||
*/
|
||||
public function of($class, $name = 'default')
|
||||
@ -278,7 +259,7 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Load factories from path.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $path
|
||||
* @return $this
|
||||
*/
|
||||
public function load($path)
|
||||
@ -297,7 +278,7 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Determine if the given offset exists.
|
||||
*
|
||||
* @param string $offset
|
||||
* @param string $offset
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
@ -308,8 +289,7 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Get the value of the given offset.
|
||||
*
|
||||
* @param string $offset
|
||||
* @return mixed
|
||||
* @param string $offset
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
@ -319,9 +299,8 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Set the given offset to the given value.
|
||||
*
|
||||
* @param string $offset
|
||||
* @param callable $value
|
||||
* @return void
|
||||
* @param string $offset
|
||||
* @param callable $value
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
@ -331,8 +310,7 @@ class Factory implements ArrayAccess
|
||||
/**
|
||||
* Unset the value at the given offset.
|
||||
*
|
||||
* @param string $offset
|
||||
* @return void
|
||||
* @param string $offset
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -92,14 +93,8 @@ class FactoryBuilder
|
||||
/**
|
||||
* Create an new builder instance.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
* @param array $definitions
|
||||
* @param array $states
|
||||
* @param array $afterMaking
|
||||
* @param array $afterCreating
|
||||
* @param \Faker\Generator $faker
|
||||
* @return void
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(
|
||||
$class,
|
||||
@ -122,7 +117,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Set the amount of models you wish to create / make.
|
||||
*
|
||||
* @param int $amount
|
||||
* @param int $amount
|
||||
* @return $this
|
||||
*/
|
||||
public function times($amount)
|
||||
@ -135,7 +130,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Set the state to be applied to the model.
|
||||
*
|
||||
* @param string $state
|
||||
* @param string $state
|
||||
* @return $this
|
||||
*/
|
||||
public function state($state)
|
||||
@ -146,7 +141,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Set the states to be applied to the model.
|
||||
*
|
||||
* @param array|mixed $states
|
||||
* @param array|mixed $states
|
||||
* @return $this
|
||||
*/
|
||||
public function states($states)
|
||||
@ -159,7 +154,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Set the database connection on which the model instance should be persisted.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function connection($name)
|
||||
@ -172,7 +167,6 @@ class FactoryBuilder
|
||||
/**
|
||||
* Create a model and persist it in the database if requested.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Closure
|
||||
*/
|
||||
public function lazy(array $attributes = [])
|
||||
@ -184,9 +178,6 @@ class FactoryBuilder
|
||||
|
||||
/**
|
||||
* Create a collection of models and persist them to the database.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(array $attributes = [])
|
||||
{
|
||||
@ -207,23 +198,20 @@ class FactoryBuilder
|
||||
|
||||
/**
|
||||
* Create a collection of models.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function make(array $attributes = [])
|
||||
{
|
||||
if ($this->amount === null) {
|
||||
if (null === $this->amount) {
|
||||
return tap($this->makeInstance($attributes), function ($instance) {
|
||||
$this->callAfterMaking(collect([$instance]));
|
||||
});
|
||||
}
|
||||
|
||||
if ($this->amount < 1) {
|
||||
return (new $this->class)->newCollection();
|
||||
return (new $this->class())->newCollection();
|
||||
}
|
||||
|
||||
$instances = (new $this->class)->newCollection(array_map(function () use ($attributes) {
|
||||
$instances = (new $this->class())->newCollection(array_map(function () use ($attributes) {
|
||||
return $this->makeInstance($attributes);
|
||||
}, range(1, $this->amount)));
|
||||
|
||||
@ -234,13 +222,10 @@ class FactoryBuilder
|
||||
|
||||
/**
|
||||
* Create an array of raw attribute arrays.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function raw(array $attributes = [])
|
||||
{
|
||||
if ($this->amount === null) {
|
||||
if (null === $this->amount) {
|
||||
return $this->getRawAttributes($attributes);
|
||||
}
|
||||
|
||||
@ -256,8 +241,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Run after making callbacks on a collection of models.
|
||||
*
|
||||
* @param \Hyperf\Utils\Collection $models
|
||||
* @return void
|
||||
* @param \Hyperf\Utils\Collection $models
|
||||
*/
|
||||
public function callAfterMaking($models)
|
||||
{
|
||||
@ -267,8 +251,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Run after creating callbacks on a collection of models.
|
||||
*
|
||||
* @param \Hyperf\Utils\Collection $models
|
||||
* @return void
|
||||
* @param \Hyperf\Utils\Collection $models
|
||||
*/
|
||||
public function callAfterCreating($models)
|
||||
{
|
||||
@ -278,8 +261,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Set the connection name on the results and store them.
|
||||
*
|
||||
* @param \Hyperf\Utils\Collection $results
|
||||
* @return void
|
||||
* @param \Hyperf\Utils\Collection $results
|
||||
*/
|
||||
protected function store($results)
|
||||
{
|
||||
@ -295,8 +277,6 @@ class FactoryBuilder
|
||||
/**
|
||||
* Get a raw attributes array for the model.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
@ -320,7 +300,6 @@ class FactoryBuilder
|
||||
/**
|
||||
* Make an instance of the model with the given attributes.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
protected function makeInstance(array $attributes = [])
|
||||
@ -341,8 +320,6 @@ class FactoryBuilder
|
||||
/**
|
||||
* Apply the active states to the model definition array.
|
||||
*
|
||||
* @param array $definition
|
||||
* @param array $attributes
|
||||
* @return array
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
@ -370,8 +347,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Get the state attributes.
|
||||
*
|
||||
* @param string $state
|
||||
* @param array $attributes
|
||||
* @param string $state
|
||||
* @return array
|
||||
*/
|
||||
protected function stateAttributes($state, array $attributes)
|
||||
@ -392,7 +368,6 @@ class FactoryBuilder
|
||||
/**
|
||||
* Expand all attributes to their underlying values.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return array
|
||||
*/
|
||||
protected function expandAttributes(array $attributes)
|
||||
@ -417,9 +392,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Call after callbacks for each model and state.
|
||||
*
|
||||
* @param array $afterCallbacks
|
||||
* @param \Hyperf\Utils\Collection $models
|
||||
* @return void
|
||||
* @param \Hyperf\Utils\Collection $models
|
||||
*/
|
||||
protected function callAfter(array $afterCallbacks, $models)
|
||||
{
|
||||
@ -435,10 +408,8 @@ class FactoryBuilder
|
||||
/**
|
||||
* Call after callbacks for each model and state.
|
||||
*
|
||||
* @param array $afterCallbacks
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @param string $state
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @param string $state
|
||||
*/
|
||||
protected function callAfterCallbacks(array $afterCallbacks, $model, $state)
|
||||
{
|
||||
@ -454,7 +425,7 @@ class FactoryBuilder
|
||||
/**
|
||||
* Determine if the given state has an "after" callback.
|
||||
*
|
||||
* @param string $state
|
||||
* @param string $state
|
||||
* @return bool
|
||||
*/
|
||||
protected function stateHasAfterCallback($state)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -18,20 +19,17 @@ class JsonEncodingException extends RuntimeException
|
||||
/**
|
||||
* Create a new JSON encoding exception for the model.
|
||||
*
|
||||
* @param mixed $model
|
||||
* @param string $message
|
||||
* @param string $message
|
||||
* @return static
|
||||
*/
|
||||
public static function forModel($model, $message)
|
||||
{
|
||||
return new static('Error encoding model ['.get_class($model).'] with ID ['.$model->getKey().'] to JSON: '.$message);
|
||||
return new static('Error encoding model [' . get_class($model) . '] with ID [' . $model->getKey() . '] to JSON: ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new JSON encoding exception for an attribute.
|
||||
*
|
||||
* @param mixed $model
|
||||
* @param mixed $key
|
||||
* @param string $message
|
||||
* @return static
|
||||
*/
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -15,5 +16,4 @@ use RuntimeException;
|
||||
|
||||
class MassAssignmentException extends RuntimeException
|
||||
{
|
||||
//
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -117,9 +118,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Create a new Model model instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
@ -133,8 +131,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Dynamically retrieve attributes on the model.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
@ -144,9 +141,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Dynamically set attributes on the model.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
* @param string $key
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
@ -167,8 +162,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Unset an attribute on the model.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
* @param string $key
|
||||
*/
|
||||
public function __unset($key)
|
||||
{
|
||||
@ -178,9 +172,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Handle dynamic method calls into the model.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
@ -194,19 +187,16 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Handle dynamic static method calls into the method.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
return (new static)->$method(...$parameters);
|
||||
return (new static())->$method(...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the model to its string representation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
@ -215,8 +205,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* When a model is being unserialized, check if it needs to be booted.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup()
|
||||
{
|
||||
@ -225,9 +213,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Disables relationship model touching for the current class during given callback scope.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public static function withoutTouching(callable $callback)
|
||||
{
|
||||
@ -236,10 +221,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Disables relationship model touching for the given model classes during given callback scope.
|
||||
*
|
||||
* @param array $models
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public static function withoutTouchingOn(array $models, callable $callback)
|
||||
{
|
||||
@ -274,7 +255,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Fill the model with an array of attributes.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return $this
|
||||
* @throws \Hyperf\Database\Model\MassAssignmentException
|
||||
*/
|
||||
@ -301,7 +281,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Fill the model with an array of attributes. Force mass assignment.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function forceFill(array $attributes)
|
||||
@ -329,8 +308,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Create a new instance of the given model.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param bool $exists
|
||||
* @param array $attributes
|
||||
* @param bool $exists
|
||||
* @return static
|
||||
*/
|
||||
public function newInstance($attributes = [], $exists = false)
|
||||
@ -338,7 +317,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
// This method just provides a convenient way for us to generate fresh model
|
||||
// instances of this current model. It is particularly useful during the
|
||||
// hydration of new objects via the Model query builder instances.
|
||||
$model = new static((array)$attributes);
|
||||
$model = new static((array) $attributes);
|
||||
|
||||
$model->exists = $exists;
|
||||
|
||||
@ -352,7 +331,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Create a new model instance that is existing.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
* @param string|null $connection
|
||||
* @return static
|
||||
*/
|
||||
@ -360,7 +339,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
{
|
||||
$model = $this->newInstance([], true);
|
||||
|
||||
$model->setRawAttributes((array)$attributes, true);
|
||||
$model->setRawAttributes((array) $attributes, true);
|
||||
|
||||
$model->setConnection($connection ? : $this->getConnectionName());
|
||||
|
||||
@ -372,7 +351,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Begin querying the model on a given connection.
|
||||
*
|
||||
* @param string|null $connection
|
||||
* @param string|null $connection
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public static function on($connection = null)
|
||||
@ -380,7 +359,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
// First we will just create a fresh instance of this model, and then we can set the
|
||||
// connection on the model so that it is used for the queries we execute, as well
|
||||
// as being set on every relation we retrieve without a custom connection name.
|
||||
$instance = new static;
|
||||
$instance = new static();
|
||||
|
||||
$instance->setConnection($connection);
|
||||
|
||||
@ -400,7 +379,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Get all of the models from the database.
|
||||
*
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Collection|static[]
|
||||
*/
|
||||
public static function all($columns = ['*'])
|
||||
@ -411,7 +390,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Begin querying a model with eager loading.
|
||||
*
|
||||
* @param array|string $relations
|
||||
* @param array|string $relations
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public static function with($relations)
|
||||
@ -467,8 +446,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Update the model in the database.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
public function update(array $attributes = [], array $options = [])
|
||||
@ -510,7 +487,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Save the model to the database.
|
||||
*
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
public function save(array $options = [])
|
||||
@ -520,7 +496,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
// If the "saving" event returns false we'll bail out of the save and return
|
||||
// false, indicating that the save failed. This provides a chance for any
|
||||
// listeners to cancel save operations if validations fail or whatever.
|
||||
if ($this->fireModelEvent('saving') === false) {
|
||||
if (false === $this->fireModelEvent('saving')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -555,7 +531,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Save the model to the database using transaction.
|
||||
*
|
||||
* @param array $options
|
||||
* @return bool
|
||||
* @throws \Throwable
|
||||
*/
|
||||
@ -588,11 +563,11 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
// We will actually pull the models from the database table and call delete on
|
||||
// each of them individually so that their events get fired properly with a
|
||||
// correct set of attributes in case the developers wants to check these.
|
||||
$key = ($instance = new static)->getKeyName();
|
||||
$key = ($instance = new static())->getKeyName();
|
||||
|
||||
foreach ($instance->whereIn($key, $ids)->get() as $model) {
|
||||
if ($model->delete()) {
|
||||
$count++;
|
||||
++$count;
|
||||
}
|
||||
}
|
||||
|
||||
@ -618,7 +593,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->fireModelEvent('deleting') === false) {
|
||||
if (false === $this->fireModelEvent('deleting')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -655,7 +630,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
*/
|
||||
public static function query()
|
||||
{
|
||||
return (new static)->newQuery();
|
||||
return (new static())->newQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -727,7 +702,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Get a new query to restore one or more models by their queueable IDs.
|
||||
*
|
||||
* @param array|int $ids
|
||||
* @param array|int $ids
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function newQueryForRestoration($ids)
|
||||
@ -739,7 +714,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Create a new Model query builder for the model.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return \Hyperf\Database\Model\Builder|static
|
||||
*/
|
||||
public function newModelBuilder($query)
|
||||
@ -750,7 +725,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Create a new Model Collection instance.
|
||||
*
|
||||
* @param array $models
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function newCollection(array $models = [])
|
||||
@ -761,11 +735,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Create a new pivot model instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param array $attributes
|
||||
* @param string $table
|
||||
* @param bool $exists
|
||||
* @param string|null $using
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $table
|
||||
* @param bool $exists
|
||||
* @param string|null $using
|
||||
* @return \Hyperf\Database\Model\Relations\Pivot
|
||||
*/
|
||||
public function newPivot(self $parent, array $attributes, $table, $exists, $using = null)
|
||||
@ -775,8 +748,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Convert the model instance to an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
@ -786,7 +757,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Convert the model instance to JSON.
|
||||
*
|
||||
* @param int $options
|
||||
* @param int $options
|
||||
* @return string
|
||||
* @throws \Hyperf\Database\Model\JsonEncodingException
|
||||
*/
|
||||
@ -852,7 +823,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Clone the model into a new, non-existing instance.
|
||||
*
|
||||
* @param array|null $except
|
||||
* @return static
|
||||
*/
|
||||
public function replicate(array $except = null)
|
||||
@ -865,7 +835,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
$attributes = Arr::except($this->attributes, $except ? array_unique(array_merge($except, $defaults)) : $defaults);
|
||||
|
||||
return tap(new static, function ($instance) use ($attributes) {
|
||||
return tap(new static(), function ($instance) use ($attributes) {
|
||||
$instance->setRawAttributes($attributes);
|
||||
|
||||
$instance->setRelations($this->relations);
|
||||
@ -880,7 +850,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
*/
|
||||
public function is($model)
|
||||
{
|
||||
return ! is_null($model) && $this->getKey() === $model->getKey() && $this->getTable() === $model->getTable() && $this->getConnectionName() === $model->getConnectionName();
|
||||
return ! is_null($model) &&
|
||||
$this->getKey() === $model->getKey() &&
|
||||
$this->getTable() === $model->getTable() &&
|
||||
$this->getConnectionName() === $model->getConnectionName();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -897,8 +870,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Get the database connection for the model.
|
||||
* You can write it by yourself.
|
||||
*
|
||||
* @return ConnectionInterface
|
||||
*/
|
||||
public function getConnection(): ConnectionInterface
|
||||
{
|
||||
@ -1031,7 +1002,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Set whether IDs are incrementing.
|
||||
*
|
||||
* @param bool $value
|
||||
* @param bool $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setIncrementing($value)
|
||||
@ -1043,8 +1014,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Get the value of the model's primary key.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
@ -1053,8 +1022,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Get the queueable identity for the entity.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getQueueableId()
|
||||
{
|
||||
@ -1093,8 +1060,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Get the queueable connection for the entity.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getQueueableConnection()
|
||||
{
|
||||
@ -1103,8 +1068,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Get the value of the model's route key.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRouteKey()
|
||||
{
|
||||
@ -1124,7 +1087,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Retrieve the model for a bound value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return \Hyperf\Database\Model\Model|null
|
||||
*/
|
||||
public function resolveRouteBinding($value)
|
||||
@ -1155,7 +1117,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Set the number of models to return per page.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param int $perPage
|
||||
* @return $this
|
||||
*/
|
||||
public function setPerPage($perPage)
|
||||
@ -1168,7 +1130,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Determine if the given attribute exists.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
@ -1178,9 +1139,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Get the value for a given offset.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
@ -1189,10 +1147,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Set the value for a given offset.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
@ -1201,9 +1155,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Unset the value for a given offset.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
@ -1269,9 +1220,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Increment a column's value by a given amount.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @param float|int $amount
|
||||
* @param array $extra
|
||||
* @return int
|
||||
*/
|
||||
protected function increment($column, $amount = 1, array $extra = [])
|
||||
@ -1282,9 +1232,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Decrement a column's value by a given amount.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @param float|int $amount
|
||||
* @param array $extra
|
||||
* @return int
|
||||
*/
|
||||
protected function decrement($column, $amount = 1, array $extra = [])
|
||||
@ -1295,10 +1244,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Run the increment or decrement method on the model.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @param float|int $amount
|
||||
* @param array $extra
|
||||
* @param string $method
|
||||
* @param array $extra
|
||||
* @param string $method
|
||||
* @return int
|
||||
*/
|
||||
protected function incrementOrDecrement($column, $amount, $extra, $method)
|
||||
@ -1317,15 +1266,14 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Increment the underlying attribute value and sync with original.
|
||||
*
|
||||
* @param string $column
|
||||
* @param float|int $amount
|
||||
* @param array $extra
|
||||
* @param string $method
|
||||
* @return void
|
||||
* @param string $column
|
||||
* @param float|int $amount
|
||||
* @param array $extra
|
||||
* @param string $method
|
||||
*/
|
||||
protected function incrementOrDecrementAttributeValue($column, $amount, $extra, $method)
|
||||
{
|
||||
$this->{$column} = $this->{$column} + ($method === 'increment' ? $amount : $amount * -1);
|
||||
$this->{$column} = $this->{$column} + ('increment' === $method ? $amount : $amount * -1);
|
||||
|
||||
$this->forceFill($extra);
|
||||
|
||||
@ -1334,9 +1282,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Perform any actions that are necessary after the model is saved.
|
||||
*
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
protected function finishSave(array $options)
|
||||
{
|
||||
@ -1360,7 +1305,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
// If the updating event returns false, we will cancel the update operation so
|
||||
// developers can hook Validation systems into their models and cancel this
|
||||
// operation if the model does not pass validation. Otherwise, we update.
|
||||
if ($this->fireModelEvent('updating') === false) {
|
||||
if (false === $this->fireModelEvent('updating')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1402,8 +1347,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Get the primary key value for a save query.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getKeyForSaveQuery()
|
||||
{
|
||||
@ -1418,7 +1361,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
*/
|
||||
protected function performInsert(Builder $query)
|
||||
{
|
||||
if ($this->fireModelEvent('creating') === false) {
|
||||
if (false === $this->fireModelEvent('creating')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1464,9 +1407,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
/**
|
||||
* Insert the given attributes and set the ID on the model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param array $attributes
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param array $attributes
|
||||
*/
|
||||
protected function insertAndSetId(Builder $query, $attributes)
|
||||
{
|
||||
@ -1477,8 +1419,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
|
||||
|
||||
/**
|
||||
* Perform the actual delete query on this model instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function performDeleteOnModel()
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -33,8 +34,8 @@ class ModelNotFoundException extends RuntimeException
|
||||
/**
|
||||
* Set the affected Model model and instance ids.
|
||||
*
|
||||
* @param string $model
|
||||
* @param int|array $ids
|
||||
* @param string $model
|
||||
* @param int|array $ids
|
||||
* @return $this
|
||||
*/
|
||||
public function setModel($model, $ids = [])
|
||||
@ -45,7 +46,7 @@ class ModelNotFoundException extends RuntimeException
|
||||
$this->message = "No query results for model [{$model}]";
|
||||
|
||||
if (count($this->ids) > 0) {
|
||||
$this->message .= ' '.implode(', ', $this->ids);
|
||||
$this->message .= ' ' . implode(', ', $this->ids);
|
||||
} else {
|
||||
$this->message .= '.';
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -32,7 +33,7 @@ class Register
|
||||
/**
|
||||
* Resolve a connection instance.
|
||||
*
|
||||
* @param string|null $connection
|
||||
* @param string|null $connection
|
||||
* @return ConnectionInterface
|
||||
*/
|
||||
public static function resolveConnection($connection = null)
|
||||
@ -52,9 +53,6 @@ class Register
|
||||
|
||||
/**
|
||||
* Set the connection resolver instance.
|
||||
*
|
||||
* @param ConnectionResolverInterface $resolver
|
||||
* @return void
|
||||
*/
|
||||
public static function setConnectionResolver(ConnectionResolverInterface $resolver)
|
||||
{
|
||||
@ -63,8 +61,6 @@ class Register
|
||||
|
||||
/**
|
||||
* Unset the connection resolver for models.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function unsetConnectionResolver()
|
||||
{
|
||||
@ -83,9 +79,6 @@ class Register
|
||||
|
||||
/**
|
||||
* Set the event dispatcher instance.
|
||||
*
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
* @return void
|
||||
*/
|
||||
public static function setEventDispatcher(EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
@ -94,8 +87,6 @@ class Register
|
||||
|
||||
/**
|
||||
* Unset the event dispatcher for models.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function unsetEventDispatcher()
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -32,8 +33,7 @@ class RelationNotFoundException extends RuntimeException
|
||||
/**
|
||||
* Create a new exception instance.
|
||||
*
|
||||
* @param mixed $model
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return static
|
||||
*/
|
||||
public static function make($model, $relation)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -56,13 +57,9 @@ class BelongsTo extends Relation
|
||||
/**
|
||||
* Create a new belongs to relationship instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $child
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $relationName
|
||||
*
|
||||
* @return void
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $relationName
|
||||
*/
|
||||
public function __construct(Builder $query, Model $child, $foreignKey, $ownerKey, $relationName)
|
||||
{
|
||||
@ -80,8 +77,6 @@ class BelongsTo extends Relation
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
@ -90,8 +85,6 @@ class BelongsTo extends Relation
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
@ -101,22 +94,19 @@ class BelongsTo extends Relation
|
||||
// of the related models matching on the foreign key that's on a parent.
|
||||
$table = $this->related->getTable();
|
||||
|
||||
$this->query->where($table.'.'.$this->ownerKey, '=', $this->child->{$this->foreignKey});
|
||||
$this->query->where($table . '.' . $this->ownerKey, '=', $this->child->{$this->foreignKey});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->ownerKey;
|
||||
$key = $this->related->getTable() . '.' . $this->ownerKey;
|
||||
|
||||
$whereIn = $this->whereInMethod($this->related, $this->ownerKey);
|
||||
|
||||
@ -126,8 +116,7 @@ class BelongsTo extends Relation
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
@ -142,9 +131,7 @@ class BelongsTo extends Relation
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
@ -176,9 +163,6 @@ class BelongsTo extends Relation
|
||||
|
||||
/**
|
||||
* Update the parent model on the relationship.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(array $attributes)
|
||||
{
|
||||
@ -188,7 +172,7 @@ class BelongsTo extends Relation
|
||||
/**
|
||||
* Associate the model instance to the given parent.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model|int|string $model
|
||||
* @param \Hyperf\Database\Model\Model|int|string $model
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function associate($model)
|
||||
@ -221,9 +205,7 @@ class BelongsTo extends Relation
|
||||
/**
|
||||
* Add the constraints for a relationship query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
@ -242,21 +224,19 @@ class BelongsTo extends Relation
|
||||
/**
|
||||
* Add the constraints for a relationship query on the same table.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
{
|
||||
$query->select($columns)->from(
|
||||
$query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash()
|
||||
$query->getModel()->getTable() . ' as ' . $hash = $this->getRelationCountHash()
|
||||
);
|
||||
|
||||
$query->getModel()->setTable($hash);
|
||||
|
||||
return $query->whereColumn(
|
||||
$hash.'.'.$this->ownerKey,
|
||||
$hash . '.' . $this->ownerKey,
|
||||
'=',
|
||||
$this->getQualifiedForeignKeyName()
|
||||
);
|
||||
@ -269,7 +249,7 @@ class BelongsTo extends Relation
|
||||
*/
|
||||
public function getRelationCountHash()
|
||||
{
|
||||
return 'laravel_reserved_'.static::$selfJoinCount++;
|
||||
return 'laravel_reserved_' . static::$selfJoinCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -346,7 +326,6 @@ class BelongsTo extends Relation
|
||||
/**
|
||||
* Gather the keys from an array of related models.
|
||||
*
|
||||
* @param array $models
|
||||
* @return array
|
||||
*/
|
||||
protected function getEagerModelKeys(array $models)
|
||||
@ -365,7 +344,7 @@ class BelongsTo extends Relation
|
||||
// If there are no keys that were not null we will just return an array with null
|
||||
// so this query wont fail plus returns zero results, which should be what the
|
||||
// developer expects to happen in this situation. Otherwise we'll sort them.
|
||||
if (count($keys) === 0) {
|
||||
if (0 === count($keys)) {
|
||||
return [null];
|
||||
}
|
||||
|
||||
@ -382,13 +361,12 @@ class BelongsTo extends Relation
|
||||
protected function relationHasIncrementingId()
|
||||
{
|
||||
return $this->related->getIncrementing() &&
|
||||
$this->related->getKeyType() === 'int';
|
||||
'int' === $this->related->getKeyType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a new related instance for the given model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
protected function newRelatedInstanceFor(Model $parent)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -137,15 +138,12 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Create a new belongs to many relationship instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relationName
|
||||
* @return void
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relationName
|
||||
*/
|
||||
public function __construct(
|
||||
Builder $query,
|
||||
@ -169,8 +167,6 @@ class BelongsToMany extends Relation
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
@ -183,9 +179,6 @@ class BelongsToMany extends Relation
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
@ -200,8 +193,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
@ -216,9 +208,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
@ -253,7 +243,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Specify the custom pivot model to use for the relationship.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $class
|
||||
* @return $this
|
||||
*/
|
||||
public function using($class)
|
||||
@ -266,7 +256,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Specify the custom pivot accessor to use for the relationship.
|
||||
*
|
||||
* @param string $accessor
|
||||
* @param string $accessor
|
||||
* @return $this
|
||||
*/
|
||||
public function as($accessor)
|
||||
@ -279,41 +269,38 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Set a where clause for a pivot table column.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $operator
|
||||
* @param mixed $value
|
||||
* @param string $boolean
|
||||
* @param string $column
|
||||
* @param string $operator
|
||||
* @param string $boolean
|
||||
* @return $this
|
||||
*/
|
||||
public function wherePivot($column, $operator = null, $value = null, $boolean = 'and')
|
||||
{
|
||||
$this->pivotWheres[] = func_get_args();
|
||||
|
||||
return $this->where($this->table.'.'.$column, $operator, $value, $boolean);
|
||||
return $this->where($this->table . '.' . $column, $operator, $value, $boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a "where in" clause for a pivot table column.
|
||||
*
|
||||
* @param string $column
|
||||
* @param mixed $values
|
||||
* @param string $boolean
|
||||
* @param bool $not
|
||||
* @param string $column
|
||||
* @param string $boolean
|
||||
* @param bool $not
|
||||
* @return $this
|
||||
*/
|
||||
public function wherePivotIn($column, $values, $boolean = 'and', $not = false)
|
||||
{
|
||||
$this->pivotWhereIns[] = func_get_args();
|
||||
|
||||
return $this->whereIn($this->table.'.'.$column, $values, $boolean, $not);
|
||||
return $this->whereIn($this->table . '.' . $column, $values, $boolean, $not);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an "or where" clause for a pivot table column.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $operator
|
||||
* @param mixed $value
|
||||
* @param string $column
|
||||
* @param string $operator
|
||||
* @return $this
|
||||
*/
|
||||
public function orWherePivot($column, $operator = null, $value = null)
|
||||
@ -326,8 +313,7 @@ class BelongsToMany extends Relation
|
||||
*
|
||||
* In addition, new pivot records will receive this value.
|
||||
*
|
||||
* @param string|array $column
|
||||
* @param mixed $value
|
||||
* @param string|array $column
|
||||
* @return $this
|
||||
*/
|
||||
public function withPivotValue($column, $value = null)
|
||||
@ -352,8 +338,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Set an "or where in" clause for a pivot table column.
|
||||
*
|
||||
* @param string $column
|
||||
* @param mixed $values
|
||||
* @param string $column
|
||||
* @return $this
|
||||
*/
|
||||
public function orWherePivotIn($column, $values)
|
||||
@ -364,8 +349,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Find a related model by its primary key or return new instance of the related model.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Utils\Collection|\Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function findOrNew($id, $columns = ['*'])
|
||||
@ -380,7 +364,6 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Get the first related model record matching the attributes or instantiate it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function firstOrNew(array $attributes)
|
||||
@ -395,9 +378,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Get the first related record matching the attributes or create it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $joining
|
||||
* @param bool $touch
|
||||
* @param bool $touch
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function firstOrCreate(array $attributes, array $joining = [], $touch = true)
|
||||
@ -412,10 +393,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Create or update a related record matching the attributes, and fill it with values.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @param array $joining
|
||||
* @param bool $touch
|
||||
* @param bool $touch
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function updateOrCreate(array $attributes, array $values = [], array $joining = [], $touch = true)
|
||||
@ -434,8 +412,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Find a related model by its primary key.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection|null
|
||||
*/
|
||||
public function find($id, $columns = ['*'])
|
||||
@ -450,8 +427,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Find multiple related models by their primary keys.
|
||||
*
|
||||
* @param mixed $ids
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function findMany($ids, $columns = ['*'])
|
||||
@ -465,8 +441,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Find a related model by its primary key or throw an exception.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection
|
||||
*
|
||||
* @throws \Hyperf\Database\Model\ModelNotFoundException
|
||||
@ -483,14 +458,13 @@ class BelongsToMany extends Relation
|
||||
return $result;
|
||||
}
|
||||
|
||||
throw (new ModelNotFoundException)->setModel(get_class($this->related), $id);
|
||||
throw (new ModelNotFoundException())->setModel(get_class($this->related), $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query and get the first result.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return mixed
|
||||
* @param array $columns
|
||||
*/
|
||||
public function first($columns = ['*'])
|
||||
{
|
||||
@ -502,7 +476,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Execute the query and get the first result or throw an exception.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|static
|
||||
*
|
||||
* @throws \Hyperf\Database\Model\ModelNotFoundException
|
||||
@ -513,13 +487,11 @@ class BelongsToMany extends Relation
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw (new ModelNotFoundException)->setModel(get_class($this->related));
|
||||
throw (new ModelNotFoundException())->setModel(get_class($this->related));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
@ -529,7 +501,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Execute the query as a "select" statement.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function get($columns = ['*'])
|
||||
@ -560,10 +532,10 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Get a paginator for the "select" statement.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @return \Hyperf\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
|
||||
@ -578,10 +550,10 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Paginate the given query into a simple paginator.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @return \Hyperf\Contracts\Pagination\Paginator
|
||||
*/
|
||||
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
|
||||
@ -597,7 +569,6 @@ class BelongsToMany extends Relation
|
||||
* Chunk the results of the query.
|
||||
*
|
||||
* @param int $count
|
||||
* @param callable $callback
|
||||
* @return bool
|
||||
*/
|
||||
public function chunk($count, callable $callback)
|
||||
@ -614,7 +585,6 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Execute a callback over each item while chunking.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param int $count
|
||||
* @return bool
|
||||
*/
|
||||
@ -622,7 +592,7 @@ class BelongsToMany extends Relation
|
||||
{
|
||||
return $this->chunk($count, function ($results) use ($callback) {
|
||||
foreach ($results as $key => $value) {
|
||||
if ($callback($value, $key) === false) {
|
||||
if (false === $callback($value, $key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -631,8 +601,6 @@ class BelongsToMany extends Relation
|
||||
|
||||
/**
|
||||
* If we're touching the parent model, touch.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function touchIfTouching()
|
||||
{
|
||||
@ -649,8 +617,6 @@ class BelongsToMany extends Relation
|
||||
* Touch all of the related models for the relationship.
|
||||
*
|
||||
* E.g.: Touch all roles associated with this user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
@ -681,9 +647,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Save a new model and attach it to the parent model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @param array $pivotAttributes
|
||||
* @param bool $touch
|
||||
* @param bool $touch
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function save(Model $model, array $pivotAttributes = [], $touch = true)
|
||||
@ -698,8 +662,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Save an array of new models and attach them to the parent model.
|
||||
*
|
||||
* @param \Hyperf\Utils\Collection|array $models
|
||||
* @param array $pivotAttributes
|
||||
* @param \Hyperf\Utils\Collection|array $models
|
||||
* @return array
|
||||
*/
|
||||
public function saveMany($models, array $pivotAttributes = [])
|
||||
@ -716,9 +679,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Create a new instance of the related model.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $joining
|
||||
* @param bool $touch
|
||||
* @param bool $touch
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function create(array $attributes = [], array $joining = [], $touch = true)
|
||||
@ -738,8 +699,6 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Create an array of new instances of the related models.
|
||||
*
|
||||
* @param array $records
|
||||
* @param array $joinings
|
||||
* @return array
|
||||
*/
|
||||
public function createMany(array $records, array $joinings = [])
|
||||
@ -758,9 +717,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Add the constraints for a relationship query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
@ -777,16 +734,14 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Add the constraints for a relationship query on the same table.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQueryForSelfJoin(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
{
|
||||
$query->select($columns);
|
||||
|
||||
$query->from($this->related->getTable().' as '.$hash = $this->getRelationCountHash());
|
||||
$query->from($this->related->getTable() . ' as ' . $hash = $this->getRelationCountHash());
|
||||
|
||||
$this->related->setTable($hash);
|
||||
|
||||
@ -812,14 +767,12 @@ class BelongsToMany extends Relation
|
||||
*/
|
||||
public function getRelationCountHash()
|
||||
{
|
||||
return 'laravel_reserved_'.static::$selfJoinCount++;
|
||||
return 'laravel_reserved_' . static::$selfJoinCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify that the pivot table has creation and update timestamps.
|
||||
*
|
||||
* @param mixed $createdAt
|
||||
* @param mixed $updatedAt
|
||||
* @return $this
|
||||
*/
|
||||
public function withTimestamps($createdAt = null, $updatedAt = null)
|
||||
@ -869,7 +822,7 @@ class BelongsToMany extends Relation
|
||||
*/
|
||||
public function getQualifiedForeignPivotKeyName()
|
||||
{
|
||||
return $this->table.'.'.$this->foreignPivotKey;
|
||||
return $this->table . '.' . $this->foreignPivotKey;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -889,7 +842,7 @@ class BelongsToMany extends Relation
|
||||
*/
|
||||
public function getQualifiedRelatedPivotKeyName()
|
||||
{
|
||||
return $this->table.'.'.$this->relatedPivotKey;
|
||||
return $this->table . '.' . $this->relatedPivotKey;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -955,7 +908,7 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Set the join clause for the relation query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder|null $query
|
||||
* @param \Hyperf\Database\Model\Builder|null $query
|
||||
* @return $this
|
||||
*/
|
||||
protected function performJoin($query = null)
|
||||
@ -967,7 +920,7 @@ class BelongsToMany extends Relation
|
||||
// model instance. Then we can set the "where" for the parent models.
|
||||
$baseTable = $this->related->getTable();
|
||||
|
||||
$key = $baseTable.'.'.$this->relatedKey;
|
||||
$key = $baseTable . '.' . $this->relatedKey;
|
||||
|
||||
$query->join($this->table, $key, '=', $this->getQualifiedRelatedPivotKeyName());
|
||||
|
||||
@ -993,7 +946,6 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Build model dictionary keyed by the relation's foreign key.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @return array
|
||||
*/
|
||||
protected function buildDictionary(Collection $results)
|
||||
@ -1013,13 +965,12 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Get the select columns for the relation query.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return array
|
||||
*/
|
||||
protected function shouldSelect(array $columns = ['*'])
|
||||
{
|
||||
if ($columns == ['*']) {
|
||||
$columns = [$this->related->getTable().'.*'];
|
||||
$columns = [$this->related->getTable() . '.*'];
|
||||
}
|
||||
|
||||
return array_merge($columns, $this->aliasedPivotColumns());
|
||||
@ -1037,15 +988,12 @@ class BelongsToMany extends Relation
|
||||
$defaults = [$this->foreignPivotKey, $this->relatedPivotKey];
|
||||
|
||||
return collect(array_merge($defaults, $this->pivotColumns))->map(function ($column) {
|
||||
return $this->table.'.'.$column.' as pivot_'.$column;
|
||||
return $this->table . '.' . $column . ' as pivot_' . $column;
|
||||
})->unique()->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the pivot table relationship on the models.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
protected function hydratePivotRelation(array $models)
|
||||
{
|
||||
@ -1062,7 +1010,6 @@ class BelongsToMany extends Relation
|
||||
/**
|
||||
* Get the pivot attributes from a model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @return array
|
||||
*/
|
||||
protected function migratePivotAttributes(Model $model)
|
||||
@ -1073,7 +1020,7 @@ class BelongsToMany extends Relation
|
||||
// To get the pivots attributes we will just take any of the attributes which
|
||||
// begin with "pivot_" and add those to this arrays, as well as unsetting
|
||||
// them from the parent's models since they exist in a different table.
|
||||
if (strpos($key, 'pivot_') === 0) {
|
||||
if (0 === strpos($key, 'pivot_')) {
|
||||
$values[substr($key, 6)] = $value;
|
||||
|
||||
unset($model->$key);
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -41,15 +42,14 @@ trait AsPivot
|
||||
/**
|
||||
* Create a new pivot model instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param array $attributes
|
||||
* @param string $table
|
||||
* @param bool $exists
|
||||
* @param array $attributes
|
||||
* @param string $table
|
||||
* @param bool $exists
|
||||
* @return static
|
||||
*/
|
||||
public static function fromAttributes(Model $parent, $attributes, $table, $exists = false)
|
||||
{
|
||||
$instance = new static;
|
||||
$instance = new static();
|
||||
|
||||
// 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
|
||||
@ -74,10 +74,9 @@ trait AsPivot
|
||||
/**
|
||||
* Create a new pivot model from raw values returned from a query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param array $attributes
|
||||
* @param string $table
|
||||
* @param bool $exists
|
||||
* @param array $attributes
|
||||
* @param string $table
|
||||
* @param bool $exists
|
||||
* @return static
|
||||
*/
|
||||
public static function fromRawAttributes(Model $parent, $attributes, $table, $exists = false)
|
||||
@ -156,8 +155,8 @@ trait AsPivot
|
||||
/**
|
||||
* Set the key names for the pivot model instance.
|
||||
*
|
||||
* @param string $foreignKey
|
||||
* @param string $relatedKey
|
||||
* @param string $foreignKey
|
||||
* @param string $relatedKey
|
||||
* @return $this
|
||||
*/
|
||||
public function setPivotKeys($foreignKey, $relatedKey)
|
||||
@ -205,8 +204,6 @@ trait AsPivot
|
||||
|
||||
/**
|
||||
* Get the queueable identity for the entity.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getQueueableId()
|
||||
{
|
||||
@ -226,7 +223,7 @@ trait AsPivot
|
||||
/**
|
||||
* Get a new query to restore one or more models by their queueable IDs.
|
||||
*
|
||||
* @param array<int> $ids
|
||||
* @param array<int> $ids
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function newQueryForRestoration($ids)
|
||||
@ -249,7 +246,6 @@ trait AsPivot
|
||||
/**
|
||||
* Set the keys for a save update query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
protected function setKeysForSaveQuery(Builder $query)
|
||||
@ -285,7 +281,7 @@ trait AsPivot
|
||||
/**
|
||||
* Get a new query to restore multiple models by their queueable IDs.
|
||||
*
|
||||
* @param array|int $ids
|
||||
* @param array|int $ids
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
protected function newQueryForCollectionRestoration(array $ids)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -22,8 +23,7 @@ trait InteractsWithPivotTable
|
||||
*
|
||||
* Each existing model is detached, and non existing ones are attached.
|
||||
*
|
||||
* @param mixed $ids
|
||||
* @param bool $touch
|
||||
* @param bool $touch
|
||||
* @return array
|
||||
*/
|
||||
public function toggle($ids, $touch = true)
|
||||
@ -73,7 +73,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Sync the intermediate tables with a list of IDs without detaching.
|
||||
*
|
||||
* @param \Hyperf\Utils\Collection|\Hyperf\Database\Model\Model|array $ids
|
||||
* @param \Hyperf\Utils\Collection|\Hyperf\Database\Model\Model|array $ids
|
||||
* @return array
|
||||
*/
|
||||
public function syncWithoutDetaching($ids)
|
||||
@ -84,8 +84,8 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Sync the intermediate tables with a list of IDs or collection of models.
|
||||
*
|
||||
* @param \Hyperf\Utils\Collection|\Hyperf\Database\Model\Model|array $ids
|
||||
* @param bool $detaching
|
||||
* @param \Hyperf\Utils\Collection|\Hyperf\Database\Model\Model|array $ids
|
||||
* @param bool $detaching
|
||||
* @return array
|
||||
*/
|
||||
public function sync($ids, $detaching = true)
|
||||
@ -136,9 +136,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Update an existing pivot record on the table.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $attributes
|
||||
* @param bool $touch
|
||||
* @param bool $touch
|
||||
* @return int
|
||||
*/
|
||||
public function updateExistingPivot($id, array $attributes, $touch = true)
|
||||
@ -161,10 +159,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Attach a model to the parent.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $attributes
|
||||
* @param bool $touch
|
||||
* @return void
|
||||
* @param bool $touch
|
||||
*/
|
||||
public function attach($id, array $attributes = [], $touch = true)
|
||||
{
|
||||
@ -184,8 +179,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Detach models from the relationship.
|
||||
*
|
||||
* @param mixed $ids
|
||||
* @param bool $touch
|
||||
* @param bool $touch
|
||||
* @return int
|
||||
*/
|
||||
public function detach($ids = null, $touch = true)
|
||||
@ -220,8 +214,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Create a new pivot model instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param bool $exists
|
||||
* @param bool $exists
|
||||
* @return \Hyperf\Database\Model\Relations\Pivot
|
||||
*/
|
||||
public function newPivot(array $attributes = [], $exists = false)
|
||||
@ -240,7 +233,6 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Create a new existing pivot model instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Relations\Pivot
|
||||
*/
|
||||
public function newExistingPivot(array $attributes = [])
|
||||
@ -261,7 +253,6 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Get a new pivot statement for a given "other" ID.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return \Hyperf\Database\Query\Builder
|
||||
*/
|
||||
public function newPivotStatementForId($id)
|
||||
@ -272,7 +263,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Set the columns on the pivot table to retrieve.
|
||||
*
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return $this
|
||||
*/
|
||||
public function withPivot($columns)
|
||||
@ -288,7 +279,6 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Format the sync / toggle record list so that it is keyed by ID.
|
||||
*
|
||||
* @param array $records
|
||||
* @return array
|
||||
*/
|
||||
protected function formatRecordsList(array $records)
|
||||
@ -305,9 +295,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Attach all of the records that aren't in the given current records.
|
||||
*
|
||||
* @param array $records
|
||||
* @param array $current
|
||||
* @param bool $touch
|
||||
* @param bool $touch
|
||||
* @return array
|
||||
*/
|
||||
protected function attachNew(array $records, array $current, $touch = true)
|
||||
@ -339,8 +327,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Create an array of records to insert into the pivot table.
|
||||
*
|
||||
* @param array $ids
|
||||
* @param array $attributes
|
||||
* @param array $ids
|
||||
* @return array
|
||||
*/
|
||||
protected function formatAttachRecords($ids, array $attributes)
|
||||
@ -368,10 +355,9 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Create a full attachment record payload.
|
||||
*
|
||||
* @param int $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param bool $hasTimestamps
|
||||
* @param int $key
|
||||
* @param array $attributes
|
||||
* @param bool $hasTimestamps
|
||||
* @return array
|
||||
*/
|
||||
protected function formatAttachRecord($key, $value, $attributes, $hasTimestamps)
|
||||
@ -387,9 +373,6 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Get the attach record ID and extra attributes.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return array
|
||||
*/
|
||||
protected function extractAttachIdAndAttributes($key, $value, array $attributes)
|
||||
@ -429,8 +412,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Set the creation and update timestamps on an attach record.
|
||||
*
|
||||
* @param array $record
|
||||
* @param bool $exists
|
||||
* @param bool $exists
|
||||
* @return array
|
||||
*/
|
||||
protected function addTimestampsToAttachment(array $record, $exists = false)
|
||||
@ -438,7 +420,7 @@ trait InteractsWithPivotTable
|
||||
$fresh = $this->parent->freshTimestamp();
|
||||
|
||||
if ($this->using) {
|
||||
$pivotModel = new $this->using;
|
||||
$pivotModel = new $this->using();
|
||||
|
||||
$fresh = $fresh->format($pivotModel->getDateFormat());
|
||||
}
|
||||
@ -457,7 +439,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Determine whether the given column is defined as a pivot column.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasPivotColumn($column)
|
||||
@ -488,7 +470,6 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Get all of the IDs from the given mixed value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
protected function parseIds($value)
|
||||
@ -510,9 +491,6 @@ trait InteractsWithPivotTable
|
||||
|
||||
/**
|
||||
* Get the ID from the given mixed value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
protected function parseId($value)
|
||||
{
|
||||
@ -522,7 +500,6 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Cast the given keys to integers if they are numeric and string otherwise.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return array
|
||||
*/
|
||||
protected function castKeys(array $keys)
|
||||
@ -534,9 +511,6 @@ trait InteractsWithPivotTable
|
||||
|
||||
/**
|
||||
* Cast the given key to convert to primary key type.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function castKey($key)
|
||||
{
|
||||
@ -562,9 +536,7 @@ trait InteractsWithPivotTable
|
||||
/**
|
||||
* Converts a given value to a given type value.
|
||||
*
|
||||
* @param string $type
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
* @param string $type
|
||||
*/
|
||||
protected function getTypeSwapValue($type, $value)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -27,7 +28,7 @@ trait SupportsDefaultModels
|
||||
/**
|
||||
* Return a new model instance in case the relationship does not exist.
|
||||
*
|
||||
* @param \Closure|array|bool $callback
|
||||
* @param \Closure|array|bool $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function withDefault($callback = true)
|
||||
@ -40,7 +41,6 @@ trait SupportsDefaultModels
|
||||
/**
|
||||
* Make a new related instance for the given model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
abstract protected function newRelatedInstanceFor(Model $parent);
|
||||
@ -48,7 +48,6 @@ trait SupportsDefaultModels
|
||||
/**
|
||||
* Get the default value for this relation.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @return \Hyperf\Database\Model\Model|null
|
||||
*/
|
||||
protected function getDefaultFor(Model $parent)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -17,8 +18,6 @@ class HasMany extends HasOneOrMany
|
||||
{
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
@ -28,8 +27,7 @@ class HasMany extends HasOneOrMany
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
@ -44,9 +42,7 @@ class HasMany extends HasOneOrMany
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -71,14 +72,10 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Create a new has many through relationship instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $farParent
|
||||
* @param \Hyperf\Database\Model\Model $throughParent
|
||||
* @param string $firstKey
|
||||
* @param string $secondKey
|
||||
* @param string $localKey
|
||||
* @param string $secondLocalKey
|
||||
* @return void
|
||||
* @param string $firstKey
|
||||
* @param string $secondKey
|
||||
* @param string $localKey
|
||||
* @param string $secondLocalKey
|
||||
*/
|
||||
public function __construct(Builder $query, Model $farParent, Model $throughParent, $firstKey, $secondKey, $localKey, $secondLocalKey)
|
||||
{
|
||||
@ -94,8 +91,6 @@ class HasManyThrough extends Relation
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
@ -130,9 +125,6 @@ class HasManyThrough extends Relation
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
@ -147,8 +139,7 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
@ -163,9 +154,7 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
@ -190,7 +179,6 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Get the first related model record matching the attributes or instantiate it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function firstOrNew(array $attributes)
|
||||
@ -205,8 +193,6 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Create or update a related record matching the attributes, and fill it with values.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function updateOrCreate(array $attributes, array $values = [])
|
||||
@ -221,8 +207,7 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Execute the query and get the first related model.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return mixed
|
||||
* @param array $columns
|
||||
*/
|
||||
public function first($columns = ['*'])
|
||||
{
|
||||
@ -234,7 +219,7 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Execute the query and get the first result or throw an exception.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|static
|
||||
*
|
||||
* @throws \Hyperf\Database\Model\ModelNotFoundException
|
||||
@ -245,14 +230,13 @@ class HasManyThrough extends Relation
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw (new ModelNotFoundException)->setModel(get_class($this->related));
|
||||
throw (new ModelNotFoundException())->setModel(get_class($this->related));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a related model by its primary key.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection|null
|
||||
*/
|
||||
public function find($id, $columns = ['*'])
|
||||
@ -271,8 +255,7 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Find multiple related models by their primary keys.
|
||||
*
|
||||
* @param mixed $ids
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function findMany($ids, $columns = ['*'])
|
||||
@ -290,8 +273,7 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Find a related model by its primary key or throw an exception.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Model|\Hyperf\Database\Model\Collection
|
||||
*
|
||||
* @throws \Hyperf\Database\Model\ModelNotFoundException
|
||||
@ -308,13 +290,11 @@ class HasManyThrough extends Relation
|
||||
return $result;
|
||||
}
|
||||
|
||||
throw (new ModelNotFoundException)->setModel(get_class($this->related), $id);
|
||||
throw (new ModelNotFoundException())->setModel(get_class($this->related), $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
@ -324,7 +304,7 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Execute the query as a "select" statement.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function get($columns = ['*'])
|
||||
@ -346,10 +326,10 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Get a paginator for the "select" statement.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int $page
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int $page
|
||||
* @return \Hyperf\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
|
||||
@ -362,10 +342,10 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Paginate the given query into a simple paginator.
|
||||
*
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @param int $perPage
|
||||
* @param array $columns
|
||||
* @param string $pageName
|
||||
* @param int|null $page
|
||||
* @return \Hyperf\Contracts\Pagination\Paginator
|
||||
*/
|
||||
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
|
||||
@ -379,7 +359,6 @@ class HasManyThrough extends Relation
|
||||
* Chunk the results of the query.
|
||||
*
|
||||
* @param int $count
|
||||
* @param callable $callback
|
||||
* @return bool
|
||||
*/
|
||||
public function chunk($count, callable $callback)
|
||||
@ -400,7 +379,6 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Execute a callback over each item while chunking.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param int $count
|
||||
* @return bool
|
||||
*/
|
||||
@ -408,7 +386,7 @@ class HasManyThrough extends Relation
|
||||
{
|
||||
return $this->chunk($count, function ($results) use ($callback) {
|
||||
foreach ($results as $key => $value) {
|
||||
if ($callback($value, $key) === false) {
|
||||
if (false === $callback($value, $key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -418,9 +396,7 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Add the constraints for a relationship query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
@ -445,16 +421,14 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Add the constraints for a relationship query on the same table.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
{
|
||||
$query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash());
|
||||
$query->from($query->getModel()->getTable() . ' as ' . $hash = $this->getRelationCountHash());
|
||||
|
||||
$query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $hash.'.'.$this->secondKey);
|
||||
$query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $hash . '.' . $this->secondKey);
|
||||
|
||||
if ($this->throughParentSoftDeletes()) {
|
||||
$query->whereNull($this->throughParent->getQualifiedDeletedAtColumn());
|
||||
@ -463,7 +437,7 @@ class HasManyThrough extends Relation
|
||||
$query->getModel()->setTable($hash);
|
||||
|
||||
return $query->select($columns)->whereColumn(
|
||||
$parentQuery->getQuery()->from.'.'.$this->localKey,
|
||||
$parentQuery->getQuery()->from . '.' . $this->localKey,
|
||||
'=',
|
||||
$this->getQualifiedFirstKeyName()
|
||||
);
|
||||
@ -472,25 +446,23 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Add the constraints for a relationship query on the same table as the through parent.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQueryForThroughSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
{
|
||||
$table = $this->throughParent->getTable().' as '.$hash = $this->getRelationCountHash();
|
||||
$table = $this->throughParent->getTable() . ' as ' . $hash = $this->getRelationCountHash();
|
||||
|
||||
$query->join($table, $hash.'.'.$this->secondLocalKey, '=', $this->getQualifiedFarKeyName());
|
||||
$query->join($table, $hash . '.' . $this->secondLocalKey, '=', $this->getQualifiedFarKeyName());
|
||||
|
||||
if ($this->throughParentSoftDeletes()) {
|
||||
$query->whereNull($hash.'.'.$this->throughParent->getDeletedAtColumn());
|
||||
$query->whereNull($hash . '.' . $this->throughParent->getDeletedAtColumn());
|
||||
}
|
||||
|
||||
return $query->select($columns)->whereColumn(
|
||||
$parentQuery->getQuery()->from.'.'.$this->localKey,
|
||||
$parentQuery->getQuery()->from . '.' . $this->localKey,
|
||||
'=',
|
||||
$hash.'.'.$this->firstKey
|
||||
$hash . '.' . $this->firstKey
|
||||
);
|
||||
}
|
||||
|
||||
@ -501,7 +473,7 @@ class HasManyThrough extends Relation
|
||||
*/
|
||||
public function getRelationCountHash()
|
||||
{
|
||||
return 'laravel_reserved_'.static::$selfJoinCount++;
|
||||
return 'laravel_reserved_' . static::$selfJoinCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -586,9 +558,6 @@ class HasManyThrough extends Relation
|
||||
|
||||
/**
|
||||
* Set the join clause on the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder|null $query
|
||||
* @return void
|
||||
*/
|
||||
protected function performJoin(Builder $query = null)
|
||||
{
|
||||
@ -606,7 +575,6 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Build model dictionary keyed by the relation's foreign key.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @return array
|
||||
*/
|
||||
protected function buildDictionary(Collection $results)
|
||||
@ -626,22 +594,21 @@ class HasManyThrough extends Relation
|
||||
/**
|
||||
* Set the select clause for the relation query.
|
||||
*
|
||||
* @param array $columns
|
||||
* @return array
|
||||
*/
|
||||
protected function shouldSelect(array $columns = ['*'])
|
||||
{
|
||||
if ($columns == ['*']) {
|
||||
$columns = [$this->related->getTable().'.*'];
|
||||
$columns = [$this->related->getTable() . '.*'];
|
||||
}
|
||||
|
||||
return array_merge($columns, [$this->getQualifiedFirstKeyName().' as laravel_through_key']);
|
||||
return array_merge($columns, [$this->getQualifiedFirstKeyName() . ' as laravel_through_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the query builder for query execution.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
protected function prepareQueryBuilder($columns = ['*'])
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -21,8 +22,6 @@ class HasOne extends HasOneOrMany
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
@ -32,8 +31,7 @@ class HasOne extends HasOneOrMany
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
@ -48,9 +46,7 @@ class HasOne extends HasOneOrMany
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
@ -61,7 +57,6 @@ class HasOne extends HasOneOrMany
|
||||
/**
|
||||
* Make a new related instance for the given model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function newRelatedInstanceFor(Model $parent)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -41,11 +42,8 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Create a new has one or many relationship instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
* @return void
|
||||
* @param string $foreignKey
|
||||
* @param string $localKey
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $foreignKey, $localKey)
|
||||
{
|
||||
@ -58,7 +56,6 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Create and return an un-saved instance of the related model.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function make(array $attributes = [])
|
||||
@ -70,8 +67,6 @@ abstract class HasOneOrMany extends Relation
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
@ -84,9 +79,6 @@ abstract class HasOneOrMany extends Relation
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
@ -101,9 +93,7 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Match the eagerly loaded results to their single parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function matchOne(array $models, Collection $results, $relation)
|
||||
@ -114,9 +104,7 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Match the eagerly loaded results to their many parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function matchMany(array $models, Collection $results, $relation)
|
||||
@ -127,8 +115,7 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Find a model by its primary key or return new instance of the related model.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Utils\Collection|\Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function findOrNew($id, $columns = ['*'])
|
||||
@ -145,8 +132,6 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Get the first related model record matching the attributes or instantiate it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function firstOrNew(array $attributes, array $values = [])
|
||||
@ -163,8 +148,6 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Get the first related record matching the attributes or create it.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function firstOrCreate(array $attributes, array $values = [])
|
||||
@ -179,8 +162,6 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Create or update a related record matching the attributes, and fill it with values.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function updateOrCreate(array $attributes, array $values = [])
|
||||
@ -195,7 +176,6 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Attach a model instance to the parent model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @return \Hyperf\Database\Model\Model|false
|
||||
*/
|
||||
public function save(Model $model)
|
||||
@ -208,7 +188,7 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Attach a collection of models to the parent instance.
|
||||
*
|
||||
* @param \Traversable|array $models
|
||||
* @param \Traversable|array $models
|
||||
* @return \Traversable|array
|
||||
*/
|
||||
public function saveMany($models)
|
||||
@ -223,7 +203,6 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Create a new instance of the related model.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function create(array $attributes = [])
|
||||
@ -238,7 +217,6 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Create a Collection of new instances of the related model.
|
||||
*
|
||||
* @param array $records
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function createMany(array $records)
|
||||
@ -255,7 +233,6 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Perform an update on all the related models.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return int
|
||||
*/
|
||||
public function update(array $attributes)
|
||||
@ -270,9 +247,7 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Add the constraints for a relationship query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
@ -287,21 +262,19 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Add the constraints for a relationship query on the same table.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
{
|
||||
$query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash());
|
||||
$query->from($query->getModel()->getTable() . ' as ' . $hash = $this->getRelationCountHash());
|
||||
|
||||
$query->getModel()->setTable($hash);
|
||||
|
||||
return $query->select($columns)->whereColumn(
|
||||
$this->getQualifiedParentKeyName(),
|
||||
'=',
|
||||
$hash.'.'.$this->getForeignKeyName()
|
||||
$hash . '.' . $this->getForeignKeyName()
|
||||
);
|
||||
}
|
||||
|
||||
@ -312,7 +285,7 @@ abstract class HasOneOrMany extends Relation
|
||||
*/
|
||||
public function getRelationCountHash()
|
||||
{
|
||||
return 'laravel_reserved_'.static::$selfJoinCount++;
|
||||
return 'laravel_reserved_' . static::$selfJoinCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,8 +300,6 @@ abstract class HasOneOrMany extends Relation
|
||||
|
||||
/**
|
||||
* Get the key value of the parent's local key.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParentKey()
|
||||
{
|
||||
@ -380,10 +351,8 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Match the eagerly loaded results to their many parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $type
|
||||
* @param string $relation
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function matchOneOrMany(array $models, Collection $results, $relation, $type)
|
||||
@ -408,22 +377,19 @@ abstract class HasOneOrMany extends Relation
|
||||
/**
|
||||
* Get the value of a relationship by one or many type.
|
||||
*
|
||||
* @param array $dictionary
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
*/
|
||||
protected function getRelationValue(array $dictionary, $key, $type)
|
||||
{
|
||||
$value = $dictionary[$key];
|
||||
|
||||
return $type === 'one' ? reset($value) : $this->related->newCollection($value);
|
||||
return 'one' === $type ? reset($value) : $this->related->newCollection($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build model dictionary keyed by the relation's foreign key.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @return array
|
||||
*/
|
||||
protected function buildDictionary(Collection $results)
|
||||
@ -437,9 +403,6 @@ abstract class HasOneOrMany extends Relation
|
||||
|
||||
/**
|
||||
* Set the foreign ID for creating a related model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @return void
|
||||
*/
|
||||
protected function setForeignAttributesForCreate(Model $model)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -21,8 +22,6 @@ class HasOneThrough extends HasManyThrough
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
@ -32,8 +31,7 @@ class HasOneThrough extends HasManyThrough
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
@ -48,9 +46,7 @@ class HasOneThrough extends HasManyThrough
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
@ -76,7 +72,6 @@ class HasOneThrough extends HasManyThrough
|
||||
/**
|
||||
* Make a new related instance for the given model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function newRelatedInstanceFor(Model $parent)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -17,8 +18,6 @@ class MorphMany extends MorphOneOrMany
|
||||
{
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
@ -28,8 +27,7 @@ class MorphMany extends MorphOneOrMany
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
@ -44,9 +42,7 @@ class MorphMany extends MorphOneOrMany
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -21,8 +22,6 @@ class MorphOne extends MorphOneOrMany
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
@ -32,8 +31,7 @@ class MorphOne extends MorphOneOrMany
|
||||
/**
|
||||
* Initialize the relation on a set of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function initRelation(array $models, $relation)
|
||||
@ -48,9 +46,7 @@ class MorphOne extends MorphOneOrMany
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
@ -61,7 +57,6 @@ class MorphOne extends MorphOneOrMany
|
||||
/**
|
||||
* Make a new related instance for the given model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function newRelatedInstanceFor(Model $parent)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -33,12 +34,9 @@ abstract class MorphOneOrMany extends HasOneOrMany
|
||||
/**
|
||||
* Create a new morph one or many relationship instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
* @return void
|
||||
* @param string $type
|
||||
* @param string $id
|
||||
* @param string $localKey
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $type, $id, $localKey)
|
||||
{
|
||||
@ -51,8 +49,6 @@ abstract class MorphOneOrMany extends HasOneOrMany
|
||||
|
||||
/**
|
||||
* Set the base constraints on the relation query.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addConstraints()
|
||||
{
|
||||
@ -65,9 +61,6 @@ abstract class MorphOneOrMany extends HasOneOrMany
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
@ -79,9 +72,7 @@ abstract class MorphOneOrMany extends HasOneOrMany
|
||||
/**
|
||||
* Get the relationship query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
@ -124,9 +115,6 @@ abstract class MorphOneOrMany extends HasOneOrMany
|
||||
|
||||
/**
|
||||
* Set the foreign ID and type for creating a related model.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @return void
|
||||
*/
|
||||
protected function setForeignAttributesForCreate(Model $model)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -51,7 +52,7 @@ class MorphPivot extends Pivot
|
||||
/**
|
||||
* Set the morph type for the pivot.
|
||||
*
|
||||
* @param string $morphType
|
||||
* @param string $morphType
|
||||
* @return $this
|
||||
*/
|
||||
public function setMorphType($morphType)
|
||||
@ -64,7 +65,7 @@ class MorphPivot extends Pivot
|
||||
/**
|
||||
* Set the morph class for the pivot.
|
||||
*
|
||||
* @param string $morphClass
|
||||
* @param string $morphClass
|
||||
* @return \Hyperf\Database\Model\Relations\MorphPivot
|
||||
*/
|
||||
public function setMorphClass($morphClass)
|
||||
@ -76,8 +77,6 @@ class MorphPivot extends Pivot
|
||||
|
||||
/**
|
||||
* Get the queueable identity for the entity.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getQueueableId()
|
||||
{
|
||||
@ -99,7 +98,7 @@ class MorphPivot extends Pivot
|
||||
/**
|
||||
* Get a new query to restore one or more models by their queueable IDs.
|
||||
*
|
||||
* @param array|int $ids
|
||||
* @param array|int $ids
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function newQueryForRestoration($ids)
|
||||
@ -123,7 +122,6 @@ class MorphPivot extends Pivot
|
||||
/**
|
||||
* Set the keys for a save update query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
protected function setKeysForSaveQuery(Builder $query)
|
||||
@ -136,7 +134,7 @@ class MorphPivot extends Pivot
|
||||
/**
|
||||
* Get a new query to restore multiple models by their queueable IDs.
|
||||
*
|
||||
* @param array<int> $ids
|
||||
* @param array<int> $ids
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
protected function newQueryForCollectionRestoration(array $ids)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -49,13 +50,10 @@ class MorphTo extends BelongsTo
|
||||
/**
|
||||
* Create a new morph to relationship instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $type
|
||||
* @param string $relation
|
||||
* @return void
|
||||
* @param string $foreignKey
|
||||
* @param string $ownerKey
|
||||
* @param string $type
|
||||
* @param string $relation
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent, $foreignKey, $ownerKey, $type, $relation)
|
||||
{
|
||||
@ -67,9 +65,8 @@ class MorphTo extends BelongsTo
|
||||
/**
|
||||
* Handle dynamic method calls to the relationship.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
@ -95,9 +92,6 @@ class MorphTo extends BelongsTo
|
||||
|
||||
/**
|
||||
* Set the constraints for an eager load of the relation.
|
||||
*
|
||||
* @param array $models
|
||||
* @return void
|
||||
*/
|
||||
public function addEagerConstraints(array $models)
|
||||
{
|
||||
@ -106,8 +100,6 @@ class MorphTo extends BelongsTo
|
||||
|
||||
/**
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
@ -118,8 +110,6 @@ class MorphTo extends BelongsTo
|
||||
* Get the results of the relationship.
|
||||
*
|
||||
* Called via eager load method of Model query builder.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEager()
|
||||
{
|
||||
@ -133,22 +123,20 @@ class MorphTo extends BelongsTo
|
||||
/**
|
||||
* Create a new model instance by type.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function createModelByType($type)
|
||||
{
|
||||
$class = Model::getActualClassNameForMorph($type);
|
||||
|
||||
return new $class;
|
||||
return new $class();
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
public function match(array $models, Collection $results, $relation)
|
||||
@ -159,7 +147,7 @@ class MorphTo extends BelongsTo
|
||||
/**
|
||||
* Associate the model instance to the given parent.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @return \Hyperf\Database\Model\Model
|
||||
*/
|
||||
public function associate($model)
|
||||
@ -193,8 +181,6 @@ class MorphTo extends BelongsTo
|
||||
|
||||
/**
|
||||
* Touch all of the related models for the relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
@ -225,9 +211,6 @@ class MorphTo extends BelongsTo
|
||||
|
||||
/**
|
||||
* Build a dictionary with the models.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Collection $models
|
||||
* @return void
|
||||
*/
|
||||
protected function buildDictionary(Collection $models)
|
||||
{
|
||||
@ -241,7 +224,7 @@ class MorphTo extends BelongsTo
|
||||
/**
|
||||
* Get all of the relation results for a type.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
protected function getResultsByType($type)
|
||||
@ -255,7 +238,7 @@ class MorphTo extends BelongsTo
|
||||
->with($this->getQuery()->getEagerLoads());
|
||||
|
||||
return $query->whereIn(
|
||||
$instance->getTable().'.'.$ownerKey,
|
||||
$instance->getTable() . '.' . $ownerKey,
|
||||
$this->gatherKeysByType($type)
|
||||
)->get();
|
||||
}
|
||||
@ -263,7 +246,7 @@ class MorphTo extends BelongsTo
|
||||
/**
|
||||
* Gather all of the foreign keys for a given type.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function gatherKeysByType($type)
|
||||
@ -276,9 +259,7 @@ class MorphTo extends BelongsTo
|
||||
/**
|
||||
* Match the results for a given type to their parents.
|
||||
*
|
||||
* @param string $type
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @return void
|
||||
* @param string $type
|
||||
*/
|
||||
protected function matchToMorphParents($type, Collection $results)
|
||||
{
|
||||
@ -296,7 +277,6 @@ class MorphTo extends BelongsTo
|
||||
/**
|
||||
* Replay stored macro calls on the actual related instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
protected function replayMacros(Builder $query)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -43,17 +44,14 @@ class MorphToMany extends BelongsToMany
|
||||
/**
|
||||
* Create a new morph to many relationship instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relationName
|
||||
* @param bool $inverse
|
||||
* @return void
|
||||
* @param string $name
|
||||
* @param string $table
|
||||
* @param string $foreignPivotKey
|
||||
* @param string $relatedPivotKey
|
||||
* @param string $parentKey
|
||||
* @param string $relatedKey
|
||||
* @param string $relationName
|
||||
* @param bool $inverse
|
||||
*/
|
||||
public function __construct(
|
||||
Builder $query,
|
||||
@ -68,7 +66,7 @@ class MorphToMany extends BelongsToMany
|
||||
$inverse = false
|
||||
) {
|
||||
$this->inverse = $inverse;
|
||||
$this->morphType = $name.'_type';
|
||||
$this->morphType = $name . '_type';
|
||||
$this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass();
|
||||
|
||||
parent::__construct(
|
||||
@ -85,29 +83,24 @@ class MorphToMany extends BelongsToMany
|
||||
|
||||
/**
|
||||
* 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);
|
||||
$this->query->where($this->table . '.' . $this->morphType, $this->morphClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the constraints for a relationship count query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
{
|
||||
return parent::getRelationExistenceQuery($query, $parentQuery, $columns)->where(
|
||||
$this->table.'.'.$this->morphType,
|
||||
$this->table . '.' . $this->morphType,
|
||||
$this->morphClass
|
||||
);
|
||||
}
|
||||
@ -115,8 +108,7 @@ class MorphToMany extends BelongsToMany
|
||||
/**
|
||||
* Create a new pivot model instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param bool $exists
|
||||
* @param bool $exists
|
||||
* @return \Hyperf\Database\Model\Relations\Pivot
|
||||
*/
|
||||
public function newPivot(array $attributes = [], $exists = false)
|
||||
@ -172,7 +164,7 @@ class MorphToMany extends BelongsToMany
|
||||
{
|
||||
parent::addWhereConstraints();
|
||||
|
||||
$this->query->where($this->table.'.'.$this->morphType, $this->morphClass);
|
||||
$this->query->where($this->table . '.' . $this->morphType, $this->morphClass);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -215,7 +207,7 @@ class MorphToMany extends BelongsToMany
|
||||
$defaults = [$this->foreignPivotKey, $this->relatedPivotKey, $this->morphType];
|
||||
|
||||
return collect(array_merge($defaults, $this->pivotColumns))->map(function ($column) {
|
||||
return $this->table.'.'.$column.' as pivot_'.$column;
|
||||
return $this->table . '.' . $column . ' as pivot_' . $column;
|
||||
})->unique()->all();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -66,10 +67,6 @@ abstract class Relation
|
||||
|
||||
/**
|
||||
* Create a new relation instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Model $parent
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Builder $query, Model $parent)
|
||||
{
|
||||
@ -83,9 +80,8 @@ abstract class Relation
|
||||
/**
|
||||
* Handle dynamic method calls to the relationship.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
@ -104,8 +100,6 @@ abstract class Relation
|
||||
|
||||
/**
|
||||
* Force a clone of the underlying query builder when cloning.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
@ -114,9 +108,6 @@ abstract class Relation
|
||||
|
||||
/**
|
||||
* Run a callback with constraints disabled on the relation.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public static function noConstraints(Closure $callback)
|
||||
{
|
||||
@ -136,24 +127,18 @@ abstract class Relation
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param string $relation
|
||||
* @return array
|
||||
*/
|
||||
abstract public function initRelation(array $models, $relation);
|
||||
@ -161,17 +146,13 @@ abstract class Relation
|
||||
/**
|
||||
* Match the eagerly loaded results to their parents.
|
||||
*
|
||||
* @param array $models
|
||||
* @param \Hyperf\Database\Model\Collection $results
|
||||
* @param string $relation
|
||||
* @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();
|
||||
|
||||
@ -188,7 +169,7 @@ abstract class Relation
|
||||
/**
|
||||
* Execute the query as a "select" statement.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public function get($columns = ['*'])
|
||||
@ -198,8 +179,6 @@ abstract class Relation
|
||||
|
||||
/**
|
||||
* Touch all of the related models for the relationship.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
@ -215,7 +194,6 @@ abstract class Relation
|
||||
/**
|
||||
* Run a raw update against the base query.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return int
|
||||
*/
|
||||
public function rawUpdate(array $attributes = [])
|
||||
@ -226,8 +204,6 @@ abstract class Relation
|
||||
/**
|
||||
* Add the constraints for a relationship count query.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceCountQuery(Builder $query, Builder $parentQuery)
|
||||
@ -244,9 +220,7 @@ abstract class Relation
|
||||
*
|
||||
* Essentially, these queries compare on column names like whereColumn.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $query
|
||||
* @param \Hyperf\Database\Model\Builder $parentQuery
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Database\Model\Builder
|
||||
*/
|
||||
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
|
||||
@ -341,7 +315,6 @@ abstract class Relation
|
||||
/**
|
||||
* Set or get the morph map for polymorphic relations.
|
||||
*
|
||||
* @param array|null $map
|
||||
* @param bool $merge
|
||||
* @return array
|
||||
*/
|
||||
@ -360,7 +333,7 @@ abstract class Relation
|
||||
/**
|
||||
* Get the model associated with a custom polymorphic type.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param string $alias
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getMorphedModel($alias)
|
||||
@ -371,8 +344,7 @@ abstract class Relation
|
||||
/**
|
||||
* Get all of the primary keys for an array of models.
|
||||
*
|
||||
* @param array $models
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
protected function getKeys(array $models, $key = null)
|
||||
@ -385,8 +357,7 @@ abstract class Relation
|
||||
/**
|
||||
* Get the name of the "where in" method for eager loading.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function whereInMethod(Model $model, $key)
|
||||
@ -401,7 +372,7 @@ abstract class Relation
|
||||
/**
|
||||
* Builds a table-keyed array from model class names.
|
||||
*
|
||||
* @param string[]|null $models
|
||||
* @param string[]|null $models
|
||||
* @return array|null
|
||||
*/
|
||||
protected static function buildMorphMapFromModels(array $models = null)
|
||||
@ -411,7 +382,7 @@ abstract class Relation
|
||||
}
|
||||
|
||||
return array_combine(array_map(function ($model) {
|
||||
return (new $model)->getTable();
|
||||
return (new $model())->getTable();
|
||||
}, $models), $models);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -16,9 +17,8 @@ interface Scope
|
||||
/**
|
||||
* Apply the scope to a given Model query builder.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -22,12 +23,10 @@ trait SoftDeletes
|
||||
|
||||
/**
|
||||
* Boot the soft deleting trait for a model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function bootSoftDeletes()
|
||||
{
|
||||
static::addGlobalScope(new SoftDeletingScope);
|
||||
static::addGlobalScope(new SoftDeletingScope());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,7 +57,7 @@ trait SoftDeletes
|
||||
// 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) {
|
||||
if (false === $this->fireModelEvent('restoring')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -89,8 +88,7 @@ trait SoftDeletes
|
||||
/**
|
||||
* Register a restoring model event with the dispatcher.
|
||||
*
|
||||
* @param \Closure|string $callback
|
||||
* @return void
|
||||
* @param \Closure|string $callback
|
||||
*/
|
||||
public static function restoring($callback)
|
||||
{
|
||||
@ -100,8 +98,7 @@ trait SoftDeletes
|
||||
/**
|
||||
* Register a restored model event with the dispatcher.
|
||||
*
|
||||
* @param \Closure|string $callback
|
||||
* @return void
|
||||
* @param \Closure|string $callback
|
||||
*/
|
||||
public static function restored($callback)
|
||||
{
|
||||
@ -140,8 +137,6 @@ trait SoftDeletes
|
||||
|
||||
/**
|
||||
* Perform the actual delete query on this model instance.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function performDeleteOnModel()
|
||||
{
|
||||
@ -156,8 +151,6 @@ trait SoftDeletes
|
||||
|
||||
/**
|
||||
* Perform the actual delete query on this model instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function runSoftDelete()
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -23,9 +24,8 @@ class SoftDeletingScope implements Scope
|
||||
/**
|
||||
* Apply the scope to a given Model query builder.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @param \Hyperf\Database\Model\Model $model
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model)
|
||||
{
|
||||
@ -35,8 +35,7 @@ class SoftDeletingScope implements Scope
|
||||
/**
|
||||
* Extend the query builder with the needed functions.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
*/
|
||||
public function extend(Builder $builder)
|
||||
{
|
||||
@ -56,7 +55,7 @@ class SoftDeletingScope implements Scope
|
||||
/**
|
||||
* Get the "deleted at" column for the builder.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @return string
|
||||
*/
|
||||
protected function getDeletedAtColumn(Builder $builder)
|
||||
@ -71,8 +70,7 @@ class SoftDeletingScope implements Scope
|
||||
/**
|
||||
* Add the restore extension to the builder.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
*/
|
||||
protected function addRestore(Builder $builder)
|
||||
{
|
||||
@ -86,8 +84,7 @@ class SoftDeletingScope implements Scope
|
||||
/**
|
||||
* Add the with-trashed extension to the builder.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
*/
|
||||
protected function addWithTrashed(Builder $builder)
|
||||
{
|
||||
@ -103,8 +100,7 @@ class SoftDeletingScope implements Scope
|
||||
/**
|
||||
* Add the without-trashed extension to the builder.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
*/
|
||||
protected function addWithoutTrashed(Builder $builder)
|
||||
{
|
||||
@ -122,8 +118,7 @@ class SoftDeletingScope implements Scope
|
||||
/**
|
||||
* Add the only-trashed extension to the builder.
|
||||
*
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Model\Builder $builder
|
||||
*/
|
||||
protected function addOnlyTrashed(Builder $builder)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -53,7 +54,7 @@ class MySqlConnection extends Connection
|
||||
*/
|
||||
protected function getDefaultQueryGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new QueryGrammar);
|
||||
return $this->withTablePrefix(new QueryGrammar());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,7 +64,7 @@ class MySqlConnection extends Connection
|
||||
*/
|
||||
protected function getDefaultSchemaGrammar()
|
||||
{
|
||||
return $this->withTablePrefix(new SchemaGrammar);
|
||||
return $this->withTablePrefix(new SchemaGrammar());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,7 +74,7 @@ class MySqlConnection extends Connection
|
||||
*/
|
||||
protected function getDefaultPostProcessor()
|
||||
{
|
||||
return new MySqlProcessor;
|
||||
return new MySqlProcessor();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,6 +84,6 @@ class MySqlConnection extends Connection
|
||||
*/
|
||||
protected function getDoctrineDriver()
|
||||
{
|
||||
return new DoctrineDriver;
|
||||
return new DoctrineDriver();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -22,9 +23,6 @@ class Expression
|
||||
|
||||
/**
|
||||
* Create a new raw query expression.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
@ -43,8 +41,6 @@ class Expression
|
||||
|
||||
/**
|
||||
* Get the value of the expression.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -50,7 +51,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a select query into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
public function compileSelect(Builder $query)
|
||||
@ -85,7 +85,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Prepare the binding for a "JSON contains" statement.
|
||||
*
|
||||
* @param mixed $binding
|
||||
* @return string
|
||||
*/
|
||||
public function prepareBindingForJsonContains($binding)
|
||||
@ -107,7 +106,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile an exists statement into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
public function compileExists(Builder $query)
|
||||
@ -120,8 +118,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile an insert statement into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function compileInsert(Builder $query, array $values)
|
||||
@ -131,7 +127,7 @@ class Grammar extends BaseGrammar
|
||||
// basic routine regardless of an amount of records given to us to insert.
|
||||
$table = $this->wrapTable($query->from);
|
||||
|
||||
if (!is_array(reset($values))) {
|
||||
if (! is_array(reset($values))) {
|
||||
$values = [$values];
|
||||
}
|
||||
|
||||
@ -150,8 +146,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile an insert and get ID statement into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @param array $values
|
||||
* @param string $sequence
|
||||
* @return string
|
||||
*/
|
||||
@ -163,9 +158,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile an insert statement using a subquery into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $columns
|
||||
* @param string $sql
|
||||
* @return string
|
||||
*/
|
||||
public function compileInsertUsing(Builder $query, array $columns, string $sql)
|
||||
@ -176,8 +168,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile an update statement into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function compileUpdate(Builder $query, $values)
|
||||
@ -211,8 +202,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Prepare the bindings for an update statement.
|
||||
*
|
||||
* @param array $bindings
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function prepareBindingsForUpdate(array $bindings, array $values)
|
||||
@ -227,7 +216,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a delete statement into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
public function compileDelete(Builder $query)
|
||||
@ -240,7 +228,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Prepare the bindings for a delete statement.
|
||||
*
|
||||
* @param array $bindings
|
||||
* @return array
|
||||
*/
|
||||
public function prepareBindingsForDelete(array $bindings)
|
||||
@ -251,7 +238,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a truncate table statement into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return array
|
||||
*/
|
||||
public function compileTruncate(Builder $query)
|
||||
@ -295,7 +281,7 @@ class Grammar extends BaseGrammar
|
||||
* Wrap a value in keyword identifiers.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Expression|string $value
|
||||
* @param bool $prefixAlias
|
||||
* @param bool $prefixAlias
|
||||
* @return string
|
||||
*/
|
||||
public function wrap($value, $prefixAlias = false)
|
||||
@ -307,7 +293,7 @@ class Grammar extends BaseGrammar
|
||||
// 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 its
|
||||
// own, and then join these both back together using the "as" connector.
|
||||
if (stripos($value, ' as ') !== false) {
|
||||
if (false !== stripos($value, ' as ')) {
|
||||
return $this->wrapAliasedValue($value, $prefixAlias);
|
||||
}
|
||||
|
||||
@ -334,7 +320,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the components necessary for a select clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return array
|
||||
*/
|
||||
protected function compileComponents(Builder $query)
|
||||
@ -345,7 +330,7 @@ class Grammar extends BaseGrammar
|
||||
// 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 (isset($query->$component) && !is_null($query->$component)) {
|
||||
if (isset($query->$component) && ! is_null($query->$component)) {
|
||||
$method = 'compile' . ucfirst($component);
|
||||
|
||||
$sql[$component] = $this->$method($query, $query->$component);
|
||||
@ -358,8 +343,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile an aggregated select clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $aggregate
|
||||
* @param array $aggregate
|
||||
* @return string
|
||||
*/
|
||||
protected function compileAggregate(Builder $query, $aggregate)
|
||||
@ -369,7 +353,7 @@ class Grammar extends BaseGrammar
|
||||
// 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 !== '*') {
|
||||
if ($query->distinct && '*' !== $column) {
|
||||
$column = 'distinct ' . $column;
|
||||
}
|
||||
|
||||
@ -379,8 +363,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the "select *" portion of the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $columns
|
||||
* @param array $columns
|
||||
* @return string|null
|
||||
*/
|
||||
protected function compileColumns(Builder $query, $columns)
|
||||
@ -388,7 +371,7 @@ class Grammar extends BaseGrammar
|
||||
// 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)) {
|
||||
if (! is_null($query->aggregate)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -400,7 +383,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the "from" portion of the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
@ -412,8 +394,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the "join" portions of the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $joins
|
||||
* @param array $joins
|
||||
* @return string
|
||||
*/
|
||||
protected function compileJoins(Builder $query, $joins)
|
||||
@ -432,7 +413,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the "where" portions of the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
protected function compileWheres(Builder $query)
|
||||
@ -471,7 +451,7 @@ class Grammar extends BaseGrammar
|
||||
* Format the where clause statements into one string.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $sql
|
||||
* @param array $sql
|
||||
* @return string
|
||||
*/
|
||||
protected function concatenateWhereClauses($query, $sql)
|
||||
@ -484,8 +464,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a raw where clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereRaw(Builder $query, $where)
|
||||
@ -496,8 +475,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a basic where clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereBasic(Builder $query, $where)
|
||||
@ -510,13 +488,12 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where in" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereIn(Builder $query, $where)
|
||||
{
|
||||
if (!empty($where['values'])) {
|
||||
if (! empty($where['values'])) {
|
||||
return $this->wrap($where['column']) . ' in (' . $this->parameterize($where['values']) . ')';
|
||||
}
|
||||
|
||||
@ -526,13 +503,12 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where not in" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNotIn(Builder $query, $where)
|
||||
{
|
||||
if (!empty($where['values'])) {
|
||||
if (! empty($where['values'])) {
|
||||
return $this->wrap($where['column']) . ' not in (' . $this->parameterize($where['values']) . ')';
|
||||
}
|
||||
|
||||
@ -544,13 +520,12 @@ class Grammar extends BaseGrammar
|
||||
*
|
||||
* For safety, whereIntegerInRaw ensures this method is only used with integer values.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNotInRaw(Builder $query, $where)
|
||||
{
|
||||
if (!empty($where['values'])) {
|
||||
if (! empty($where['values'])) {
|
||||
return $this->wrap($where['column']) . ' not in (' . implode(', ', $where['values']) . ')';
|
||||
}
|
||||
|
||||
@ -560,8 +535,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a where in sub-select clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereInSub(Builder $query, $where)
|
||||
@ -572,8 +546,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a where not in sub-select clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNotInSub(Builder $query, $where)
|
||||
@ -586,13 +559,12 @@ class Grammar extends BaseGrammar
|
||||
*
|
||||
* For safety, whereIntegerInRaw ensures this method is only used with integer values.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereInRaw(Builder $query, $where)
|
||||
{
|
||||
if (!empty($where['values'])) {
|
||||
if (! empty($where['values'])) {
|
||||
return $this->wrap($where['column']) . ' in (' . implode(', ', $where['values']) . ')';
|
||||
}
|
||||
|
||||
@ -602,8 +574,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where null" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNull(Builder $query, $where)
|
||||
@ -614,8 +585,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where not null" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNotNull(Builder $query, $where)
|
||||
@ -626,8 +596,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "between" where clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereBetween(Builder $query, $where)
|
||||
@ -644,8 +613,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where date" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereDate(Builder $query, $where)
|
||||
@ -656,8 +624,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where time" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereTime(Builder $query, $where)
|
||||
@ -668,8 +635,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where day" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereDay(Builder $query, $where)
|
||||
@ -680,8 +646,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where month" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereMonth(Builder $query, $where)
|
||||
@ -692,8 +657,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where year" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereYear(Builder $query, $where)
|
||||
@ -705,8 +669,7 @@ class Grammar extends BaseGrammar
|
||||
* Compile a date based where clause.
|
||||
*
|
||||
* @param string $type
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function dateBasedWhere($type, Builder $query, $where)
|
||||
@ -719,8 +682,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a where clause comparing two columns..
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereColumn(Builder $query, $where)
|
||||
@ -731,8 +693,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a nested where clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNested(Builder $query, $where)
|
||||
@ -748,8 +709,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a where condition with a sub-select.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereSub(Builder $query, $where)
|
||||
@ -762,8 +722,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a where exists clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereExists(Builder $query, $where)
|
||||
@ -774,8 +733,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a where exists clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereNotExists(Builder $query, $where)
|
||||
@ -786,8 +744,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a where row values condition.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereRowValues(Builder $query, $where)
|
||||
@ -802,8 +759,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where JSON contains" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereJsonContains(Builder $query, $where)
|
||||
@ -833,8 +789,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "where JSON length" clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $where
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function whereJsonLength(Builder $query, $where)
|
||||
@ -864,8 +819,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the "group by" portions of the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $groups
|
||||
* @param array $groups
|
||||
* @return string
|
||||
*/
|
||||
protected function compileGroups(Builder $query, $groups)
|
||||
@ -876,8 +830,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the "having" portions of the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $havings
|
||||
* @param array $havings
|
||||
* @return string
|
||||
*/
|
||||
protected function compileHavings(Builder $query, $havings)
|
||||
@ -890,7 +843,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a single having clause.
|
||||
*
|
||||
* @param array $having
|
||||
* @return string
|
||||
*/
|
||||
protected function compileHaving(array $having)
|
||||
@ -898,9 +850,9 @@ class Grammar extends BaseGrammar
|
||||
// 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') {
|
||||
if ('Raw' === $having['type']) {
|
||||
return $having['boolean'] . ' ' . $having['sql'];
|
||||
} elseif ($having['type'] === 'between') {
|
||||
} elseif ('between' === $having['type']) {
|
||||
return $this->compileHavingBetween($having);
|
||||
}
|
||||
|
||||
@ -910,7 +862,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a basic having clause.
|
||||
*
|
||||
* @param array $having
|
||||
* @param array $having
|
||||
* @return string
|
||||
*/
|
||||
protected function compileBasicHaving($having)
|
||||
@ -925,7 +877,7 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a "between" having clause.
|
||||
*
|
||||
* @param array $having
|
||||
* @param array $having
|
||||
* @return string
|
||||
*/
|
||||
protected function compileHavingBetween($having)
|
||||
@ -944,13 +896,12 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the "order by" portions of the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $orders
|
||||
* @param array $orders
|
||||
* @return string
|
||||
*/
|
||||
protected function compileOrders(Builder $query, $orders)
|
||||
{
|
||||
if (!empty($orders)) {
|
||||
if (! empty($orders)) {
|
||||
return 'order by ' . implode(', ', $this->compileOrdersToArray($query, $orders));
|
||||
}
|
||||
|
||||
@ -960,14 +911,13 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the query orders to an array.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $orders
|
||||
* @return array
|
||||
*/
|
||||
protected function compileOrdersToArray(Builder $query, $orders)
|
||||
{
|
||||
return array_map(function ($order) {
|
||||
return !isset($order['sql'])
|
||||
return ! isset($order['sql'])
|
||||
? $this->wrap($order['column']) . ' ' . $order['direction']
|
||||
: $order['sql'];
|
||||
}, $orders);
|
||||
@ -976,31 +926,28 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the "limit" portions of the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param int $limit
|
||||
* @param int $limit
|
||||
* @return string
|
||||
*/
|
||||
protected function compileLimit(Builder $query, $limit)
|
||||
{
|
||||
return 'limit ' . (int)$limit;
|
||||
return 'limit ' . (int) $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "offset" portions of the query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param int $offset
|
||||
* @param int $offset
|
||||
* @return string
|
||||
*/
|
||||
protected function compileOffset(Builder $query, $offset)
|
||||
{
|
||||
return 'offset ' . (int)$offset;
|
||||
return 'offset ' . (int) $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "union" queries attached to the main query.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUnions(Builder $query)
|
||||
@ -1011,7 +958,7 @@ class Grammar extends BaseGrammar
|
||||
$sql .= $this->compileUnion($union);
|
||||
}
|
||||
|
||||
if (!empty($query->unionOrders)) {
|
||||
if (! empty($query->unionOrders)) {
|
||||
$sql .= ' ' . $this->compileOrders($query, $query->unionOrders);
|
||||
}
|
||||
|
||||
@ -1029,7 +976,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a single union statement.
|
||||
*
|
||||
* @param array $union
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUnion(array $union)
|
||||
@ -1042,7 +988,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a union aggregate query into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUnionAggregate(Builder $query)
|
||||
@ -1057,7 +1002,6 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the lock into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param bool|string $value
|
||||
* @return string
|
||||
*/
|
||||
@ -1120,13 +1064,13 @@ class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Concatenate an array of segments, removing empties.
|
||||
*
|
||||
* @param array $segments
|
||||
* @param array $segments
|
||||
* @return string
|
||||
*/
|
||||
protected function concatenate($segments)
|
||||
{
|
||||
return implode(' ', array_filter($segments, function ($value) {
|
||||
return (string)$value !== '';
|
||||
return '' !== (string) $value;
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -46,7 +47,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a select query into SQL.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @return string
|
||||
*/
|
||||
public function compileSelect(Builder $query)
|
||||
@ -78,8 +78,7 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile an update statement into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param array $values
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
public function compileUpdate(Builder $query, $values)
|
||||
@ -110,7 +109,7 @@ class MySqlGrammar extends Grammar
|
||||
// If the query has an order by clause we will compile it since MySQL supports
|
||||
// order bys on update statements. We'll compile them using the typical way
|
||||
// of compiling order bys. Then they will be appended to the SQL queries.
|
||||
if (!empty($query->orders)) {
|
||||
if (! empty($query->orders)) {
|
||||
$sql .= ' ' . $this->compileOrders($query, $query->orders);
|
||||
}
|
||||
|
||||
@ -129,8 +128,6 @@ class MySqlGrammar extends Grammar
|
||||
*
|
||||
* Booleans, integers, and doubles are inserted into JSON updates as raw values.
|
||||
*
|
||||
* @param array $bindings
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function prepareBindingsForUpdate(array $bindings, array $values)
|
||||
@ -145,7 +142,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a delete statement into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @return string
|
||||
*/
|
||||
public function compileDelete(Builder $query)
|
||||
@ -162,7 +158,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Prepare the bindings for a delete statement.
|
||||
*
|
||||
* @param array $bindings
|
||||
* @return array
|
||||
*/
|
||||
public function prepareBindingsForDelete(array $bindings)
|
||||
@ -206,7 +201,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a single union statement.
|
||||
*
|
||||
* @param array $union
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUnion(array $union)
|
||||
@ -219,13 +213,12 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile the lock into SQL.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param bool|string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileLock(Builder $query, $value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
if (! is_string($value)) {
|
||||
return $value ? 'for update' : 'lock in share mode';
|
||||
}
|
||||
|
||||
@ -235,7 +228,7 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile all of the columns for an update statement.
|
||||
*
|
||||
* @param array $values
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUpdateColumns($values)
|
||||
@ -253,7 +246,6 @@ class MySqlGrammar extends Grammar
|
||||
* Prepares a JSON column being updated using the JSON_SET function.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \Hyperf\Database\Query\JsonExpression $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileJsonUpdateColumn($key, JsonExpression $value)
|
||||
@ -267,8 +259,8 @@ class MySqlGrammar extends Grammar
|
||||
* Compile a delete query that does not use joins.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param string $table
|
||||
* @param array $where
|
||||
* @param string $table
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function compileDeleteWithoutJoins($query, $table, $where)
|
||||
@ -278,7 +270,7 @@ class MySqlGrammar extends Grammar
|
||||
// When using MySQL, delete statements may contain order by statements and limits
|
||||
// so we will compile both of those here. Once we have finished compiling this
|
||||
// we will return the completed SQL statement so it will be executed for us.
|
||||
if (!empty($query->orders)) {
|
||||
if (! empty($query->orders)) {
|
||||
$sql .= ' ' . $this->compileOrders($query, $query->orders);
|
||||
}
|
||||
|
||||
@ -293,15 +285,15 @@ class MySqlGrammar extends Grammar
|
||||
* Compile a delete query that uses joins.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $query
|
||||
* @param string $table
|
||||
* @param array $where
|
||||
* @param string $table
|
||||
* @param array $where
|
||||
* @return string
|
||||
*/
|
||||
protected function compileDeleteWithJoins($query, $table, $where)
|
||||
{
|
||||
$joins = ' ' . $this->compileJoins($query, $query->joins);
|
||||
|
||||
$alias = stripos($table, ' as ') !== false
|
||||
$alias = false !== stripos($table, ' as ')
|
||||
? explode(' as ', $table)[1] : $table;
|
||||
|
||||
return trim("delete {$alias} from {$table}{$joins} {$where}");
|
||||
@ -315,7 +307,7 @@ class MySqlGrammar extends Grammar
|
||||
*/
|
||||
protected function wrapValue($value)
|
||||
{
|
||||
return $value === '*' ? $value : '`' . str_replace('`', '``', $value) . '`';
|
||||
return '*' === $value ? $value : '`' . str_replace('`', '``', $value) . '`';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -39,10 +40,9 @@ class JoinClause extends Builder
|
||||
/**
|
||||
* Create a new join clause instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Builder $parentQuery
|
||||
* @param string $type
|
||||
* @param string $table
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Query\Builder $parentQuery
|
||||
* @param string $type
|
||||
* @param string $table
|
||||
*/
|
||||
public function __construct(Builder $parentQuery, $type, $table)
|
||||
{
|
||||
@ -69,10 +69,10 @@ class JoinClause extends Builder
|
||||
*
|
||||
* on `contacts`.`user_id` = `users`.`id` and `contacts`.`info_id` = `info`.`id`
|
||||
*
|
||||
* @param \Closure|string $first
|
||||
* @param string|null $operator
|
||||
* @param string|null $second
|
||||
* @param string $boolean
|
||||
* @param \Closure|string $first
|
||||
* @param string|null $operator
|
||||
* @param string|null $second
|
||||
* @param string $boolean
|
||||
* @return $this
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
@ -89,9 +89,9 @@ class JoinClause extends Builder
|
||||
/**
|
||||
* Add an "or on" clause to the join.
|
||||
*
|
||||
* @param \Closure|string $first
|
||||
* @param string|null $operator
|
||||
* @param string|null $second
|
||||
* @param \Closure|string $first
|
||||
* @param string|null $operator
|
||||
* @param string|null $second
|
||||
* @return \Hyperf\Database\Query\JoinClause
|
||||
*/
|
||||
public function orOn($first, $operator = null, $second = null)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -17,9 +18,6 @@ class JsonExpression extends Expression
|
||||
{
|
||||
/**
|
||||
* Create a new raw query expression.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
@ -31,7 +29,6 @@ class JsonExpression extends Expression
|
||||
/**
|
||||
* Translate the given value into the appropriate JSON binding parameter.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -16,7 +17,7 @@ class MySqlProcessor extends Processor
|
||||
/**
|
||||
* Process the results of a column listing query.
|
||||
*
|
||||
* @param array $results
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
public function processColumnListing($results)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -18,7 +19,6 @@ class Processor
|
||||
/**
|
||||
* Process the results of a "select" query.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param array $results
|
||||
* @return array
|
||||
*/
|
||||
@ -30,9 +30,8 @@ class Processor
|
||||
/**
|
||||
* Process an "insert get ID" query.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param string $sql
|
||||
* @param array $values
|
||||
* @param array $values
|
||||
* @param string $sequence
|
||||
* @return int
|
||||
*/
|
||||
@ -42,7 +41,7 @@ class Processor
|
||||
|
||||
$id = $query->getConnection()->getPdo()->lastInsertId($sequence);
|
||||
|
||||
return is_numeric($id) ? (int)$id : $id;
|
||||
return is_numeric($id) ? (int) $id : $id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -78,27 +79,21 @@ class Blueprint
|
||||
/**
|
||||
* Create a new schema blueprint.
|
||||
*
|
||||
* @param string $table
|
||||
* @param \Closure|null $callback
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
* @param string $table
|
||||
* @param string $prefix
|
||||
*/
|
||||
public function __construct($table, Closure $callback = null, $prefix = '')
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->prefix = $prefix;
|
||||
|
||||
if (!is_null($callback)) {
|
||||
if (! is_null($callback)) {
|
||||
$callback($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the blueprint against the database.
|
||||
*
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return void
|
||||
*/
|
||||
public function build(Connection $connection, Grammar $grammar)
|
||||
{
|
||||
@ -110,8 +105,6 @@ class Blueprint
|
||||
/**
|
||||
* Get the raw SQL statements for the blueprint.
|
||||
*
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return array
|
||||
*/
|
||||
public function toSql(Connection $connection, Grammar $grammar)
|
||||
@ -129,8 +122,8 @@ class Blueprint
|
||||
$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);
|
||||
if (! is_null($sql = $grammar->$method($this, $command, $connection))) {
|
||||
$statements = array_merge($statements, (array) $sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,9 +133,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Add the fluent commands specified on any columns.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return void
|
||||
*/
|
||||
public function addFluentCommands(Grammar $grammar)
|
||||
{
|
||||
@ -150,7 +140,7 @@ class Blueprint
|
||||
foreach ($grammar->getFluentCommands() as $commandName) {
|
||||
$attributeName = lcfirst($commandName);
|
||||
|
||||
if (!isset($column->{$attributeName})) {
|
||||
if (! isset($column->{$attributeName})) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -176,8 +166,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Indicate that the table needs to be temporary.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function temporary()
|
||||
{
|
||||
@ -207,7 +195,7 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the given columns should be dropped.
|
||||
*
|
||||
* @param array|mixed $columns
|
||||
* @param array|mixed $columns
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function dropColumn($columns)
|
||||
@ -220,8 +208,8 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the given columns should be renamed.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function renameColumn($from, $to)
|
||||
@ -232,7 +220,7 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the given primary key should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @param string|array $index
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function dropPrimary($index = null)
|
||||
@ -243,7 +231,7 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the given unique key should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @param string|array $index
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function dropUnique($index)
|
||||
@ -254,7 +242,7 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the given index should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @param string|array $index
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function dropIndex($index)
|
||||
@ -265,7 +253,7 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the given spatial index should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @param string|array $index
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function dropSpatialIndex($index)
|
||||
@ -276,7 +264,7 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the given foreign key should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @param string|array $index
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function dropForeign($index)
|
||||
@ -287,8 +275,8 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the given indexes should be renamed.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function renameIndex($from, $to)
|
||||
@ -298,8 +286,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Indicate that the timestamp columns should be dropped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropTimestamps()
|
||||
{
|
||||
@ -308,8 +294,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Indicate that the timestamp columns should be dropped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropTimestampsTz()
|
||||
{
|
||||
@ -319,8 +303,7 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the soft delete column should be dropped.
|
||||
*
|
||||
* @param string $column
|
||||
* @return void
|
||||
* @param string $column
|
||||
*/
|
||||
public function dropSoftDeletes($column = 'deleted_at')
|
||||
{
|
||||
@ -330,8 +313,7 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the soft delete column should be dropped.
|
||||
*
|
||||
* @param string $column
|
||||
* @return void
|
||||
* @param string $column
|
||||
*/
|
||||
public function dropSoftDeletesTz($column = 'deleted_at')
|
||||
{
|
||||
@ -340,8 +322,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Indicate that the remember token column should be dropped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropRememberToken()
|
||||
{
|
||||
@ -351,9 +331,8 @@ class Blueprint
|
||||
/**
|
||||
* Indicate that the polymorphic columns should be dropped.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|null $indexName
|
||||
* @return void
|
||||
* @param string $name
|
||||
* @param string|null $indexName
|
||||
*/
|
||||
public function dropMorphs($name, $indexName = null)
|
||||
{
|
||||
@ -365,7 +344,7 @@ class Blueprint
|
||||
/**
|
||||
* Rename the table to a given name.
|
||||
*
|
||||
* @param string $to
|
||||
* @param string $to
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function rename($to)
|
||||
@ -376,9 +355,9 @@ class Blueprint
|
||||
/**
|
||||
* Specify the primary key(s) for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @param string|null $algorithm
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @param string|null $algorithm
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function primary($columns, $name = null, $algorithm = null)
|
||||
@ -389,9 +368,9 @@ class Blueprint
|
||||
/**
|
||||
* Specify a unique index for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @param string|null $algorithm
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @param string|null $algorithm
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function unique($columns, $name = null, $algorithm = null)
|
||||
@ -402,9 +381,9 @@ class Blueprint
|
||||
/**
|
||||
* Specify an index for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @param string|null $algorithm
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @param string|null $algorithm
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function index($columns, $name = null, $algorithm = null)
|
||||
@ -415,8 +394,8 @@ class Blueprint
|
||||
/**
|
||||
* Specify a spatial index for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function spatialIndex($columns, $name = null)
|
||||
@ -427,8 +406,8 @@ class Blueprint
|
||||
/**
|
||||
* Specify a foreign key for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
public function foreign($columns, $name = null)
|
||||
@ -439,7 +418,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new auto-incrementing integer (4-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function increments($column)
|
||||
@ -450,7 +429,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new auto-incrementing integer (4-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function integerIncrements($column)
|
||||
@ -461,7 +440,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new auto-incrementing tiny integer (1-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function tinyIncrements($column)
|
||||
@ -472,7 +451,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new auto-incrementing small integer (2-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function smallIncrements($column)
|
||||
@ -483,7 +462,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new auto-incrementing medium integer (3-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function mediumIncrements($column)
|
||||
@ -494,7 +473,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new auto-incrementing big integer (8-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function bigIncrements($column)
|
||||
@ -505,8 +484,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new char column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $length
|
||||
* @param string $column
|
||||
* @param int $length
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function char($column, $length = null)
|
||||
@ -519,8 +498,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new string column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $length
|
||||
* @param string $column
|
||||
* @param int $length
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function string($column, $length = null)
|
||||
@ -533,7 +512,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function text($column)
|
||||
@ -544,7 +523,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new medium text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function mediumText($column)
|
||||
@ -555,7 +534,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new long text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function longText($column)
|
||||
@ -566,9 +545,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new integer (4-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function integer($column, $autoIncrement = false, $unsigned = false)
|
||||
@ -579,9 +558,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new tiny integer (1-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function tinyInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
@ -592,9 +571,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new small integer (2-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function smallInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
@ -605,9 +584,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new medium integer (3-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function mediumInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
@ -618,9 +597,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new big integer (8-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function bigInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
@ -631,8 +610,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new unsigned integer (4-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function unsignedInteger($column, $autoIncrement = false)
|
||||
@ -643,8 +622,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new unsigned tiny integer (1-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function unsignedTinyInteger($column, $autoIncrement = false)
|
||||
@ -655,8 +634,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new unsigned small integer (2-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function unsignedSmallInteger($column, $autoIncrement = false)
|
||||
@ -667,8 +646,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new unsigned medium integer (3-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function unsignedMediumInteger($column, $autoIncrement = false)
|
||||
@ -679,8 +658,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new unsigned big integer (8-byte) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function unsignedBigInteger($column, $autoIncrement = false)
|
||||
@ -691,9 +670,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new float column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function float($column, $total = 8, $places = 2)
|
||||
@ -704,9 +683,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new double column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int|null $total
|
||||
* @param int|null $places
|
||||
* @param string $column
|
||||
* @param int|null $total
|
||||
* @param int|null $places
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function double($column, $total = null, $places = null)
|
||||
@ -717,9 +696,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new decimal column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function decimal($column, $total = 8, $places = 2)
|
||||
@ -730,9 +709,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new unsigned decimal column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function unsignedDecimal($column, $total = 8, $places = 2)
|
||||
@ -745,7 +724,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new boolean column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function boolean($column)
|
||||
@ -756,8 +735,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new enum column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param array $allowed
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function enum($column, array $allowed)
|
||||
@ -768,7 +746,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new json column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function json($column)
|
||||
@ -779,7 +757,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new jsonb column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function jsonb($column)
|
||||
@ -790,7 +768,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new date column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function date($column)
|
||||
@ -801,8 +779,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new date-time column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function dateTime($column, $precision = 0)
|
||||
@ -813,8 +791,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new date-time column (with time zone) on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function dateTimeTz($column, $precision = 0)
|
||||
@ -825,8 +803,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new time column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function time($column, $precision = 0)
|
||||
@ -837,8 +815,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new time column (with time zone) on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function timeTz($column, $precision = 0)
|
||||
@ -849,8 +827,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new timestamp column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function timestamp($column, $precision = 0)
|
||||
@ -861,8 +839,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new timestamp (with time zone) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function timestampTz($column, $precision = 0)
|
||||
@ -873,8 +851,7 @@ class Blueprint
|
||||
/**
|
||||
* Add nullable creation and update timestamps to the table.
|
||||
*
|
||||
* @param int $precision
|
||||
* @return void
|
||||
* @param int $precision
|
||||
*/
|
||||
public function timestamps($precision = 0)
|
||||
{
|
||||
@ -888,8 +865,7 @@ class Blueprint
|
||||
*
|
||||
* Alias for self::timestamps().
|
||||
*
|
||||
* @param int $precision
|
||||
* @return void
|
||||
* @param int $precision
|
||||
*/
|
||||
public function nullableTimestamps($precision = 0)
|
||||
{
|
||||
@ -899,8 +875,7 @@ class Blueprint
|
||||
/**
|
||||
* Add creation and update timestampTz columns to the table.
|
||||
*
|
||||
* @param int $precision
|
||||
* @return void
|
||||
* @param int $precision
|
||||
*/
|
||||
public function timestampsTz($precision = 0)
|
||||
{
|
||||
@ -912,8 +887,8 @@ class Blueprint
|
||||
/**
|
||||
* Add a "deleted at" timestamp for the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function softDeletes($column = 'deleted_at', $precision = 0)
|
||||
@ -924,8 +899,8 @@ class Blueprint
|
||||
/**
|
||||
* Add a "deleted at" timestampTz for the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @param string $column
|
||||
* @param int $precision
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function softDeletesTz($column = 'deleted_at', $precision = 0)
|
||||
@ -936,7 +911,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new year column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function year($column)
|
||||
@ -947,7 +922,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new binary column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function binary($column)
|
||||
@ -958,7 +933,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new uuid column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function uuid($column)
|
||||
@ -969,7 +944,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new IP address column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function ipAddress($column)
|
||||
@ -980,7 +955,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new MAC address column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function macAddress($column)
|
||||
@ -991,7 +966,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new geometry column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function geometry($column)
|
||||
@ -1002,8 +977,8 @@ class Blueprint
|
||||
/**
|
||||
* Create a new point column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int|null $srid
|
||||
* @param string $column
|
||||
* @param int|null $srid
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function point($column, $srid = null)
|
||||
@ -1014,7 +989,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new linestring column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function lineString($column)
|
||||
@ -1025,7 +1000,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new polygon column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function polygon($column)
|
||||
@ -1036,7 +1011,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new geometrycollection column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function geometryCollection($column)
|
||||
@ -1047,7 +1022,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new multipoint column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function multiPoint($column)
|
||||
@ -1058,7 +1033,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new multilinestring column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function multiLineString($column)
|
||||
@ -1069,7 +1044,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new multipolygon column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $column
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function multiPolygon($column)
|
||||
@ -1080,9 +1055,8 @@ class Blueprint
|
||||
/**
|
||||
* Add the proper columns for a polymorphic table.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|null $indexName
|
||||
* @return void
|
||||
* @param string $name
|
||||
* @param string|null $indexName
|
||||
*/
|
||||
public function morphs($name, $indexName = null)
|
||||
{
|
||||
@ -1096,9 +1070,8 @@ class Blueprint
|
||||
/**
|
||||
* Add nullable columns for a polymorphic table.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|null $indexName
|
||||
* @return void
|
||||
* @param string $name
|
||||
* @param string|null $indexName
|
||||
*/
|
||||
public function nullableMorphs($name, $indexName = null)
|
||||
{
|
||||
@ -1122,9 +1095,8 @@ class Blueprint
|
||||
/**
|
||||
* Add a new column to the blueprint.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @param string $type
|
||||
* @param string $name
|
||||
* @return \Hyperf\Database\Schema\ColumnDefinition
|
||||
*/
|
||||
public function addColumn($type, $name, array $parameters = [])
|
||||
@ -1189,7 +1161,7 @@ class Blueprint
|
||||
public function getAddedColumns()
|
||||
{
|
||||
return array_filter($this->columns, function ($column) {
|
||||
return !$column->change;
|
||||
return ! $column->change;
|
||||
});
|
||||
}
|
||||
|
||||
@ -1201,15 +1173,13 @@ class Blueprint
|
||||
public function getChangedColumns()
|
||||
{
|
||||
return array_filter($this->columns, function ($column) {
|
||||
return (bool)$column->change;
|
||||
return (bool) $column->change;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the commands on the blueprint are valid for the connection type.
|
||||
*
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @return void
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
@ -1233,7 +1203,6 @@ class Blueprint
|
||||
/**
|
||||
* Get all of the commands matching the given names.
|
||||
*
|
||||
* @param array $names
|
||||
* @return \Hyperf\Utils\Collection
|
||||
*/
|
||||
protected function commandsNamed(array $names)
|
||||
@ -1245,17 +1214,14 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Add the commands that are implied by the blueprint's state.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return void
|
||||
*/
|
||||
protected function addImpliedCommands(Grammar $grammar)
|
||||
{
|
||||
if (count($this->getAddedColumns()) > 0 && !$this->creating()) {
|
||||
if (count($this->getAddedColumns()) > 0 && ! $this->creating()) {
|
||||
array_unshift($this->commands, $this->createCommand('add'));
|
||||
}
|
||||
|
||||
if (count($this->getChangedColumns()) > 0 && !$this->creating()) {
|
||||
if (count($this->getChangedColumns()) > 0 && ! $this->creating()) {
|
||||
array_unshift($this->commands, $this->createCommand('change'));
|
||||
}
|
||||
|
||||
@ -1266,8 +1232,6 @@ class Blueprint
|
||||
|
||||
/**
|
||||
* Add the index commands fluently specified on columns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addFluentIndexes()
|
||||
{
|
||||
@ -1276,7 +1240,7 @@ class Blueprint
|
||||
// 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 the
|
||||
// index method can be called without a name and it will generate one.
|
||||
if ($column->{$index} === true) {
|
||||
if (true === $column->{$index}) {
|
||||
$this->{$index}($column->name);
|
||||
|
||||
continue 2;
|
||||
@ -1302,22 +1266,22 @@ class Blueprint
|
||||
protected function creating()
|
||||
{
|
||||
return collect($this->commands)->contains(function ($command) {
|
||||
return $command->name === 'create';
|
||||
return 'create' === $command->name;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new index command to the blueprint.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string|array $columns
|
||||
* @param string $index
|
||||
* @param string|null $algorithm
|
||||
* @param string $type
|
||||
* @param string|array $columns
|
||||
* @param string $index
|
||||
* @param string|null $algorithm
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
protected function indexCommand($type, $columns, $index, $algorithm = null)
|
||||
{
|
||||
$columns = (array)$columns;
|
||||
$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
|
||||
@ -1333,9 +1297,9 @@ class Blueprint
|
||||
/**
|
||||
* Create a new drop index command on the blueprint.
|
||||
*
|
||||
* @param string $command
|
||||
* @param string $type
|
||||
* @param string|array $index
|
||||
* @param string $command
|
||||
* @param string $type
|
||||
* @param string|array $index
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
protected function dropIndexCommand($command, $type, $index)
|
||||
@ -1356,7 +1320,6 @@ class Blueprint
|
||||
* Create a default index name for the table.
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $columns
|
||||
* @return string
|
||||
*/
|
||||
protected function createIndexName($type, array $columns)
|
||||
@ -1369,8 +1332,7 @@ class Blueprint
|
||||
/**
|
||||
* Add a new command to the blueprint.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @param string $name
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
protected function addCommand($name, array $parameters = [])
|
||||
@ -1383,8 +1345,7 @@ class Blueprint
|
||||
/**
|
||||
* Create a new Fluent command.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @param string $name
|
||||
* @return \Hyperf\Utils\Fluent
|
||||
*/
|
||||
protected function createCommand($name, array $parameters = [])
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -13,6 +14,7 @@ namespace Hyperf\Database\Schema;
|
||||
|
||||
use Closure;
|
||||
use Hyperf\Database\Connection;
|
||||
use Hyperf\Database\ConnectionInterface;
|
||||
use LogicException;
|
||||
|
||||
class Builder
|
||||
@ -48,10 +50,9 @@ class Builder
|
||||
/**
|
||||
* Create a new database Schema manager.
|
||||
*
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
*/
|
||||
public function __construct(Connection $connection)
|
||||
public function __construct(ConnectionInterface $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->grammar = $connection->getSchemaGrammar();
|
||||
@ -60,8 +61,7 @@ class Builder
|
||||
/**
|
||||
* Set the default string length for migrations.
|
||||
*
|
||||
* @param int $length
|
||||
* @return void
|
||||
* @param int $length
|
||||
*/
|
||||
public static function defaultStringLength($length)
|
||||
{
|
||||
@ -103,7 +103,6 @@ class Builder
|
||||
* Determine if the given table has given columns.
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $columns
|
||||
* @return bool
|
||||
*/
|
||||
public function hasColumns($table, array $columns)
|
||||
@ -111,7 +110,7 @@ class Builder
|
||||
$tableColumns = array_map('strtolower', $this->getColumnListing($table));
|
||||
|
||||
foreach ($columns as $column) {
|
||||
if (!in_array(strtolower($column), $tableColumns)) {
|
||||
if (! in_array(strtolower($column), $tableColumns)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -151,9 +150,7 @@ class Builder
|
||||
/**
|
||||
* Modify a table on the schema.
|
||||
*
|
||||
* @param string $table
|
||||
* @param \Closure $callback
|
||||
* @return void
|
||||
* @param string $table
|
||||
*/
|
||||
public function table($table, Closure $callback)
|
||||
{
|
||||
@ -163,9 +160,7 @@ class Builder
|
||||
/**
|
||||
* Create a new table on the schema.
|
||||
*
|
||||
* @param string $table
|
||||
* @param \Closure $callback
|
||||
* @return void
|
||||
* @param string $table
|
||||
*/
|
||||
public function create($table, Closure $callback)
|
||||
{
|
||||
@ -179,8 +174,7 @@ class Builder
|
||||
/**
|
||||
* Drop a table from the schema.
|
||||
*
|
||||
* @param string $table
|
||||
* @return void
|
||||
* @param string $table
|
||||
*/
|
||||
public function drop($table)
|
||||
{
|
||||
@ -192,8 +186,7 @@ class Builder
|
||||
/**
|
||||
* Drop a table from the schema if it exists.
|
||||
*
|
||||
* @param string $table
|
||||
* @return void
|
||||
* @param string $table
|
||||
*/
|
||||
public function dropIfExists($table)
|
||||
{
|
||||
@ -205,7 +198,6 @@ class Builder
|
||||
/**
|
||||
* Drop all tables from the database.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
@ -217,7 +209,6 @@ class Builder
|
||||
/**
|
||||
* Drop all views from the database.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
@ -229,9 +220,8 @@ class Builder
|
||||
/**
|
||||
* Rename a table on the schema.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return void
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
*/
|
||||
public function rename($from, $to)
|
||||
{
|
||||
@ -277,7 +267,6 @@ class Builder
|
||||
/**
|
||||
* Set the database connection instance.
|
||||
*
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @return $this
|
||||
*/
|
||||
public function setConnection(Connection $connection)
|
||||
@ -289,9 +278,6 @@ class Builder
|
||||
|
||||
/**
|
||||
* Set the Schema Blueprint resolver callback.
|
||||
*
|
||||
* @param \Closure $resolver
|
||||
* @return void
|
||||
*/
|
||||
public function blueprintResolver(Closure $resolver)
|
||||
{
|
||||
@ -301,8 +287,7 @@ class Builder
|
||||
/**
|
||||
* Execute the blueprint to build / modify the table.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @return void
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
*/
|
||||
protected function build(Blueprint $blueprint)
|
||||
{
|
||||
@ -312,8 +297,7 @@ class Builder
|
||||
/**
|
||||
* Create a new command set with a Closure.
|
||||
*
|
||||
* @param string $table
|
||||
* @param \Closure|null $callback
|
||||
* @param string $table
|
||||
* @return \Hyperf\Database\Schema\Blueprint
|
||||
*/
|
||||
protected function createBlueprint($table, Closure $callback = null)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -17,24 +18,23 @@ use Hyperf\Utils\Fluent;
|
||||
* @method ColumnDefinition after(string $column) Place the column "after" another column (MySQL)
|
||||
* @method ColumnDefinition always() Used as a modifier for generatedAs() (PostgreSQL)
|
||||
* @method ColumnDefinition autoIncrement() Set INTEGER columns as auto-increment (primary key)
|
||||
* @method ColumnDefinition change() Change the column
|
||||
* @method ColumnDefinition change() Change the column
|
||||
* @method ColumnDefinition charset(string $charset) Specify a character set for the column (MySQL)
|
||||
* @method ColumnDefinition collation(string $collation) Specify a collation for the column (MySQL/SQL Server)
|
||||
* @method ColumnDefinition comment(string $comment) Add a comment to the column (MySQL)
|
||||
* @method ColumnDefinition default(mixed $value) Specify a "default" value for the column
|
||||
* @method ColumnDefinition default(mixed $value) Specify a "default" value for the column
|
||||
* @method ColumnDefinition first() Place the column "first" in the table (MySQL)
|
||||
* @method ColumnDefinition generatedAs(string $expression) Create a SQL compliant identity column (PostgreSQL)
|
||||
* @method ColumnDefinition index() Add an index
|
||||
* @method ColumnDefinition nullable(bool $value = true) Allow NULL values to be inserted into the column
|
||||
* @method ColumnDefinition primary() Add a primary index
|
||||
* @method ColumnDefinition spatialIndex() Add a spatial index
|
||||
* @method ColumnDefinition index() Add an index
|
||||
* @method ColumnDefinition nullable(bool $value = true) Allow NULL values to be inserted into the column
|
||||
* @method ColumnDefinition primary() Add a primary index
|
||||
* @method ColumnDefinition spatialIndex() Add a spatial index
|
||||
* @method ColumnDefinition storedAs(string $expression) Create a stored generated column (MySQL)
|
||||
* @method ColumnDefinition unique() Add a unique index
|
||||
* @method ColumnDefinition unique() Add a unique index
|
||||
* @method ColumnDefinition unsigned() Set the INTEGER column as UNSIGNED (MySQL)
|
||||
* @method ColumnDefinition useCurrent() Set the TIMESTAMP column to use CURRENT_TIMESTAMP as default value
|
||||
* @method ColumnDefinition useCurrent() Set the TIMESTAMP column to use CURRENT_TIMESTAMP as default value
|
||||
* @method ColumnDefinition virtualAs(string $expression) Create a virtual generated column (MySQL)
|
||||
*/
|
||||
class ColumnDefinition extends Fluent
|
||||
{
|
||||
//
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -25,10 +26,7 @@ class ChangeColumn
|
||||
/**
|
||||
* Compile a change column command into a series of SQL statements.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return array
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
@ -48,7 +46,7 @@ class ChangeColumn
|
||||
$schema = $connection->getDoctrineSchemaManager()
|
||||
);
|
||||
|
||||
if ($tableDiff !== false) {
|
||||
if (false !== $tableDiff) {
|
||||
return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
|
||||
}
|
||||
|
||||
@ -58,16 +56,14 @@ class ChangeColumn
|
||||
/**
|
||||
* Get the Doctrine table difference for the given changes.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff|bool
|
||||
*/
|
||||
protected static function getChangedDiff($grammar, Blueprint $blueprint, SchemaManager $schema)
|
||||
{
|
||||
$current = $schema->listTableDetails($grammar->getTablePrefix().$blueprint->getTable());
|
||||
$current = $schema->listTableDetails($grammar->getTablePrefix() . $blueprint->getTable());
|
||||
|
||||
return (new Comparator)->diffTable(
|
||||
return (new Comparator())->diffTable(
|
||||
$current,
|
||||
static::getTableWithColumnChanges($blueprint, $current)
|
||||
);
|
||||
@ -76,8 +72,6 @@ class ChangeColumn
|
||||
/**
|
||||
* Get a copy of the given Doctrine table after making the column changes.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @return \Doctrine\DBAL\Schema\Table
|
||||
*/
|
||||
protected static function getTableWithColumnChanges(Blueprint $blueprint, Table $table)
|
||||
@ -92,7 +86,7 @@ class ChangeColumn
|
||||
// use some different terminology for various column attributes on the tables.
|
||||
foreach ($fluent->getAttributes() as $key => $value) {
|
||||
if (! is_null($option = static::mapFluentOptionToDoctrine($key))) {
|
||||
if (method_exists($column, $method = 'set'.ucfirst($option))) {
|
||||
if (method_exists($column, $method = 'set' . ucfirst($option))) {
|
||||
$column->{$method}(static::mapFluentValueToDoctrine($option, $value));
|
||||
}
|
||||
}
|
||||
@ -105,8 +99,6 @@ class ChangeColumn
|
||||
/**
|
||||
* Get the Doctrine column instance for a column change.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @param \Hyperf\Utils\Fluent $fluent
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
protected static function getDoctrineColumn(Table $table, Fluent $fluent)
|
||||
@ -120,7 +112,6 @@ class ChangeColumn
|
||||
/**
|
||||
* Get the Doctrine column change options.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $fluent
|
||||
* @return array
|
||||
*/
|
||||
protected static function getDoctrineColumnChangeOptions(Fluent $fluent)
|
||||
@ -131,7 +122,7 @@ class ChangeColumn
|
||||
$options['length'] = static::calculateDoctrineTextLength($fluent['type']);
|
||||
}
|
||||
|
||||
if ($fluent['type'] === 'json') {
|
||||
if ('json' === $fluent['type']) {
|
||||
$options['customSchemaOptions'] = [
|
||||
'collation' => '',
|
||||
];
|
||||
@ -143,7 +134,7 @@ class ChangeColumn
|
||||
/**
|
||||
* Get the doctrine column type.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
* @return \Doctrine\DBAL\Types\Type
|
||||
*/
|
||||
protected static function getDoctrineColumnType($type)
|
||||
@ -172,7 +163,7 @@ class ChangeColumn
|
||||
/**
|
||||
* Calculate the proper column length to force the Doctrine text type.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $type
|
||||
* @return int
|
||||
*/
|
||||
protected static function calculateDoctrineTextLength($type)
|
||||
@ -190,7 +181,7 @@ class ChangeColumn
|
||||
/**
|
||||
* Get the matching Doctrine option for a given Fluent attribute name.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string $attribute
|
||||
* @return string|null
|
||||
*/
|
||||
protected static function mapFluentOptionToDoctrine($attribute)
|
||||
@ -213,12 +204,10 @@ class ChangeColumn
|
||||
/**
|
||||
* Get the matching Doctrine value for a given Fluent attribute.
|
||||
*
|
||||
* @param string $option
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
* @param string $option
|
||||
*/
|
||||
protected static function mapFluentValueToDoctrine($option, $value)
|
||||
{
|
||||
return $option === 'notnull' ? ! $value : $value;
|
||||
return 'notnull' === $option ? ! $value : $value;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -38,9 +39,6 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a rename column command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @return array
|
||||
*/
|
||||
public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
@ -51,9 +49,6 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a change column command into a series of SQL statements.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @return array
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
@ -66,8 +61,6 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile a foreign key command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileForeign(Blueprint $blueprint, Fluent $command)
|
||||
@ -88,17 +81,17 @@ abstract class Grammar extends BaseGrammar
|
||||
'foreign key (%s) references %s (%s)',
|
||||
$this->columnize($command->columns),
|
||||
$this->wrapTable($command->on),
|
||||
$this->columnize((array)$command->references)
|
||||
$this->columnize((array) $command->references)
|
||||
);
|
||||
|
||||
// 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)) {
|
||||
if (! is_null($command->onDelete)) {
|
||||
$sql .= " on delete {$command->onDelete}";
|
||||
}
|
||||
|
||||
if (!is_null($command->onUpdate)) {
|
||||
if (! is_null($command->onUpdate)) {
|
||||
$sql .= " on update {$command->onUpdate}";
|
||||
}
|
||||
|
||||
@ -109,7 +102,6 @@ abstract class Grammar extends BaseGrammar
|
||||
* Add a prefix to an array of values.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function prefixArray($prefix, array $values)
|
||||
@ -122,7 +114,6 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Wrap a table in keyword identifiers.
|
||||
*
|
||||
* @param mixed $table
|
||||
* @return string
|
||||
*/
|
||||
public function wrapTable($table)
|
||||
@ -136,7 +127,7 @@ abstract class Grammar extends BaseGrammar
|
||||
* Wrap a value in keyword identifiers.
|
||||
*
|
||||
* @param \Hyperf\Database\Query\Expression|string $value
|
||||
* @param bool $prefixAlias
|
||||
* @param bool $prefixAlias
|
||||
* @return string
|
||||
*/
|
||||
public function wrap($value, $prefixAlias = false)
|
||||
@ -150,8 +141,6 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Create an empty Doctrine DBAL TableDiff from the Blueprint.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
public function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema)
|
||||
@ -186,7 +175,6 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Compile the blueprint's column definitions.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @return array
|
||||
*/
|
||||
protected function getColumns(Blueprint $blueprint)
|
||||
@ -208,7 +196,6 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Get the SQL for the column data type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function getType(Fluent $column)
|
||||
@ -220,8 +207,6 @@ abstract class Grammar extends BaseGrammar
|
||||
* Add the column modifiers to the definition.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function addModifiers($sql, Blueprint $blueprint, Fluent $column)
|
||||
@ -238,8 +223,7 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Get the primary key command if it exists on the blueprint.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @return \Hyperf\Utils\Fluent|null
|
||||
*/
|
||||
protected function getCommandByName(Blueprint $blueprint, $name)
|
||||
@ -254,7 +238,6 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Get all of the commands with a given name.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
@ -268,7 +251,6 @@ abstract class Grammar extends BaseGrammar
|
||||
/**
|
||||
* Format a value so that it can be used in "default" clauses.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefaultValue($value)
|
||||
@ -278,7 +260,7 @@ abstract class Grammar extends BaseGrammar
|
||||
}
|
||||
|
||||
return is_bool($value)
|
||||
? "'" . (int)$value . "'"
|
||||
: "'" . (string)$value . "'";
|
||||
? "'" . (int) $value . "'"
|
||||
: "'" . (string) $value . "'";
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -57,9 +58,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @return string
|
||||
*/
|
||||
public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
@ -92,8 +90,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile an add column command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
||||
@ -106,8 +102,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a primary key command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compilePrimary(Blueprint $blueprint, Fluent $command)
|
||||
@ -120,8 +114,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a unique key command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
||||
@ -132,8 +124,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a plain index key command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
||||
@ -144,8 +134,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a spatial index key command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)
|
||||
@ -156,8 +144,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a drop table command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
||||
@ -168,8 +154,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a drop table (if exists) command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
|
||||
@ -180,8 +164,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a drop column command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
|
||||
@ -194,8 +176,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a drop primary key command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
|
||||
@ -206,8 +186,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a drop unique key command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
||||
@ -220,8 +198,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a drop index command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
||||
@ -234,8 +210,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a drop spatial index command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropSpatialIndex(Blueprint $blueprint, Fluent $command)
|
||||
@ -246,8 +220,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a drop foreign key command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
|
||||
@ -260,8 +232,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a rename table command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRename(Blueprint $blueprint, Fluent $command)
|
||||
@ -274,8 +244,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile a rename index command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRenameIndex(Blueprint $blueprint, Fluent $command)
|
||||
@ -291,7 +259,7 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile the SQL needed to drop all tables.
|
||||
*
|
||||
* @param array $tables
|
||||
* @param array $tables
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropAllTables($tables)
|
||||
@ -302,7 +270,7 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile the SQL needed to drop all views.
|
||||
*
|
||||
* @param array $views
|
||||
* @param array $views
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropAllViews($views)
|
||||
@ -353,7 +321,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a spatial Geometry type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
public function typeGeometry(Fluent $column)
|
||||
@ -364,7 +331,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a spatial Point type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
public function typePoint(Fluent $column)
|
||||
@ -375,7 +341,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a spatial LineString type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
public function typeLineString(Fluent $column)
|
||||
@ -386,7 +351,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a spatial Polygon type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
public function typePolygon(Fluent $column)
|
||||
@ -397,7 +361,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a spatial GeometryCollection type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
public function typeGeometryCollection(Fluent $column)
|
||||
@ -408,7 +371,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a spatial MultiPoint type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
public function typeMultiPoint(Fluent $column)
|
||||
@ -419,7 +381,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a spatial MultiLineString type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
public function typeMultiLineString(Fluent $column)
|
||||
@ -430,7 +391,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a spatial MultiPolygon type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
public function typeMultiPolygon(Fluent $column)
|
||||
@ -442,8 +402,8 @@ class MySqlGrammar extends Grammar
|
||||
* Create the main create table clause.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCreateTable($blueprint, $command, $connection)
|
||||
@ -460,8 +420,6 @@ class MySqlGrammar extends Grammar
|
||||
* Append the character set specifications to a command.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint)
|
||||
@ -471,7 +429,7 @@ class MySqlGrammar extends Grammar
|
||||
// table is being created on. We will add these to the create table query.
|
||||
if (isset($blueprint->charset)) {
|
||||
$sql .= ' default character set ' . $blueprint->charset;
|
||||
} elseif (!is_null($charset = $connection->getConfig('charset'))) {
|
||||
} elseif (! is_null($charset = $connection->getConfig('charset'))) {
|
||||
$sql .= ' default character set ' . $charset;
|
||||
}
|
||||
|
||||
@ -480,7 +438,7 @@ class MySqlGrammar extends Grammar
|
||||
// connection that the query is targeting. We'll add it to this SQL query.
|
||||
if (isset($blueprint->collation)) {
|
||||
$sql .= " collate '{$blueprint->collation}'";
|
||||
} elseif (!is_null($collation = $connection->getConfig('collation'))) {
|
||||
} elseif (! is_null($collation = $connection->getConfig('collation'))) {
|
||||
$sql .= " collate '{$collation}'";
|
||||
}
|
||||
|
||||
@ -491,15 +449,13 @@ class MySqlGrammar extends Grammar
|
||||
* Append the engine specifications to a command.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCreateEngine($sql, Connection $connection, Blueprint $blueprint)
|
||||
{
|
||||
if (isset($blueprint->engine)) {
|
||||
return $sql . ' engine = ' . $blueprint->engine;
|
||||
} elseif (!is_null($engine = $connection->getConfig('engine'))) {
|
||||
} elseif (! is_null($engine = $connection->getConfig('engine'))) {
|
||||
return $sql . ' engine = ' . $engine;
|
||||
}
|
||||
|
||||
@ -509,8 +465,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Compile an index creation command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
@ -529,7 +483,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a char type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeChar(Fluent $column)
|
||||
@ -540,7 +493,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a string type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeString(Fluent $column)
|
||||
@ -551,7 +503,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeText(Fluent $column)
|
||||
@ -562,7 +513,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a medium text type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumText(Fluent $column)
|
||||
@ -573,7 +523,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a long text type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeLongText(Fluent $column)
|
||||
@ -584,7 +533,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a big integer type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBigInteger(Fluent $column)
|
||||
@ -595,7 +543,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for an integer type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeInteger(Fluent $column)
|
||||
@ -606,7 +553,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a medium integer type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumInteger(Fluent $column)
|
||||
@ -617,7 +563,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
@ -628,7 +573,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
@ -639,7 +583,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
@ -650,7 +593,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a double type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDouble(Fluent $column)
|
||||
@ -665,7 +607,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a decimal type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDecimal(Fluent $column)
|
||||
@ -676,7 +617,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a boolean type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBoolean(Fluent $column)
|
||||
@ -687,7 +627,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for an enumeration type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
@ -698,7 +637,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a json type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJson(Fluent $column)
|
||||
@ -709,7 +647,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a jsonb type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJsonb(Fluent $column)
|
||||
@ -720,7 +657,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a date type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDate(Fluent $column)
|
||||
@ -731,7 +667,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTime(Fluent $column)
|
||||
@ -744,7 +679,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a date-time (with time zone) type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTimeTz(Fluent $column)
|
||||
@ -755,7 +689,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
@ -766,7 +699,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a time (with time zone) type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimeTz(Fluent $column)
|
||||
@ -777,7 +709,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
@ -790,7 +721,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a timestamp (with time zone) type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestampTz(Fluent $column)
|
||||
@ -801,7 +731,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a year type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeYear(Fluent $column)
|
||||
@ -812,7 +741,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a binary type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBinary(Fluent $column)
|
||||
@ -823,7 +751,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a uuid type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeUuid(Fluent $column)
|
||||
@ -834,7 +761,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for an IP address type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeIpAddress(Fluent $column)
|
||||
@ -845,7 +771,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Create the column definition for a MAC address type.
|
||||
*
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMacAddress(Fluent $column)
|
||||
@ -856,13 +781,11 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for a generated virtual column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyVirtualAs(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (!is_null($column->virtualAs)) {
|
||||
if (! is_null($column->virtualAs)) {
|
||||
return " as ({$column->virtualAs})";
|
||||
}
|
||||
}
|
||||
@ -870,13 +793,11 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for a generated stored column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyStoredAs(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (!is_null($column->storedAs)) {
|
||||
if (! is_null($column->storedAs)) {
|
||||
return " as ({$column->storedAs}) stored";
|
||||
}
|
||||
}
|
||||
@ -884,8 +805,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for an unsigned column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyUnsigned(Blueprint $blueprint, Fluent $column)
|
||||
@ -898,13 +817,11 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for a character set column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyCharset(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (!is_null($column->charset)) {
|
||||
if (! is_null($column->charset)) {
|
||||
return ' character set ' . $column->charset;
|
||||
}
|
||||
}
|
||||
@ -912,13 +829,11 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for a collation column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (!is_null($column->collation)) {
|
||||
if (! is_null($column->collation)) {
|
||||
return " collate '{$column->collation}'";
|
||||
}
|
||||
}
|
||||
@ -926,8 +841,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for a nullable column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
||||
@ -940,13 +853,11 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for a default column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (!is_null($column->default)) {
|
||||
if (! is_null($column->default)) {
|
||||
return ' default ' . $this->getDefaultValue($column->default);
|
||||
}
|
||||
}
|
||||
@ -954,8 +865,6 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for an auto-increment column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
|
||||
@ -968,13 +877,11 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for a "first" column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyFirst(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (!is_null($column->first)) {
|
||||
if (! is_null($column->first)) {
|
||||
return ' first';
|
||||
}
|
||||
}
|
||||
@ -982,13 +889,11 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for an "after" column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyAfter(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (!is_null($column->after)) {
|
||||
if (! is_null($column->after)) {
|
||||
return ' after ' . $this->wrap($column->after);
|
||||
}
|
||||
}
|
||||
@ -996,13 +901,11 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for a "comment" column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyComment(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (!is_null($column->comment)) {
|
||||
if (! is_null($column->comment)) {
|
||||
return " comment '" . addslashes($column->comment) . "'";
|
||||
}
|
||||
}
|
||||
@ -1010,13 +913,11 @@ class MySqlGrammar extends Grammar
|
||||
/**
|
||||
* Get the SQL for a SRID column modifier.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifySrid(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if (!is_null($column->srid) && is_int($column->srid) && $column->srid > 0) {
|
||||
if (! is_null($column->srid) && is_int($column->srid) && $column->srid > 0) {
|
||||
return ' srid ' . $column->srid;
|
||||
}
|
||||
}
|
||||
@ -1029,7 +930,7 @@ class MySqlGrammar extends Grammar
|
||||
*/
|
||||
protected function wrapValue($value)
|
||||
{
|
||||
if ($value !== '*') {
|
||||
if ('*' !== $value) {
|
||||
return '`' . str_replace('`', '``', $value) . '`';
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -23,16 +24,13 @@ class RenameColumn
|
||||
/**
|
||||
* Compile a rename column command.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param \Hyperf\Database\Connection $connection
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return array
|
||||
*/
|
||||
public static function compile(Grammar $grammar, Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
{
|
||||
$column = $connection->getDoctrineColumn(
|
||||
$grammar->getTablePrefix().$blueprint->getTable(),
|
||||
$grammar->getTablePrefix() . $blueprint->getTable(),
|
||||
$command->from
|
||||
);
|
||||
|
||||
@ -50,11 +48,7 @@ class RenameColumn
|
||||
/**
|
||||
* Get a new column instance with the new column name.
|
||||
*
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @param \Hyperf\Database\Schema\Blueprint $blueprint
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
|
||||
* @param \Hyperf\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
protected static function getRenamedDiff(Grammar $grammar, Blueprint $blueprint, Fluent $command, Column $column, SchemaManager $schema)
|
||||
@ -69,9 +63,6 @@ class RenameColumn
|
||||
/**
|
||||
* Set the renamed columns on the table diff.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
|
||||
* @param \Hyperf\Utils\Fluent $command
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
protected static function setRenamedColumns(TableDiff $tableDiff, Fluent $command, Column $column)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
@ -16,12 +17,12 @@ class MySqlBuilder extends Builder
|
||||
/**
|
||||
* Determine if the given table exists.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTable($table)
|
||||
{
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
$table = $this->connection->getTablePrefix() . $table;
|
||||
|
||||
return count($this->connection->select(
|
||||
$this->grammar->compileTableExists(),
|
||||
@ -32,12 +33,12 @@ class MySqlBuilder extends Builder
|
||||
/**
|
||||
* Get the column listing for a given table.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function getColumnListing($table)
|
||||
{
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
$table = $this->connection->getTablePrefix() . $table;
|
||||
|
||||
$results = $this->connection->select(
|
||||
$this->grammar->compileColumnListing(),
|
||||
@ -49,8 +50,6 @@ class MySqlBuilder extends Builder
|
||||
|
||||
/**
|
||||
* Drop all tables from the database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropAllTables()
|
||||
{
|
||||
@ -77,8 +76,6 @@ class MySqlBuilder extends Builder
|
||||
|
||||
/**
|
||||
* Drop all views from the database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropAllViews()
|
||||
{
|
||||
@ -104,7 +101,7 @@ class MySqlBuilder extends Builder
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllTables()
|
||||
public function getAllTables()
|
||||
{
|
||||
return $this->connection->select(
|
||||
$this->grammar->compileGetAllTables()
|
||||
|
@ -12,6 +12,7 @@
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"psr/simple-cache": "^1.0",
|
||||
"hyperf/database": "dev-master",
|
||||
"hyperf/di": "dev-master",
|
||||
"hyperf/event": "dev-master",
|
||||
|
48
src/db-connection/src/Cache/Cacheable.php
Normal file
48
src/db-connection/src/Cache/Cacheable.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://hyperf.org
|
||||
* @document https://wiki.hyperf.org
|
||||
* @contact group@hyperf.org
|
||||
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Hyperf\DbConnection\Cache;
|
||||
|
||||
use Hyperf\Framework\ApplicationContext;
|
||||
|
||||
trait Cacheable
|
||||
{
|
||||
/**
|
||||
* @return self|null
|
||||
*/
|
||||
public static function findFromCache($id)
|
||||
{
|
||||
$container = ApplicationContext::getContainer();
|
||||
$manager = $container->get(Manager::class);
|
||||
|
||||
return $manager->findFromCache($id, static::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Hyperf\Database\Model\Collection
|
||||
*/
|
||||
public static function findManyFromCache($ids)
|
||||
{
|
||||
$container = ApplicationContext::getContainer();
|
||||
$manager = $container->get(Manager::class);
|
||||
|
||||
return $manager->findManyFromCache($ids, static::class);
|
||||
}
|
||||
|
||||
public function deleteCache()
|
||||
{
|
||||
$container = ApplicationContext::getContainer();
|
||||
$manager = $container->get(Manager::class);
|
||||
|
||||
return $manager->destroy([$this->getKey()], get_called_class());
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user