| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package WPEmerge |
| 4 |
* @author Atanas Angelov <hi@atanas.dev> |
| 5 |
* @copyright 2017-2019 Atanas Angelov |
| 6 |
* @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0 |
| 7 |
* @link https://wpemerge.com/ |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace WPEmerge\Application; |
| 11 |
|
| 12 |
use WPEmerge\Helpers\HandlerFactory; |
| 13 |
use WPEmerge\Helpers\MixedType; |
| 14 |
use WPEmerge\ServiceProviders\ExtendsConfigTrait; |
| 15 |
use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 16 |
|
| 17 |
/** |
| 18 |
* Provide application dependencies. |
| 19 |
* |
| 20 |
* @codeCoverageIgnore |
| 21 |
*/ |
| 22 |
class ApplicationServiceProvider implements ServiceProviderInterface { |
| 23 |
use ExtendsConfigTrait; |
| 24 |
|
| 25 |
/** |
| 26 |
* {@inheritDoc} |
| 27 |
*/ |
| 28 |
public function register( $container ) { |
| 29 |
$this->extendConfig( $container, 'providers', [] ); |
| 30 |
$this->extendConfig( $container, 'namespace', 'App\\' ); |
| 31 |
|
| 32 |
$upload_dir = wp_upload_dir(); |
| 33 |
$cache_dir = MixedType::addTrailingSlash( $upload_dir['basedir'] ) . 'wpemerge' . DIRECTORY_SEPARATOR . 'cache'; |
| 34 |
$this->extendConfig( $container, 'cache', [ |
| 35 |
'path' => $cache_dir, |
| 36 |
] ); |
| 37 |
|
| 38 |
$container[ WPEMERGE_APPLICATION_GENERIC_FACTORY_KEY ] = function ( $c ) { |
| 39 |
return new GenericFactory( $c ); |
| 40 |
}; |
| 41 |
|
| 42 |
$container[ WPEMERGE_APPLICATION_CLOSURE_FACTORY_KEY ] = function ( $c ) { |
| 43 |
return new ClosureFactory( $c[ WPEMERGE_APPLICATION_GENERIC_FACTORY_KEY ] ); |
| 44 |
}; |
| 45 |
|
| 46 |
$container[ WPEMERGE_HELPERS_HANDLER_FACTORY_KEY ] = function ( $c ) { |
| 47 |
return new HandlerFactory( $c[ WPEMERGE_APPLICATION_GENERIC_FACTORY_KEY ] ); |
| 48 |
}; |
| 49 |
|
| 50 |
$container[ WPEMERGE_APPLICATION_FILESYSTEM_KEY ] = function ( $c ) { |
| 51 |
global $wp_filesystem; |
| 52 |
|
| 53 |
require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 54 |
|
| 55 |
WP_Filesystem(); |
| 56 |
|
| 57 |
return $wp_filesystem; |
| 58 |
}; |
| 59 |
|
| 60 |
$app = $container[ WPEMERGE_APPLICATION_KEY ]; |
| 61 |
$app->alias( 'app', WPEMERGE_APPLICATION_KEY ); |
| 62 |
$app->alias( 'closure', WPEMERGE_APPLICATION_CLOSURE_FACTORY_KEY ); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* {@inheritDoc} |
| 67 |
*/ |
| 68 |
public function bootstrap( $container ) { |
| 69 |
$cache_dir = $container[ WPEMERGE_CONFIG_KEY ]['cache']['path']; |
| 70 |
wp_mkdir_p( $cache_dir ); |
| 71 |
} |
| 72 |
} |
| 73 |
|