Browse Source

Add concat/select operators

Adam Pippin 3 years ago
parent
commit
0737fcd74a
  1. 36
      app/Cfnpp/Expression/Token/OperatorBinary.php

36
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());
}
}
}

Loading…
Cancel
Save