Uname: Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
Software: LiteSpeed
PHP version: 8.1.32 [ PHP INFO ] PHP os: Linux
Server Ip: 162.213.251.212
Your Ip: 3.15.22.62
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : collection.php
<?php
namespace ElementorPro\Core\Utils;

use \Elementor\Core\Utils\Collection as Collection_Base;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

// TODO: Move to Core.
class Collection extends Collection_Base implements \JsonSerializable {

	/**
	 * Change the items key by an item field.
	 *
	 * @param string $key
	 *
	 * @return Collection
	 */
	public function key_by( $key ) {
		return $this->map_with_keys( function ( $item ) use ( $key ) {
			return [ $item->{$key} => $item ];
		} );
	}

	/**
	 * Flatten the items recursively.
	 *
	 * @return array
	 */
	public function flatten_recursive() {
		$output = [];
		$items = $this->all();

		array_walk_recursive($items, function( $item ) use ( &$output ) {
			$output[] = $item;
		} );

		return $output;
	}

	/**
	 * Run array_diff between the collection and other array or collection.
	 *
	 * @param $filter
	 *
	 * @return $this
	 */
	public function diff( $filter ) {
		if ( $filter instanceof Collection_Base ) {
			$filter = $filter->all();
		}

		return new static( array_diff( $this->all(), $filter ) );
	}

	/**
	 * Reverse the array
	 *
	 * @param false $preserve_keys
	 *
	 * @return $this
	 */
	public function reverse( $preserve_keys = false ) {
		return new static(
			array_reverse( $this->all(), $preserve_keys )
		);
	}

	/**
	 * Return a JSON serialized representation of the Collection.
	 *
	 * @return array
	 */
	#[\ReturnTypeWillChange]
	public function jsonSerialize() {
		return $this->all();
	}
}
© 2025 GrazzMean-Shell