-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes a bug where you cannot use a runtime operator in a SQL query
- Loading branch information
Showing
8 changed files
with
144 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace RulerZ\Target\Operators; | ||
|
||
class CompileTimeOperator | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $compiledOperator; | ||
|
||
public function __construct($compiled) | ||
{ | ||
$this->compiledOperator = $compiled; | ||
} | ||
|
||
public function format($shouldBreakString) | ||
{ | ||
return $this->compiledOperator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace RulerZ\Target\Operators; | ||
|
||
class OperatorTools | ||
{ | ||
public static function inlineMixedInstructions(array $instructions, $operator = null) | ||
{ | ||
$elements = []; | ||
|
||
foreach ($instructions as $instruction) { | ||
if ($instruction instanceof RuntimeOperator) { | ||
$elements[] = $instruction->format(true); | ||
} else if ($instruction instanceof CompileTimeOperator) { | ||
$elements[] = sprintf('%s', $instruction->format(false)); | ||
} else { | ||
$elements[] = sprintf('%s', $instruction); | ||
} | ||
} | ||
|
||
if (null === $operator) { | ||
return join('', $elements); | ||
} else { | ||
return join(' '.$operator.' ', $elements); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace RulerZ\Target\Operators; | ||
|
||
class RuntimeOperator | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $callable; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $arguments; | ||
|
||
public function __construct($callable, $arguments) | ||
{ | ||
$this->callable = $callable; | ||
$this->arguments = $arguments; | ||
} | ||
|
||
public function format($shouldBreakString) | ||
{ | ||
$formattedArguments = join(',', array_map(function ($argument) { | ||
if ('$' === $argument[0]) { | ||
return $argument; | ||
} else { | ||
return sprintf('"%s"', $argument); | ||
} | ||
}, $this->arguments)); | ||
|
||
if (true === $shouldBreakString) { | ||
return sprintf( | ||
'".call_user_func_array(%s, [%s])."', | ||
$this->callable, | ||
$formattedArguments | ||
); | ||
} else { | ||
return sprintf( | ||
'call_user_func_array(%s, [%s])', | ||
$this->callable, | ||
$formattedArguments | ||
); | ||
} | ||
} | ||
} |