Exemplo n.º 1
0
 /**
  * doExctractParams
  *
  * @param array $params
  * @param int $indend
  *
  * @return string
  */
 private function doExctractParams(array $params, $indent = 0)
 {
     $array = [];
     foreach ($params as $param => $value) {
         if (is_array($value)) {
             $value = $this->doExctractParams($value, $indent + 4);
         } elseif (is_string($value) && 0 === strpos($value, '$this')) {
             $value = $value;
         } else {
             $value = $this->exportVar($value);
         }
         $key = $this->exportVar($param);
         $array[$key] = sprintf('%s%s => %s,', $this->indent($indent), $key, $value);
     }
     if (empty($array)) {
         return '[]';
     }
     $flat = sprintf("[\n%s\n%s]", implode("\n", $array), $this->indent(max($indent - 4, 0)));
     if (Arr::isList($array, true)) {
         return preg_replace('#\\d+ \\=\\>\\s?#i', '', $flat);
     }
     return $flat;
 }
Exemplo n.º 2
0
 /** @test */
 public function testZip()
 {
     $zipped = Arr::zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
     $this->assertSame([["moe", 30, true], ["larry", 40, false], ["curly", 50, false]], $zipped);
 }
Exemplo n.º 3
0
 /**
  * appendDomList
  *
  * @param NormalizerInterface $normalizer
  * @param \DOMDocument $dom
  * @param mixed $node
  * @param mixed $key
  * @param mixed $value
  *
  * @return bool
  */
 protected function appendDomList(NormalizerInterface $normalizer, \DOMDocument $dom, $node, $key, $value)
 {
     if (!Arr::isList($value, true)) {
         return false;
     }
     if (($useKey = ($skey = $this->inflect($key)) && $key !== $skey) || null !== $this->indexKey) {
         $parentNode = $dom->createElement($key);
         if (!$useKey) {
             $parentNode = $dom->createElement($key);
             $this->buildXmlFromTraversable($dom, $parentNode, $value);
         } else {
             foreach ($value as $arrayValue) {
                 $this->appendDOMNode($dom, $parentNode, $skey, $arrayValue);
             }
         }
         return $node->appendChild($parentNode);
     }
     // if anything fails, append the domnodes directly.
     foreach ($value as $arrayValue) {
         $this->appendDOMNode($dom, $node, $this->inflect($normalizer->normalize($key)), $arrayValue);
     }
     return true;
 }
Exemplo n.º 4
0
 /**
  * addContent
  *
  * @param string $key
  * @param mixed $content
  *
  * @return JsonGenerator
  */
 public function addContent($key, $content)
 {
     Arr::set($this->payload, $key, $content);
     return $this;
 }
Exemplo n.º 5
0
 /**
  * valueIsList
  *
  * @param mixed $value
  *
  * @return bool
  */
 public function valueIsList($value)
 {
     return is_array($value) && Arr::isList($value, true);
 }