*/ private $items = array(); /** * Constructor. * * @param Manifest $manifest Manifest. */ public function __construct( Manifest $manifest ) { $this->manifest = $manifest; } /** * Adds an item. * * @param array{uuid: string, type: string, subtype: string, subtype_label: string, title: string, action: string, match: string|null, local_id: int|null, reference_only: bool, reason: string|null} $item Plan item. * @return void */ public function add_item( array $item ): void { $this->items[ $item['uuid'] ] = $item; } /** * Returns all items, in manifest order. * * @return array */ public function get_items(): array { return array_values( $this->items ); } /** * Returns one item. * * @param string $uuid Entity UUID. * @return array{uuid: string, type: string, subtype: string, subtype_label: string, title: string, action: string, match: string|null, local_id: int|null, reference_only: bool, reason: string|null}|null */ public function get_item( string $uuid ): ?array { return $this->items[ strtolower( $uuid ) ] ?? null; } /** * Returns the manifest. * * @return Manifest */ public function get_manifest(): Manifest { return $this->manifest; } /** * Returns the number of items per action. * * @return array */ public function get_counts(): array { $counts = array_fill_keys( array( self::CREATE, self::UPDATE, self::SKIP, self::LINK, self::MISSING ), 0 ); foreach ( $this->items as $item ) { ++$counts[ $item['action'] ]; } return $counts; } /** * Returns the plan as an array for display. * * @return array */ public function to_array(): array { return array( 'source' => $this->manifest->get_source(), 'items' => $this->get_items(), 'counts' => $this->get_counts(), ); } }