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

Builder Pattern (method chaining) approach #1

Open
jakubmikita opened this issue Feb 13, 2020 · 2 comments
Open

Builder Pattern (method chaining) approach #1

jakubmikita opened this issue Feb 13, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@jakubmikita
Copy link
Contributor

Suggested by Lucas on Facebook:

I like the Requirements one, if I may be picky, it seems like a good candidate for the Builder Pattern! https://3v4l.org/kgEJC
Above is just an example, it can be done with PHP 5.6 as well. it's nice because you get type-hinting to write the requirements

@jakubmikita jakubmikita added the enhancement New feature or request label Feb 13, 2020
@szepeviktor
Copy link
Contributor

szepeviktor commented Dec 24, 2020

Hello @Kubitomakita! 👋 I also have a wish of breaking out of WordPressy, PHP4-like thinking and provide an OOP-only solution, self-aware objects for developers.

//: Check requirements
if (
    (new Requirements())
        ->php('7.4')
        ->wp('5.2')
        ->multisite(false)
        ->plugins(['polylang/polylang.php'])
        ->packages(['psr/container', 'psr/log-implementation'])
        ->met()
) {}

//: Define constants
Config::init(
    [
        'version' => '1.0.0',
        'filePath' => __FILE__,
        'baseName' => \plugin_basename(__FILE__),
        'slug' => 'plugin-slug',
    ]
);

https://github.com/szepeviktor/small-project

What do you think?
Too much for a WP dev?? :)

@jakubmikita
Copy link
Contributor Author

@szepeviktor it could work like this!

We could also make a custom check as easy as:

(new Requirements())
        ->custom_check( function() {
                return true;
        } );

I'm not sure about the Config, though. There's a nicer approach with WP Filesytem and File Header API and we could do all the discovery automatically. I'm thinking about the plugin engine micropackage here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants