This repository was archived by the owner on Sep 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
78 lines (67 loc) · 3 KB
/
functions.php
File metadata and controls
78 lines (67 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php declare(strict_types=1);
////////////////////////////////////////////////////////////////////////////////
// ___________ __ __ _____
// \_ _____/______ __ __ _____/ |_|__|/ ____\__ __
// | __) \_ __ \ | \_/ ___\ __\ \ __< | |
// | \ | | \/ | /\ \___| | | || | \___ |
// \___ / |__| |____/ \___ >__| |__||__| / ____|
// \/ \/ \/
// -----------------------------------------------------------------------------
// https://github.com/fructify
//
// Designed and Developed by Brad Jones <brad @="bjc.id.au" />
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
use Gears\String\Str;
use DI\ContainerBuilder;
use Fructify\Contracts\IKernel;
// Install the import function globally.
// see: https://github.com/brad-jones/import/
Brads\Importer::globalise();
/**
* The Theme IoC Container.
*
* Wrap everything up into a closure because the global scope is already pretty
* crowded being a wordpress environment and all... :) Additonally it stops
* anyone from cheating and say requesting the IoC Container by using something
* like ```$GLOBALS['app']```.
*/
call_user_func(function()
{
$builder = new ContainerBuilder();
// We will enable @Inject annotation support. Between autowiring &
// annotations I am hoping we won't need to have much in the way of
// custom definitions in the ```container.php``` file.
// http://php-di.org/doc/annotations.html
$builder->useAnnotations(true);
// Add our definitions from ```container.php```.
$definitions = import(__DIR__.'/container.php');
$builder->addDefinitions($definitions);
// Grab the config object so we can use it to build the container.
$config = $definitions['config']->__invoke();
// Add definitions from a child theme that might exist.
$parentThemePath = $config->paths->theme->parent->root;
$childThemePath = $config->paths->theme->child->root;
if ($parentThemePath != $childThemePath)
{
$childContainer = $childThemePath.'/container.php';
if (file_exists($childContainer))
{
$builder->addDefinitions(import($childContainer));
}
}
// If running on staging or production we will make
// sure the container is cached for maximum performance.
if (Str::s($config->hosting->env)->containsAny(['staging','production']))
{
$builder->setDefinitionCache
(
$config->cache->container->driver->__invoke($config)
);
// NOTE: This would only be used in the case there are lazy injections.
// see: http://php-di.org/doc/lazy-injection.html
$builder->writeProxiesToFile(true, $config->paths->cache.'/proxies');
}
// Boot our theme kernel.
$builder->build()->get(IKernel::class)->boot();
});