Created
December 30, 2015 09:44
-
-
Save gplanchat/d74bdc101854291df092 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function factory($path, ...$args) { | |
$callback = require $path . '.php'; | |
if (!$callback instanceof Closure) { | |
return $callback; | |
} | |
return $callback(...$args); | |
} | |
/** | |
* Usage | |
* | |
* Whre you need the dependency: | |
* $filesystem = factory('flysystem/filesystem', __DIR__); | |
* | |
* in file flysystem/filesystem.php: | |
* <?php | |
* | |
* use League\Flysystem\Adapter\Local; | |
* use League\Flysystem\Filesystem; | |
* | |
* return function($path) { | |
* return new Filesystem(new Local($path)); | |
* }; | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment