Automattic\WooCommerce\Vendor\GraphQL\Type

Schema::collectImplementationsprivateWC 1.0

Method of the class: Schema{}

No Hooks.

Returns

Array. InterfaceImplementations>

Usage

// private - for code of main (parent) class only
$result = $this->collectImplementations(): array;

Schema::collectImplementations() code WC 10.9.4

private function collectImplementations(): array
{
    if (! isset($this->implementationsMap)) {
        $this->implementationsMap = [];

        /**
         * @var array<
         *     string,
         *     array{
         *         objects: array<int, ObjectType>,
         *         interfaces: array<int, InterfaceType>,
         *     }
         * > $foundImplementations
         */
        $foundImplementations = [];
        foreach ($this->getTypeMap() as $type) {
            if ($type instanceof InterfaceType) {
                if (! isset($foundImplementations[$type->name])) {
                    $foundImplementations[$type->name] = ['objects' => [], 'interfaces' => []];
                }

                foreach ($type->getInterfaces() as $iface) {
                    if (! isset($foundImplementations[$iface->name])) {
                        $foundImplementations[$iface->name] = ['objects' => [], 'interfaces' => []];
                    }

                    $foundImplementations[$iface->name]['interfaces'][] = $type;
                }
            } elseif ($type instanceof ObjectType) {
                foreach ($type->getInterfaces() as $iface) {
                    if (! isset($foundImplementations[$iface->name])) {
                        $foundImplementations[$iface->name] = ['objects' => [], 'interfaces' => []];
                    }

                    $foundImplementations[$iface->name]['objects'][] = $type;
                }
            }
        }

        foreach ($foundImplementations as $name => $implementations) {
            $this->implementationsMap[$name] = new InterfaceImplementations($implementations['objects'], $implementations['interfaces']);
        }
    }

    return $this->implementationsMap;
}