Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] "Node Factory" system #93

Open
kbond opened this issue Mar 1, 2023 · 0 comments
Open

[Core] "Node Factory" system #93

kbond opened this issue Mar 1, 2023 · 0 comments

Comments

@kbond
Copy link
Member

kbond commented Mar 1, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant