Blueprints/src/BlueprintForm.php
protected function doExtend($filename, array $parents, array $extends, $override = false)
    {
        if (\is_string(key($extends))) {
            $extends = [$extends];
        }

        $data = [[]];
        foreach ($extends as $value) {
            // Accept array of type and context or a string.
            $type = !\is_string($value) ? (!isset($value['type']) ? null : $value['type']) : $value;

            if (!$type) {
                continue;
            }

            if ($type === '@parent' || $type === 'parent@') {
                if (!$parents) {
                    throw new RuntimeException("Parent blueprint missing for '{$filename}'");
                }

                $files = $parents;
            } else {
                $files = $this->getFiles($type, isset($value['context']) ? $value['context'] : null);

                if ($override && !$files) {
                    throw new RuntimeException("Blueprint '{$type}' missing for '{$filename}'");
                }

                // Detect extend loops.
                if ($files && array_intersect($files, $parents)) {
                    // Let's check if user really meant extends@: parent@.
                    $index = \array_search($filename, $files, true);
                    if ($index !== false) {
                        // We want to grab only the parents of the file which is currently being loaded.
                        $files = \array_slice($files, $index + 1);
                    }
                    if ($files !== $parents) {
                        throw new RuntimeException("Loop detected while extending blueprint file '{$filename}'");
                    }
                    if (!$parents) {
                        throw new RuntimeException("Parent blueprint missing for '{$filename}'");
                    }
                }
            }

            if ($files) {
                $data[] = $this->doLoad($files);
            }
        }

        // TODO: In PHP 5.6+ use array_merge(...$data);
        return call_user_func_array('array_merge', $data);
    }
protected function doExtend($filename, array $parents, array $extends, $override = false)
    {
        if (\is_string(key($extends))) {
            $extends = [$extends];
        }

        $data = [[]];
        foreach ($extends as $value) {
            // Accept array of type and context or a string.
            $type = !\is_string($value) ? (!isset($value['type']) ? null : $value['type']) : $value;

            if (!$type) {
                continue;
            }

            if ($type === '@parent' || $type === 'parent@') {
                if (!$parents) {
                    throw new RuntimeException("Parent blueprint missing for '{$filename}'");
                }

                $files = $parents;
            } else {
                $files = $this->getFiles($type, isset($value['context']) ? $value['context'] : null);

                if ($override && !$files) {
                    throw new RuntimeException("Blueprint '{$type}' missing for '{$filename}'");
                }

                // Detect extend loops.
                if ($files && array_intersect($files, $parents)) {
                    // Let's check if user really meant extends@: parent@.
                    $index = \array_search($filename, $files, true);
                    if ($index !== false) {
                        // We want to grab only the parents of the file which is currently being loaded.
                        $files = \array_slice($files, $index + 1);
                    }
                    if ($files !== $parents) {
                        throw new RuntimeException("Loop detected while extending blueprint file '{$filename}'");
                    }
                    if (!$parents) {
                        throw new RuntimeException("Parent blueprint missing for '{$filename}'");
                    }
                }
            }

            if ($files) {
                $data[] = $this->doLoad($files);
            }
        }

        // TODO: In PHP 5.6+ use array_merge(...$data);
        return call_user_func_array('array_merge', $data);
    }
protected function doExtend ( $ filename , array $ parents , array $ extends , $ override = false ) { if ( \ is_string ( key ( $ extends ) ) ) { $ extends = [ $ extends ] ; } $ data = [ [ ] ] ; foreach ( $ extends as $ value ) { // Accept array of type and context or a string. $ type = ! \ is_string ( $ value ) ? ( ! isset ( $ value [ 'type' ] ) ? null : $ value [ 'type' ] ) : $ value ; if ( ! $ type ) { continue ; } if ( $ type === '@parent' || $ type === 'parent@' ) { if ( ! $ parents ) { throw new RuntimeException ( "Parent blueprint missing for '{$filename}'" ) ; } $ files = $ parents ; } else { $ files = $ this -> getFiles ( $ type , isset ( $ value [ 'context' ] ) ? $ value [ 'context' ] : null ) ; if ( $ override && ! $ files ) { throw new RuntimeException ( "Blueprint '{$type}' missing for '{$filename}'" ) ; } // Detect extend loops. if ( $ files && array_intersect ( $ files , $ parents ) ) { // Let's check if user really meant extends@: parent@. $ index = \ array_search ( $ filename , $ files , true ) ; if ( $ index !== false ) { // We want to grab only the parents of the file which is currently being loaded. $ files = \ array_slice ( $ files , $ index + 1 ) ; } if ( $ files !== $ parents ) { throw new RuntimeException ( "Loop detected while extending blueprint file '{$filename}'" ) ; } if ( ! $ parents ) { throw new RuntimeException ( "Parent blueprint missing for '{$filename}'" ) ; } } } if ( $ files ) { $ data [ ] = $ this -> doLoad ( $ files ) ; } } // TODO: In PHP 5.6+ use array_merge(...$data); return call_user_func_array ( 'array_merge' , $ data ) ; }
Internal function to recursively load extended blueprints.

@param string $filename
@param array $parents
@param array $extends
@return array
Internal function to recursively load extended blueprints .