Transform an array into a PHP file content string

@param array $array Array to transform
@return string
434793
private static function arrayToFile($array) {
        $strFile = "<?php" . chr(13) . chr(10) . chr(13) . chr(10) . "return [" . chr(13) . chr(10);
        $strValue = \Sirgrimorum\CrudGenerator\CrudGenerator::arrayToFileWrite($array, 0);
        $strFile .= $strValue . "];";
        return $strFile;
    }
693262
public static function keyedArray($array) {
        if(is_array($array)) {
            $string = '[ ';
            foreach($array as $key => $item) {
                if(!is_string($item)) {
                    $item = self::keyedArray($item);
                }
                $string .= $key . ' => ' . $item;
                if($item !== last($array)) {
                    $string .= ', ';
                }
            }
            $string .= ' ]';

            return $string;
        } else {
            if(is_object($array)) {
                return get_class($array);
            } else {
                if(is_null($array)) {
                    return 'Null';
                } else {
                    return 'Unknown';
                }
            }
        }
    }
958725
protected function castString($array)
    {
        if (is_string($array)) return $array;

        $string = '';
        $i = 0;
        foreach ($array as $key => $val) {
            //Add values separated by comma
            //prepend the key string, if it's an associative key
            //Check if the value itself is another array to be converted to string
            $string .= ($i === $key ? '' : "$key - ") . $this->castString($val) . ', ';
            $i++;
        }

        //Remove trailing comma and space
        $string = rtrim($string, ', ');

        return $string;
    }
1374498
protected function buildMapDefinitions(array $array) {
		$result = [];
		foreach ($array as $alias => $value) {
			$result[] = "\t\t\t" . "'" . str_replace("'", "\'", $alias) . "' => " . $value . ',';
		}

		return implode(PHP_EOL, $result);
	}
649750
public function arrayToUnorderedList(array $array): string
    {
        $out = '<ul>';
        foreach ($array as $key => $elem) {
            if (!is_array($elem)) {
                $out = $out . "<li><span>{$key}: " . h($elem) . '</span></li>';
            } else {
                $out = $out . "<li><span>{$key}</span>" . $this->arrayToUnorderedList($elem) . '</li>';
            }
        }
        $out .= '</ul>';

        return $out;
    }
246569
protected static function prepareArrayLines(array $array)
    {
        $isAssoc = Arr::isAssoc($array);

        array_walk($array, function (&$value, $index, $withIndexes = false) {
            if (is_array($value)) {
                $value = self::formatArray($value);
            } else {
                $value = self::formatScalar($value);
            }

            if ($withIndexes) {
                $value = self::formatScalar($index) . ' => ' . $value;
            }
        }, $isAssoc);

        return $array;
    }
1093868
static public function stringify(array $array)
    {
        $result = array();
        foreach ($array as $key => $value) {
            $result[] = sprintf('%s=%s', $key, $value);
        }
        return implode('&', $result);
    }
124296
public static function convert(array $array)
    {
        if (function_exists('yaml_emit')) {
            $yaml = yaml_emit($array);

            // PHP-Yaml adds strange separators to the outputted YAML, we do
            // some manipulation of the outputted string to remove these.
            $yaml = explode("\n", $yaml);
            array_shift($yaml);
            array_pop($yaml);
            array_pop($yaml);

            return implode("\n", $yaml);
        }

        return spyc_dump($array);
    }
631892
public static function escapeArray( $array )
    {
        $db = eZDB::instance();
        $out = array();
        foreach( $array as $key => $value )
        {
            if ( is_array( $value ) )
            {
                $tmp = array();
                foreach( $value as $valueItem )
                {
                    $tmp[] = $db->escapeString( $valueItem );
                }
                $out[$key] = $tmp;
                unset( $tmp );
            }
            else
                $out[$key] = $db->escapeString( $value );
        }
        return $out;
    }
694096
protected static function TranslationArrayExport($array)
    {
        $output = "[\n";
        foreach ($array as $key => $value) {
            /**
             * Escape '
             */
            $key    = str_replace('\'', '\\\'', $key);
            $value  = str_replace('\'', '\\\'', $value);
            $output .= "\t'{$key}' => '{$value}',\n";
        }

        return $output . "];";
    }
