Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/Target/Eloquent/Eloquent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ class Eloquent extends AbstractSqlTarget
*/
protected $allowEloquentBuilderAsQuery = false;

/**
* Preserve positional parameters.
*
* @var bool
*/
protected $preservePositionalParameters = false;

/**
* @param bool $allowEloquentBuilderAsQuery Whether to allow the execution target to be eloquent builder instead of query builder.
*/
public function __construct($allowEloquentBuilderAsQuery = false)
{
public function __construct(
$allowEloquentBuilderAsQuery = false,
$preservePositionalParameters = false
) {
parent::__construct();

$this->allowEloquentBuilderAsQuery = (bool) $allowEloquentBuilderAsQuery;
$this->preservePositionalParameters = (bool) $preservePositionalParameters;
}

/**
Expand All @@ -51,6 +61,12 @@ protected function getExecutorTraits()
*/
protected function createVisitor(Context $context)
{
return new EloquentVisitor($context, $this->getOperators(), $this->allowStarOperator, $this->allowEloquentBuilderAsQuery);
return new EloquentVisitor(
$context,
$this->getOperators(),
$this->allowStarOperator,
$this->allowEloquentBuilderAsQuery,
$this->preservePositionalParameters
);
}
}
29 changes: 27 additions & 2 deletions src/Target/Eloquent/EloquentVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace RulerZ\Target\Eloquent;

use RulerZ\Model;
use RulerZ\Compiler\Context;
use RulerZ\Target\GenericSqlVisitor;
use RulerZ\Target\Operators\Definitions as OperatorsDefinitions;
Expand All @@ -15,11 +16,35 @@ class EloquentVisitor extends GenericSqlVisitor
*/
protected $allowEloquentBuilderAsQuery = false;

public function __construct(Context $context, OperatorsDefinitions $operators, $allowStarOperator = true, $allowEloquentBuilderAsQuery = false)
{
/**
* Preserve positional parameters.
*
* @var bool
*/
protected $preservePositionalParameters = false;

/**
* @param bool $allowEloquentBuilderAsQuery Whether to allow the execution target to be eloquent builder instead of query builder.
*/
public function __construct(
Context $context,
OperatorsDefinitions $operators,
$allowStarOperator = true,
$allowEloquentBuilderAsQuery = false,
$preservePositionalParameters = false
) {
parent::__construct($context, $operators, $allowStarOperator);

$this->allowEloquentBuilderAsQuery = (bool) $allowEloquentBuilderAsQuery;
$this->preservePositionalParameters = (bool) $preservePositionalParameters;
}

/**
* {@inheritdoc}
*/
public function visitParameter(Model\Parameter $element, &$handle = null, $eldnah = null)
{
return $this->preservePositionalParameters ? '?' : ':'.$element->getName();
}

/**
Expand Down