Skip to content

Instantly share code, notes, and snippets.

@gplanchat
Created December 30, 2015 09:44
Show Gist options
  • Save gplanchat/d74bdc101854291df092 to your computer and use it in GitHub Desktop.
Save gplanchat/d74bdc101854291df092 to your computer and use it in GitHub Desktop.
<?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