Check if an item is a reference, and if it is, convert it to an entity.

This function will recurse into deeper arrays.

@param mixed &$item The item to check.
@param mixed $key Unused.
@access private
342151
private function referenceToEntity(&$item, $key) {
    if (is_array($item)) {
      if (isset($item[0]) && $item[0] === 'nymph_entity_reference') {
        $item = call_user_func([$item[2], 'factoryReference'], $item);
      } else {
        array_walk($item, [$this, 'referenceToEntity']);
      }
    } elseif (is_object($item)
              && !(
                (
                  is_a($item, '\Nymph\Entity')
                  || is_a($item, '\SciActive\HookOverride')
                )
                && is_callable([$item, 'toReference'])
              )) {
      // Only do this for non-entity objects.
      foreach ($item as &$curProperty) {
        $this->referenceToEntity($curProperty, null);
      }
      unset($curProperty);
    }
  }
446206
private function sanitizeStashStorageItem($item, $key)
    {
        if ( is_object($item) && ! ( $item instanceof \JsonSerializable ) ) {
            throw new StashException(
                'Can not stash value of key `'.$key.'`, provided object does not implement JsonSerializable'
            );
        }

        return $item;
    }
1124795
public function isArray($item=null) {
    list($item) = self::_wrapArgs(func_get_args(), 1);
    return self::_wrap(is_array($item));
  }
801293
public function contains($item)
    {
        if ($item instanceof AbstractEntity) {
            $item = $item->id;
        }
        foreach ($this->value as $entity) {
            $eId = $entity->id;
            if (!$this->isNull($eId) && $eId == $item) {
                return true;
            }
        }

        return false;
    }
501728
private function isAssocArray($item): bool
    {
        if (!is_array($item)) {
            // Is not an array at all
            return false;
        }

        if ($item === []) {
            // Treat empty array as Sequential
            return false;
        }

        // Check if keys are equal to sequence of 0 .. n-1
        return array_keys($item) !== range(0, count($item) - 1);
    }
1180596
protected function _checkViewVars(&$item, $key)
    {
        if ($item instanceof Exception) {
            $item = (string)$item;
        }

        if (is_resource($item) ||
            $item instanceof Closure ||
            $item instanceof PDO
        ) {
            throw new RuntimeException(sprintf(
                'Failed serializing the `%s` %s in the `%s` view var',
                is_resource($item) ? get_resource_type($item) : get_class($item),
                is_resource($item) ? 'resource' : 'object',
                $key
            ));
        }
    }
1344529
public function propertyExists($property, $item)
    {
        if (gettype($item) == 'array') {
            return array_key_exists($property, $item);
        } elseif (gettype($item) == 'object') {
            return property_exists($item , $property);
        }
        return false;
    }
583642
public function saveDeferred($key, $item, $ttl = null)
    {
        $this->queue[$key]['data'] = $item;
        if (null != $ttl) {
            $this->queue[$key]['ttl'] = $ttl;
        }
    }
62287
public function has($key)
    {
        $result = $this->get($key);

        //an empty EntityCollection means no related entities
        if ($result instanceof EntityCollection && count($result) === 0) {
            return false;
        }

        return $result ? true : false;
    }
309268
public function remove($key)
	{
		if(($item=parent::remove($key))!==null)
			$this->_form->removedElement($key,$item,$this->_forButtons);
	}
231340
public function offsetUnset($key)
    {
        if ($this->offsetExists($key)) {
            $this->deleted[] = $this->items[$key];
        }
        parent::offsetUnset($key);
    }
265980
public function removeItem($item)
    {
        $key = $this->getKey($item);
        if ($key !== false) {
            $this->offsetUnset($key);
        }
    }
476837
public function __item($item = null)
    {
        $result = parent::__item($item);
        $result['content'] = true;
        return $result;
    }
6354
public function hasRelation($key)
    {
        if (array_key_exists($key, $this->relations)) {
            return true;
        }

        $entity = $this->getEntity();
        if (method_exists($entity, $key)) {
            return true;
        }

        return false;
    }
576003
private function _isLink($item): bool
	{
		if ($item === null) {
			return true;
		} elseif (is_array($item)) {
			return !is_array(current($item));
		} else {
			throw new \InvalidArgumentException('Cms menu items is wrong in config.neon');
		}
	}
812332
private function trackReference(string $key)
    {
        if (!in_array($key, $this->columns)) {
            throw new NodeException("Unable to create reference, key {$key} does not exist");
        }

        if (!in_array($key, $this->trackReferences)) {
            //We are only tracking unique references
            $this->trackReferences[] = $key;
        }
    }
531095
public function put($key, $item)
    {
        $file = $this->filename($key);

        // json
        // text
        if (!file_put_contents($file, serialize($item))) {
            throw new \Exception(
                t("Failed writing cache object '!key'.", [
                    '!key' => $key
                ])
            );
        }
    }