diff --git a/app/Cfnpp/Expression/Token/OperatorBinary.php b/app/Cfnpp/Expression/Token/OperatorBinary.php index a0b82fb..a45b549 100644 --- a/app/Cfnpp/Expression/Token/OperatorBinary.php +++ b/app/Cfnpp/Expression/Token/OperatorBinary.php @@ -22,7 +22,9 @@ class OperatorBinary extends TokenBinary implements ICloudformationNative public const OPERATORS = [ 'and', 'or', - 'eq' + 'eq', + 'concat', + 'select' ]; /** @@ -147,8 +149,32 @@ class OperatorBinary extends TokenBinary implements ICloudformationNative return null; + case 'concat': + if (is_scalar($value1) && is_scalar($value2)) + { + return $value2.$value1; + } + elseif ($value1 instanceof Parameter && is_scalar($value2) && empty($value2)) + { + return $value1; + } + elseif ($value2 instanceof Parameter && is_scalar($value1) && empty($value1)) + { + return $value2; + } + + return null; + + case 'select': + if (is_scalar($value1) && is_array($value2)) + { + return $value2[$value1]; + } + + return null; + default: - throw new \Exception('Missing implementation for unary operator: '.$this->getOperator()); + throw new \Exception('Missing implementation for binary operator: '.$this->getOperator()); } } @@ -174,8 +200,12 @@ class OperatorBinary extends TokenBinary implements ICloudformationNative return ['Fn::Or' => [$value1, $value2]]; case 'eq': return ['Fn::Equals' => [$value1, $value2]]; + case 'concat': + return ['Fn::Join' => ['', [$value2, $value1]]]; + case 'select': + return ['Fn::Select' => [$value1, $value2]]; default: - throw new \Exception('Missing implementation for unary operator: '.$this->getOperator()); + throw new \Exception('Operator cannot be applied to parameters: '.$this->getOperator()); } } }