src/Buybrain/Nervus/Adapter/TypedAdapter.php
protected function assignToHandlers(array $objects)
    {
        $result = [];
        $perType = TypedUtils::groupByType($objects);
        foreach ($this->handlers as $handler) {
            $remainingTypes = array_keys($perType);
            $handlerTypes = $handler->getSupportedEntityTypes();
            $useTypes = $handlerTypes === null ? $remainingTypes : array_intersect($handlerTypes, $remainingTypes);
            if (count($useTypes) > 0) {
                $assigned = [];
                foreach ($useTypes as $type) {
                    $assigned[] = $perType[$type];
                    unset($perType[$type]);
                }
                $result[] = [$handler, Arrays::flatten($assigned)];
                if (count($perType) === 0) {
                    // Done
                    break;
                }
            }
        }

        return $result;
    }
protected function assignToHandlers(array $objects)
    {
        $result = [];
        $perType = TypedUtils::groupByType($objects);
        foreach ($this->handlers as $handler) {
            $remainingTypes = array_keys($perType);
            $handlerTypes = $handler->getSupportedEntityTypes();
            $useTypes = $handlerTypes === null ? $remainingTypes : array_intersect($handlerTypes, $remainingTypes);
            if (count($useTypes) > 0) {
                $assigned = [];
                foreach ($useTypes as $type) {
                    $assigned[] = $perType[$type];
                    unset($perType[$type]);
                }
                $result[] = [$handler, Arrays::flatten($assigned)];
                if (count($perType) === 0) {
                    // Done
                    break;
                }
            }
        }

        return $result;
    }
protected function assignToHandlers ( array $ objects ) { $ result = [ ] ; $ perType = TypedUtils :: groupByType ( $ objects ) ; foreach ( $ this -> handlers as $ handler ) { $ remainingTypes = array_keys ( $ perType ) ; $ handlerTypes = $ handler -> getSupportedEntityTypes ( ) ; $ useTypes = $ handlerTypes === null ? $ remainingTypes : array_intersect ( $ handlerTypes , $ remainingTypes ) ; if ( count ( $ useTypes ) > 0 ) { $ assigned = [ ] ; foreach ( $ useTypes as $ type ) { $ assigned [ ] = $ perType [ $ type ] ; unset ( $ perType [ $ type ] ) ; } $ result [ ] = [ $ handler , Arrays :: flatten ( $ assigned ) ] ; if ( count ( $ perType ) === 0 ) { // Done break ; } } } return $ result ; }
Assign every entity to the first handler that supports it

@param Typed[] $objects
@return array tuples of [Handler, object[]]
Assign every entity to the first handler that supports it