1040289
private function phpEncodeArray(array $array)
    {
        $isPlainArray = function (array $value) {
            return ((count($value) === 0)
                || (
                    (array_keys($value) === range(0, count($value) - 1))
                    && (0 === count(array_filter(array_keys($value), 'is_string'))))
            );
        };

        if ($isPlainArray($array)) {
            return '['.implode(', ', array_map([$this, 'phpEncodeValue'], $array)).']';
        }

        return '['.implode(', ', array_map(function ($key) use ($array) {
            return $this->phpEncodeValue($key).' => '.$this->phpEncodeValue($array[$key]);
        }, array_keys($array))).']';
    }
273312
private static function encodeArray(array $array)
    {
        // If it is an associative array, treat it as an object.
        if (!empty($array) && array_keys($array) !== range(0, count($array) - 1)) {
            return self::encodeMap($array);
        }

        // Differentiate on the array length.
        if (count($array) < 16) {
            // fixarray
            $prefix = bindec(1001) * 16 + count($array);
        } elseif (count($array) < pow(2, 16)) {
            // array 16
            $prefix = 0xdc * 256 * 256;
            $prefix += count($array);
        } elseif (count($array) < pow(2, 32)) {
            // array 32
            $prefix = 0xdd * 256 * 256 * 256 * 256;
            $prefix += count($array);
        } else {
            throw new UnencodeableException('Array with more then 2^32 elements included cannot be encoded.', 1);
        }

        // Byte encode it.
        $result = pack('H*', dechex($prefix));

        // Loop every item of the array.
        foreach (array_values($array) as $item) {
            // Concatenate everything.
            $result .= self::encode($item);
        }

        // Return the result.
        return $result;
    }
239692
private function getArrayValue(array $array)
    {
        $value = [];
        foreach ($array as $item) {
            if ($item instanceof Keyword) {
                $item = $this->getKeyword($item);
            }
            $value[] = trim(str_replace(array("\n", "\r"), '', strip_tags('' . $item)));
        }

        array_walk($value, function(&$item) { return trim(str_replace(array("\n", "\r"), '', strip_tags('' . $item))); });

        return implode(',', array_filter($value));
    }
788707
public function doCapture(array $array)
    {
        $WSRequest = array(
            'transactionID'   => $array['transactionID'],
            'payment'         => $this->payment($array['payment']),
            'privateDataList' => $this->privateData,
            'sequenceNumber'  => $array['sequenceNumber']
        );
        return $this->webServiceRequest($array, $WSRequest, self::DIRECT_API, 'doCapture');
    }
364575
protected static function encodeArray($array)
    {
        if (Arrays::isAssoc($array)) {
            $output = [];
            foreach ($array as $key => $val) {
                $output[] = $key . ':' . \addcslashes($val, ': ');
            }

            return self::encodeString(\implode(' ', $output));
        }

        $output = [];
        foreach ($array as $val) {
            $output[] = \addcslashes($val, ': ');
        }

        return self::encodeString(\implode(' ', $output));
    }
