Skip to content

Commit c40d652

Browse files
committed
added Alias type
1 parent e11ef9c commit c40d652

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/Alias.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace WikibaseSolutions\CypherDSL;
4+
5+
use WikibaseSolutions\CypherDSL\Types\AnyType;
6+
use function sprintf;
7+
8+
class Alias implements AnyType
9+
{
10+
/**
11+
* @var Variable The original variable to be aliased
12+
*/
13+
private Variable $original;
14+
15+
/**
16+
* @var Variable The new variable aliasing the original
17+
*/
18+
private Variable $variable;
19+
20+
/**
21+
* BinaryOperator constructor.
22+
*
23+
* @param Variable $original The original variable to be aliased
24+
* @param Variable $variable The new variable aliasing the original
25+
*/
26+
public function __construct(Variable $original, Variable $variable)
27+
{
28+
$this->original = $original;
29+
$this->variable = $variable;
30+
}
31+
32+
/**
33+
* @inheritDoc
34+
*/
35+
public function toQuery(): string
36+
{
37+
return sprintf("%s AS %s", $this->original->toQuery(), $this->variable->toQuery());
38+
}
39+
40+
/**
41+
* Gets the original variable of the alias.
42+
*
43+
* @return Variable
44+
*/
45+
public function getOriginal(): Variable
46+
{
47+
return $this->original;
48+
}
49+
50+
/**
51+
* Gets the variable from the alias.
52+
*
53+
* @return Variable
54+
*/
55+
public function getVariable(): Variable
56+
{
57+
return $this->variable;
58+
}
59+
}

0 commit comments

Comments
 (0)