src/PNDP/NixGenerator.php
public static function arrayMembersToAttrsMembers(array $array, $indentLevel, $format)
	{
		$expr = "";

		/* Convert inherit objects separately, since they have to be generated differently */

		$first = true;
		$haveInherits = false;
		$previousInherit = null;

		foreach($array as $key => $value)
		{
			if($value instanceof NixInherit)
			{
				$haveInherits = true;

				if($previousInherit === null || !$value->equals($previousInherit)) // If the current inherit applies to the same scope as the previous inherit we can merge them into a single inherit statement. If not, we must terminate it, and generate a new one
				{
					if($first)
						$first = false;
					else
						$expr .= ";\n";

					$expr .= NixGenerator::generateIndentation($indentLevel, $format).$value->toNixExpr($indentLevel, $format);
				}

				$expr .= " ".NixGenerator::objectKeyToAttrName($key);
				$previousInherit = $value;
			}
		}

		if($haveInherits)
			$expr .= ";\n"; // If we have inherits we must terminate it with a semicolon

		/* Process "ordinary" object members */

		foreach($array as $key => $value)
		{
			if(!($value instanceof NixInherit))
				$expr .= NixGenerator::generateIndentation($indentLevel, $format).NixGenerator::objectKeyToAttrName($key)." = ".NixGenerator::phpToIndentedNix($value, $indentLevel, $format).";\n";
		}

		return $expr;
	}
public static function arrayMembersToAttrsMembers(array $array, $indentLevel, $format)
	{
		$expr = "";

		/* Convert inherit objects separately, since they have to be generated differently */

		$first = true;
		$haveInherits = false;
		$previousInherit = null;

		foreach($array as $key => $value)
		{
			if($value instanceof NixInherit)
			{
				$haveInherits = true;

				if($previousInherit === null || !$value->equals($previousInherit)) // If the current inherit applies to the same scope as the previous inherit we can merge them into a single inherit statement. If not, we must terminate it, and generate a new one
				{
					if($first)
						$first = false;
					else
						$expr .= ";\n";

					$expr .= NixGenerator::generateIndentation($indentLevel, $format).$value->toNixExpr($indentLevel, $format);
				}

				$expr .= " ".NixGenerator::objectKeyToAttrName($key);
				$previousInherit = $value;
			}
		}

		if($haveInherits)
			$expr .= ";\n"; // If we have inherits we must terminate it with a semicolon

		/* Process "ordinary" object members */

		foreach($array as $key => $value)
		{
			if(!($value instanceof NixInherit))
				$expr .= NixGenerator::generateIndentation($indentLevel, $format).NixGenerator::objectKeyToAttrName($key)." = ".NixGenerator::phpToIndentedNix($value, $indentLevel, $format).";\n";
		}

		return $expr;
	}
public static function arrayMembersToAttrsMembers ( array $ array , $ indentLevel , $ format ) { $ expr = "" ; /* Convert inherit objects separately, since they have to be generated differently */ $ first = true ; $ haveInherits = false ; $ previousInherit = null ; foreach ( $ array as $ key => $ value ) { if ( $ value instanceof NixInherit ) { $ haveInherits = true ; if ( $ previousInherit === null || ! $ value -> equals ( $ previousInherit ) ) // If the current inherit applies to the same scope as the previous inherit we can merge them into a single inherit statement. If not, we must terminate it, and generate a new one { if ( $ first ) $ first = false ; else $ expr .= ";\n" ; $ expr .= NixGenerator :: generateIndentation ( $ indentLevel , $ format ) . $ value -> toNixExpr ( $ indentLevel , $ format ) ; } $ expr .= " " . NixGenerator :: objectKeyToAttrName ( $ key ) ; $ previousInherit = $ value ; } } if ( $ haveInherits ) $ expr .= ";\n" ; // If we have inherits we must terminate it with a semicolon /* Process "ordinary" object members */ foreach ( $ array as $ key => $ value ) { if ( ! ( $ value instanceof NixInherit ) ) $ expr .= NixGenerator :: generateIndentation ( $ indentLevel , $ format ) . NixGenerator :: objectKeyToAttrName ( $ key ) . " = " . NixGenerator :: phpToIndentedNix ( $ value , $ indentLevel , $ format ) . ";\n" ; } return $ expr ; }
Converts members of an array to members of an attribute set

@param array $array Array to convert
@param int $indentLevel The indentation level of the resulting sub expression
@param bool $format Indicates whether to nicely format to expression (i.e. generating whitespaces) or not
@return string A string containing the Nix attribute set members
Converts members of an array to members of an attribute set