1159536
public function copyToArray(array &$array)
    {
        $array['developer']              = $this->developer;
        $array['clientId']               = $this->clientId;
        $array['clientIdAlias']          = $this->clientIdAlias;
        $array['clientIdAliasEnabled']   = $this->clientIdAliasEnabled;
        $array['clientSecret']           = $this->clientSecret;
        $array['clientType']             = LanguageUtility::toString($this->clientType);
        $array['redirectUris']           = $this->redirectUris;
        $array['responseTypes']          = LanguageUtility::convertArrayToStringArray($this->responseTypes);
        $array['grantTypes']             = LanguageUtility::convertArrayToStringArray($this->grantTypes);
        $array['applicationType']        = LanguageUtility::toString($this->applicationType);
        $array['contacts']               = $this->contacts;
        $array['clientName']             = $this->clientName;
        $array['clientNames']            = LanguageUtility::convertArrayOfArrayCopyableToArray($this->clientNames);
        $array['logoUri']                = $this->logoUri;
        $array['logoUris']               = LanguageUtility::convertArrayOfArrayCopyableToArray($this->logoUris);
        $array['clientUri']              = $this->clientUri;
        $array['clientUris']             = LanguageUtility::convertArrayOfArrayCopyableToArray($this->clientUris);
        $array['policyUri']              = $this->policyUri;
        $array['policyUris']             = LanguageUtility::convertArrayOfArrayCopyableToArray($this->policyUris);
        $array['tosUri']                 = $this->tosUri;
        $array['tosUris']                = LanguageUtility::convertArrayOfArrayCopyableToArray($this->tosUris);
        $array['jwksUri']                = $this->jwksUri;
        $array['jwks']                   = $this->jwks;
        $array['sectorIdentifier']       = $this->sectorIdentifier;
        $array['subjectType']            = LanguageUtility::toString($this->subjectType);
        $array['idTokenSignAlg']         = LanguageUtility::toString($this->idTokenSignAlg);
        $array['idTokenEncryptionAlg']   = LanguageUtility::toString($this->idTokenEncryptionAlg);
        $array['idTokenEncryptionEnc']   = LanguageUtility::toString($this->idTokenEncryptionEnc);
        $array['userInfoSignAlg']        = LanguageUtility::toString($this->userInfoSignAlg);
        $array['userInfoEncryptionAlg']  = LanguageUtility::toString($this->userInfoEncryptionAlg);
        $array['userInfoEncryptionEnc']  = LanguageUtility::toString($this->userInfoEncryptionEnc);
        $array['requestSignAlg']         = LanguageUtility::toString($this->requestSignAlg);
        $array['requestEncryptionAlg']   = LanguageUtility::toString($this->requestEncryptionAlg);
        $array['requestEncryptionEnc']   = LanguageUtility::toString($this->requestEncryptionEnc);
        $array['tokenAuthMethod']        = LanguageUtility::toString($this->tokenAuthMethod);
        $array['tokenAuthSignAlg']       = LanguageUtility::toString($this->tokenAuthSignAlg);
        $array['defaultMaxAge']          = LanguageUtility::orZero($this->defaultMaxAge);
        $array['authTimeRequired']       = $this->authTimeRequired;
        $array['defaultAcrs']            = $this->defaultAcrs;
        $array['loginUri']               = $this->loginUri;
        $array['requestUris']            = $this->requestUris;
        $array['description']            = $this->description;
        $array['descriptions']           = LanguageUtility::convertArrayOfArrayCopyableToArray($this->descriptions);
        $array['createdAt']              = LanguageUtility::orZero($this->createdAt);
        $array['modifiedAt']             = LanguageUtility::orZero($this->modifiedAt);
        $array['extension']              = LanguageUtility::convertArrayCopyableToArray($this->extension);
        $array['tlsClientAuthSubjectDn'] = $this->tlsClientAuthSubjectDn;
        $array['tlsClientCertificateBoundAccessTokens'] = $this->tlsClientCertificateBoundAccessTokens;
        $array['selfSignedCertificateKeyId']            = $this->selfSignedCertificateKeyId;
        $array['softwareId']                            = $this->softwareId;
        $array['softwareVersion']                       = $this->softwareVersion;
        $array['authorizationSignAlg']                  = LanguageUtility::toString($this->authorizationSignAlg);
        $array['authorizationEncryptionAlg']            = LanguageUtility::toString($this->authorizationEncryptionAlg);
        $array['authorizationEncryptionEnc']            = LanguageUtility::toString($this->authorizationEncryptionEnc);
    }
518453
static function build_line($array)
    {
        if (self::$data_sep)
        {
            $line = '';
            foreach ($array as $k => $v)
            {
                $line .= $k . self::$data_sep . $v . self::$col_sep;
            }
            return rtrim($line, self::$col_sep);
        }
        else
        {
            return implode(self::$col_sep, $array);
        }
    }