View Source PhpAssocMap (PhpAssocMap v2.0.1)

Summary

Functions

Gets the document AST from leex and yecc parser. The ast is automatically obtain from to_tuple/1 and to_map/1

Converts a map structure to an associative array string. The string key and value are single quoted

Converts a keyword list structure to an associative array string. The string key and value are single quoted

Parses an associative array string (or charlist) to a key-valued map. Both single and double quotes are supported.

Parses an associative array string (or charlist) to a key-valued keyword list. Both single and double quotes are supported.

Functions

@spec ast(charlist() | binary()) :: [tuple()]

Gets the document AST from leex and yecc parser. The ast is automatically obtain from to_tuple/1 and to_map/1

## Exmples

  iex> PhpAssocMap.ast("['key'=>['another_key'=>'value']]")
  [{"key", [{"another_key", "value"}]}]
@spec from_map(map()) :: binary()

Converts a map structure to an associative array string. The string key and value are single quoted

The returned document will not be formatted yet. Use PhpAssocMap.Exploder.explode/1 or PhpAssocMap.Exploder.explode/2 to have it formatted.

## Exmples

  iex> PhpAssocMap.from_map(%{"key" => %{"another_key" => "value"}})
  "['key'=>['another_key'=>'value']]"
@spec from_tuple([tuple()]) :: binary()

Converts a keyword list structure to an associative array string. The string key and value are single quoted

The returned document will not be formatted yet. Use PhpAssocMap.Exploder.explode/1 or PhpAssocMap.Exploder.explode/2 to have it formatted.

## Exmples

  iex> PhpAssocMap.from_tuple([{"key", [{"another_key", "value"}]}])
  "['key'=>['another_key'=>'value']]"
@spec to_map(binary() | charlist()) :: any()

Parses an associative array string (or charlist) to a key-valued map. Both single and double quotes are supported.

Note: If the string starts with <?php return, it'll be ignored

## Exemples

  iex> PhpAssocMap.to_map("['key' => ['another_key' => 'value']]")
  %{"key" => %{"another_key" => "value"}}

  iex> PhpAssocMap.to_map("<?php return ['key' => ['another_key' => 'value']];")
  %{"key" => %{"another_key" => "value"}}
@spec to_tuple(binary() | charlist()) :: [tuple()]

Parses an associative array string (or charlist) to a key-valued keyword list. Both single and double quotes are supported.

Note: If the string starts with <?php return, it'll be ignored

## Exemples

  iex> PhpAssocMap.to_tuple("['key' => ['another_key' => 'value']]")
  [{"key", [{"another_key", "value"}]}]

  iex> PhpAssocMap.to_tuple("<?php return ['key' => ['another_key' => 'value']];")
  [{"key", [{"another_key", "value"}]}]