/**
  * convert a line containing key value pairs into an array
  *
  * @param  mixed $data
  *         the data to convert
  * @param  string $kvSeparator
  *         the separator between keys and values
  * @param  string $valueSeparator
  *         the separator between values and the next key
  * @return mixed
  *         will return the same time that $data was
  */
 public static function from($data, $kvSeparator, $valueSeparator)
 {
     $method = MapTypeToMethod::using($data, self::$dispatchMap);
     return self::$method($data, $kvSeparator, $valueSeparator);
 }
 /**
  * convert a piece of data to be a real PHP array
  *
  * @param  mixed $data
  *         the data to convert
  * @return array
  */
 public static function from($data)
 {
     $method = MapTypeToMethod::using($data, self::$dispatchMap);
     return self::$method($data);
 }
 /**
  * @covers ::using
  */
 public function testReturnsFallbackWhenNothingMatches()
 {
     // ----------------------------------------------------------------
     // setup your test
     $data = "hello";
     $map = [];
     $expectedResult = "nothingMatchesTheInputType";
     // ----------------------------------------------------------------
     // perform the change
     $actualResult = MapTypeToMethod::using($data, $map);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedResult, $actualResult);
 }
Esempio n. 4
0
 /**
  * check if an item is empty
  *
  * empty means one of:
  * - item itself is empty
  * - item is a data container, and only contains empty data items
  *
  * BE AWARE that this check WILL descend down into the contents of $item
  * until it finds the first piece of non-empty data. This has the potential
  * to be computationally expensive.
  *
  * @param  mixed $item
  *         the item to check
  * @return boolean
  *         TRUE if the item is empty
  *         FALSE otherwise
  */
 public static function check($item)
 {
     $method = MapTypeToMethod::using($item, self::$dispatchMap);
     return self::$method($item);
 }
 /**
  * use an input item's data type to work out which method we should
  * call
  *
  * this is a faster replacement for the older FirstMethodMatchingType
  * value builder
  *
  * not only is it faster, but the lookup table can also contain protected
  * and private methods
  *
  * @param  mixed $item
  *         the item we want to dispatch
  * @param  array $typeMethods
  *         the list of methods that are available
  * @return string
  *         the name of the method to call
  */
 private static function lookupMethodFor($item, $typeMethods)
 {
     return MapTypeToMethod::using($item, $typeMethods);
 }