Exemplo n.º 1
0
 /**
  * @dataProvider isAssocDataProvider
  */
 public function testIsAssoc($array, $expectedResult)
 {
     $this->assertEquals($expectedResult, ArrayUtil::isAssoc($array));
 }
 /**
  * Walk recursively through the tree, completing block definition in tree by found correspondent data "items" list
  *
  * @param array  $actions
  * @param mixed  $currentSubTree
  * @param string $parentId
  * @param array  $items
  */
 protected function processTree(array &$actions, $currentSubTree, $parentId, array $items)
 {
     if (!is_array($currentSubTree)) {
         return;
     }
     foreach ($currentSubTree as $k => $subtree) {
         $blockId = is_numeric($k) && is_string($subtree) ? $subtree : $k;
         if (!isset($items[$blockId])) {
             throw new \LogicException(sprintf('Item with id "%s" not found in items list', $blockId));
         }
         $itemDefinition = $items[$blockId];
         if (ArrayUtil::isAssoc($itemDefinition)) {
             // merge associative values to arguments
             $itemDefinition = array_merge($itemDefinition, ['id' => $blockId, 'parentId' => $parentId]);
         } else {
             // prepend blockId and parentId to arguments
             array_unshift($itemDefinition, $blockId, $parentId);
         }
         $actions[] = [self::ACTION_ADD => $itemDefinition];
         $this->processTree($actions, $subtree, $blockId, $items);
     }
 }