Skip to content

[Core] "Node Factory" system #93

Open
@kbond

Description

@kbond

This package provides 3 node types out of the box: Directory, File and Image. It's possible that users may want other node types in the future, each with their own set of metadata/functionality. Some possible examples: Pdf, Video, Audio.

While if enough users request a specific type, we would add to core, but some kind of extension system could be developed via a NodeFactory concept to allow 3rd party nodes.

Some ideas:

/**
 * @template T of Node
 */
interface NodeFactory
{
    /**
     * @return T
     */
    public function createFrom(Node $node): Node;
}

Change Filesystem::node() method:

interface Filesystem
{
    /**
     * @template T of Node
     *
     * @param class-string<T> $type
     *
     * @return T
     */
    public function node(string $path, string $type = Node::class): Node;
}

Add Node::ensure() method:

interface Node
{
    /**
     * @template T of Node
     *
     * @param class-string<T> $type
     *
     * @return T
     */
    public function ensure(string $type): Node;
}

Once such functionality exists, the existing 1st party image support could be extracted into a dedicated zenstruck/filesystem-image package. This would leave File and Directory as the only node-types provided by the core library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions